Giter Club home page Giter Club logo

service-repository's People

Contributors

watarhu avatar

Stargazers

 avatar

Watchers

 avatar  avatar

service-repository's Issues

Non public constructors returns null and does not specify the cause

If we try to use a service with one of it's non-public constructors the result is null and does not tell the underlaying cause for this error:

Example:

(...)
public class PersistenceUnitFactoryImpl implements PersistenceUnitFactory,Closeable{

	private final String persistenceUnit;
	private final EntityManagerFactory factory;	

	PersistenceUnitFactoryImpl(final String _persistenceUnit){
		try{
			this.persistenceUnit=_persistenceUnit;
			this.factory=createEntityManagerFactory(Collections.emptyMap());
		}catch(Throwable e){
			System.err.println("Error initiallizing persistenceUnit: "+e.getMessage());
			e.printStackTrace();
			throw e;
		}
	}
(...)

Throws:

Caused by: org.bytemechanics.service.repository.exceptions.ServiceInitializationException: Service PERSISTENCEUNIT can not be initialized properly: Unable to instantiate service with class class com.allianz.ebcm.migration.tool.persistence.impl.PersistenceUnitFactoryImpl using constructor([ebcm-migration-tool])
at org.bytemechanics.service.repository.ServiceSupplier.lambda$null$4(ServiceSupplier.java:217) ~[migration-tool-content-builder.jar:?]
at java.util.Optional.orElseThrow(Unknown Source) ~[?:1.8.0_73]
at org.bytemechanics.service.repository.ServiceSupplier.lambda$generateSupplier$5(ServiceSupplier.java:216) ~[migration-tool-content-builder.jar:?]
at org.bytemechanics.service.repository.ServiceSupplier.get(ServiceSupplier.java:149) ~[migration-tool-content-builder.jar:?]
at org.bytemechanics.service.repository.ServiceRepository.get(ServiceRepository.java:98) ~[migration-tool-content-builder.jar:?]
at org.bytemechanics.service.repository.ServiceRepository.get(ServiceRepository.java:110) ~[migration-tool-content-builder.jar:?]
at com.allianz.ebcm.migration.tool.persistence.JPAPersistenceDao.lambda$createEntityManager$1(JPAPersistenceDao.java:15) ~[migration-tool-content-builder.jar:?]
at java.util.Optional.map(Unknown Source) ~[?:1.8.0_73]
at com.allianz.ebcm.migration.tool.persistence.JPAPersistenceDao.createEntityManager(JPAPersistenceDao.java:15) ~[migration-tool-content-builder.jar:?]
at com.allianz.ebcm.migration.tool.business.services.impl.ContextServiceImpl.registerProcess(ContextServiceImpl.java:44) ~[migration-tool-content-builder.jar:?]
at com.allianz.ebcm.migration.tool.business.services.impl.ContextServiceImpl.(ContextServiceImpl.java:37) ~[migration-tool-content-builder.jar:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_73]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_73]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_73]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_73]
at org.bytemechanics.service.repository.internal.commons.reflection.ObjectFactory.lambda$null$5(ObjectFactory.java:153) ~[migration-tool-content-builder.jar:?]

This could not look like so important, but it's necessary in order to find easily the initialization error cause.

Add support for service destroyers into ServiceSupplier

Not all services in standard libraries provide Closeable as implemented interface.
In order to reduce wrapper boilerplate, org.bytemechanics.service.repository.ServiceSupplier may receive an additional parameter in constructor as java.util.function.Consumer<? extends T> in order to destroy the service orderly.

Add ServiceRepository methods to recover object instance passing attributes to constructor

For non singleton services, sometimes is interesting to allow instantiate the service passing some parameters, for this reason should be a very interesting functionality to allow service instantiation with supplied parameters.

Proposed interface:

Object get(Object... _args)
<T extends Object> T get(Class<T> _class,Object... _args)
Optional<Object> tryGet(Object... _args)
<T extends Object> Optional<T> tryGet(Class<T> _class,Object... _args)

Provide static contructor of DefaultServiceSupplier from ServiceSupplier

To make the usage more intuitive should be interesting to have static instance builder to construct a DefaultServiceSupplier instance from ServiceSupplier :

public static <T extends Object> getInstance(String _name, Class<T> _adapter, Class<? extends T> _implementation, Object[] _args)
public static <T extends Object> getInstance(String _name, Class<T> _adapter, Supplier<? extends T> _supplier)
public static <T extends Object> getInstance(String _name, Class<T> _adapter, boolean _isSingleton, Class<? extends T> _implementation, Object[] _args)
public static <T extends Object> getInstance(String _name, Class<T> _adapter, boolean _isSingleton, Supplier<? extends T> _supplier)
public static <T extends Object> getInstance(String _name, Class<T> _adapter, Class<? extends T> _implementation, boolean _isSingleton, Supplier<? extends T> _supplier)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.