Package org.apache.felix.framework
Class ServiceRegistry
- java.lang.Object
-
- org.apache.felix.framework.ServiceRegistry
-
public class ServiceRegistry extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classServiceRegistry.ServiceHolderstatic interfaceServiceRegistry.ServiceRegistryCallbacks(package private) static classServiceRegistry.UsageCount
-
Field Summary
Fields Modifier and Type Field Description private HookRegistryhookRegistryprivate ServiceRegistry.ServiceRegistryCallbacksm_callbacksprivate java.util.concurrent.atomic.AtomicLongm_currentServiceIdCounter for the service idprivate java.util.concurrent.ConcurrentMap<Bundle,ServiceRegistry.UsageCount[]>m_inUseMapprivate Loggerm_loggerprivate CapabilitySetm_regCapSetprivate java.util.concurrent.ConcurrentMap<Bundle,java.util.List<ServiceRegistration<?>>>m_regsMap
-
Constructor Summary
Constructors Constructor Description ServiceRegistry(Logger logger, ServiceRegistry.ServiceRegistryCallbacks callbacks)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckCountOverflow(long c)(package private) voidflushUsageCount(Bundle bundle, ServiceReference<?> ref, ServiceRegistry.UsageCount uc)Utility method to flush the specified bundle's usage count for the specified service reference.HookRegistrygetHookRegistry()LoggergetLogger()ServiceReference<?>[]getRegisteredServices(Bundle bundle)Get all service references for a bundle<S> SgetService(Bundle bundle, ServiceReference<S> ref, boolean isServiceObjects)java.util.Collection<Capability>getServiceReferences(java.lang.String className, SimpleFilter filter)ServiceReference<?>[]getServicesInUse(Bundle bundle)Bundle[]getUsingBundles(ServiceReference<?> ref)private voidincrementToPositiveValue(java.util.concurrent.atomic.AtomicLong al)(package private) ServiceRegistry.UsageCountobtainUsageCount(Bundle bundle, ServiceReference<?> ref, java.lang.Object svcObj, java.lang.Boolean isPrototype)Obtain a UsageCount object, by looking for an existing one or creating a new one (if possible).ServiceRegistration<?>registerService(Bundle bundle, java.lang.String[] classNames, java.lang.Object svcObj, java.util.Dictionary<?,?> dict)Register a new service Caller must fire service event as this method is not doing it!(package private) voidservicePropertiesModified(ServiceRegistration<?> reg, java.util.Dictionary<?,?> oldProps)booleanungetService(Bundle bundle, ServiceReference<?> ref, java.lang.Object svcObj)voidungetServices(Bundle bundle)This is a utility method to release all services being used by the specified bundle.private voidungetServices(ServiceReference<?> ref)voidunregisterService(Bundle bundle, ServiceRegistration<?> reg)Unregister a servicevoidunregisterServices(Bundle bundle)This method retrieves all services registrations for the specified bundle and invokes ServiceRegistration.unregister() on each one.
-
-
-
Field Detail
-
m_logger
private final Logger m_logger
-
m_currentServiceId
private final java.util.concurrent.atomic.AtomicLong m_currentServiceId
Counter for the service id
-
m_regsMap
private final java.util.concurrent.ConcurrentMap<Bundle,java.util.List<ServiceRegistration<?>>> m_regsMap
-
m_regCapSet
private final CapabilitySet m_regCapSet
-
m_inUseMap
private final java.util.concurrent.ConcurrentMap<Bundle,ServiceRegistry.UsageCount[]> m_inUseMap
-
m_callbacks
private final ServiceRegistry.ServiceRegistryCallbacks m_callbacks
-
hookRegistry
private final HookRegistry hookRegistry
-
-
Constructor Detail
-
ServiceRegistry
public ServiceRegistry(Logger logger, ServiceRegistry.ServiceRegistryCallbacks callbacks)
-
-
Method Detail
-
getRegisteredServices
public ServiceReference<?>[] getRegisteredServices(Bundle bundle)
Get all service references for a bundle- Parameters:
bundle-- Returns:
- List with all valid service references or
null.
-
registerService
public ServiceRegistration<?> registerService(Bundle bundle, java.lang.String[] classNames, java.lang.Object svcObj, java.util.Dictionary<?,?> dict)
Register a new service Caller must fire service event as this method is not doing it!- Parameters:
bundle- The bundle registering the serviceclassNames- The service class namessvcObj- The service objectdict- Optional service properties- Returns:
- Service registration
-
unregisterService
public void unregisterService(Bundle bundle, ServiceRegistration<?> reg)
Unregister a service- Parameters:
bundle- The bundle unregistering the servicereg- The service registration
-
ungetServices
private void ungetServices(ServiceReference<?> ref)
-
unregisterServices
public void unregisterServices(Bundle bundle)
This method retrieves all services registrations for the specified bundle and invokes ServiceRegistration.unregister() on each one. This method is only called be the framework to clean up after a stopped bundle.- Parameters:
bundle- the bundle whose services should be unregistered.
-
getServiceReferences
public java.util.Collection<Capability> getServiceReferences(java.lang.String className, SimpleFilter filter)
-
getServicesInUse
public ServiceReference<?>[] getServicesInUse(Bundle bundle)
-
getService
public <S> S getService(Bundle bundle, ServiceReference<S> ref, boolean isServiceObjects)
-
incrementToPositiveValue
private void incrementToPositiveValue(java.util.concurrent.atomic.AtomicLong al)
-
checkCountOverflow
private void checkCountOverflow(long c)
-
ungetService
public boolean ungetService(Bundle bundle, ServiceReference<?> ref, java.lang.Object svcObj)
-
ungetServices
public void ungetServices(Bundle bundle)
This is a utility method to release all services being used by the specified bundle.- Parameters:
bundle- the bundle whose services are to be released.
-
getUsingBundles
public Bundle[] getUsingBundles(ServiceReference<?> ref)
-
servicePropertiesModified
void servicePropertiesModified(ServiceRegistration<?> reg, java.util.Dictionary<?,?> oldProps)
-
getLogger
public Logger getLogger()
-
obtainUsageCount
ServiceRegistry.UsageCount obtainUsageCount(Bundle bundle, ServiceReference<?> ref, java.lang.Object svcObj, java.lang.Boolean isPrototype)
Obtain a UsageCount object, by looking for an existing one or creating a new one (if possible). This method tries to find a UsageCount object in them_inUseMap. If one is found then this is returned, otherwise a UsageCount object will be created, but this can only be done if theisPrototypeparameter is notnull. IfisPrototypeisTRUEthen a new UsageCount object will always be created.- Parameters:
bundle- The bundle using the service.ref- The Service Reference.svcObj- A Service Object, if applicable.isPrototype-TRUEif we know that this is a prototype, {@ FALSE} if we know that it isn't. There are cases where we don't know (the pure lookup case), in that case usenull.- Returns:
- The UsageCount object if it could be obtained, or
nullotherwise.
-
flushUsageCount
void flushUsageCount(Bundle bundle, ServiceReference<?> ref, ServiceRegistry.UsageCount uc)
Utility method to flush the specified bundle's usage count for the specified service reference. This should be called to completely remove the associated usage count object for the specified service reference. If the goal is to simply decrement the usage, then get the usage count and decrement its counter. This method will also remove the specified bundle from the "in use" map if it has no more usage counts after removing the usage count for the specified service reference.- Parameters:
bundle- The bundle whose usage count should be removed.ref- The service reference whose usage count should be removed.
-
getHookRegistry
public HookRegistry getHookRegistry()
-
-