Package ej.service.loader
Class SimpleServiceLoader
- java.lang.Object
-
- ej.service.loader.SimpleServiceLoader
-
- All Implemented Interfaces:
ServiceLoader
- Direct Known Subclasses:
CompositeServiceLoader,DependencyInjectionServiceLoader,SimpleServiceRegistry
public abstract class SimpleServiceLoader extends Object implements ServiceLoader
Service loader that creates service instance based on default service implementation class.
-
-
Constructor Summary
Constructors Constructor Description SimpleServiceLoader()Instantiates a new default service loader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> voidcheckServicePermission(Class<T> service, String action)Checks that an action on a service is permitted.protected <T> TcreateAlternativeImplementation(Class<T> service)Creates an implementation for the given service and save it in the cache.<T> TgetService(Class<T> service)Gets the instance of the given service.protected <T> voidputService(Class<T> service, T instance)Put a service in the services map in a synchronized context.
-
-
-
Field Detail
-
services
protected final PackedMap<Class<?>,Object> services
The cache of instantiated services.Be careful to use it in a synchronized context.
- See Also:
putService(Class, Object)
-
-
Method Detail
-
getService
@Nullable public <T> T getService(Class<T> service)
Description copied from interface:ServiceLoaderGets the instance of the given service.If there is already an instance in cache, it is returned otherwise a new one is created.
May return
nullif the service is not defined.- Specified by:
getServicein interfaceServiceLoader- Type Parameters:
T- the service type.- Parameters:
service- the service.- Returns:
- the instance of the given service.
-
checkServicePermission
protected <T> void checkServicePermission(Class<T> service, String action)
Checks that an action on a service is permitted.- Type Parameters:
T- the service type.- Parameters:
service- the service.action- the action.
-
createAlternativeImplementation
@Nullable protected <T> T createAlternativeImplementation(Class<T> service) throws ServiceLoadingException
Creates an implementation for the given service and save it in the cache.- Type Parameters:
T- the service type.- Parameters:
service- the service.- Returns:
- a new instance of the given service or
null. - Throws:
ServiceLoadingException- if an error occurs while instantiating the service instance.
-
putService
protected <T> void putService(Class<T> service, T instance)
Put a service in the services map in a synchronized context.- Type Parameters:
T- the service type.- Parameters:
service- the service.instance- the service instance.
-
-