Package com.microej.kf.util.service
Class SharedServiceRegistryKF
- java.lang.Object
-
- ej.service.loader.SimpleServiceLoader
-
- ej.service.registry.SimpleServiceRegistry
-
- com.microej.kf.util.service.SharedServiceRegistryKF
-
- All Implemented Interfaces:
SharedServiceRegistry,FeatureStateListener,ServiceLoader,ServiceRegistry
public class SharedServiceRegistryKF extends SimpleServiceRegistry implements SharedServiceRegistry, FeatureStateListener
Implementation of the shared service registry over Kernel and Features.This service registry is able to handle the following kind of services:
- Services owned by the kernel, available to the kernel and the features (provided that the type is part of the API)
- Services owned by a feature using shared interfaces mechanism, available to other features through
Proxyinstances - Services owned by a feature using an interface owned by the kernel, only available to the kernel (kernel extensions)
- Services owned by a feature using a type owned by the feature, only available to the feature
-
-
Field Summary
-
Fields inherited from class ej.service.loader.SimpleServiceLoader
services
-
-
Constructor Summary
Constructors Constructor Description SharedServiceRegistryKF()Creates a shared service registry.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TgetService(Class<T> serviceClass)Gets the registered implementation for the given service.<T> voidregister(Class<T> serviceClass, T implementation)Registers a service instance.voidstateChanged(Feature feature, Feature.State previousState)Called when the state of a Feature has changed.<T> voidunregister(Class<T> serviceClass, T implementation)Unregisters a service instance.-
Methods inherited from class ej.service.loader.SimpleServiceLoader
checkServicePermission, createAlternativeImplementation, putService
-
-
-
-
Method Detail
-
register
public <T> void register(Class<T> serviceClass, T implementation)
Description copied from interface:ServiceRegistryRegisters a service instance.The given instance is returned each time the service is requested by
ServiceLoader.getService(Class).If the service already has a registered instance, the previous one is replaced.
- Specified by:
registerin interfaceServiceRegistry- Overrides:
registerin classSimpleServiceRegistry- Type Parameters:
T- the service type.- Parameters:
serviceClass- the implemented service.implementation- the service instance.
-
unregister
public <T> void unregister(Class<T> serviceClass, T implementation)
Description copied from interface:ServiceRegistryUnregisters a service instance.If the given instance is not the one currently registered for the given service, nothing is done.
- Specified by:
unregisterin interfaceServiceRegistry- Overrides:
unregisterin classSimpleServiceRegistry- Type Parameters:
T- the service type.- Parameters:
serviceClass- the implemented service.implementation- the service instance.
-
getService
@Nullable public <T> T getService(Class<T> serviceClass)
Gets the registered implementation for the given service. This implementation depends on who request it. if it is a feature we search the service with the following order:- We search it in the shared services provided by the current feature.
- We search it in the shared services provided by the kernel.
- We search it in the shared services provided by the trusted features.
- We search it in the shared services provided by the non trusted features.
- We search it in the shared services provided by the kernel.
- We search it in the shared services provided by the trusted features.
- We search it in the shared services provided by the non trusted features.
- Specified by:
getServicein interfaceServiceLoader- Overrides:
getServicein classSimpleServiceLoader- Type Parameters:
T- the service type.- Parameters:
serviceClass- the service to found.- Returns:
- an instance of the given service or
nullif no implementation is available.
-
stateChanged
public void stateChanged(@Nullable Feature feature, @Nullable Feature.State previousState)
Description copied from interface:FeatureStateListenerCalled when the state of a Feature has changed.- Specified by:
stateChangedin interfaceFeatureStateListener- Parameters:
feature- the Feature which state has changedpreviousState- the previous state,nullif Feature state isFeature.State.INSTALLED
-
-