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 static interface
ServiceRegistry.ServiceRegistryCallbacks
private static class
ServiceRegistry.UsageCount
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Class<?>,java.util.Set<ServiceReference<?>>>
m_allHooks
private java.util.WeakHashMap<ServiceReference<?>,ServiceReference<?>>
m_blackList
private ServiceRegistry.ServiceRegistryCallbacks
m_callbacks
private long
m_currentServiceId
private static java.lang.Class<?>[]
m_hookClasses
private java.util.Map<Bundle,ServiceRegistry.UsageCount[]>
m_inUseMap
private java.util.Map<ServiceRegistration<?>,java.lang.Object>
m_lockedRegsMap
private Logger
m_logger
private CapabilitySet
m_regCapSet
private java.util.Map<Bundle,ServiceRegistration<?>[]>
m_regsMap
-
Constructor Summary
Constructors Constructor Description ServiceRegistry(Logger logger, ServiceRegistry.ServiceRegistryCallbacks callbacks)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addHooks(java.lang.String[] classNames, java.lang.Object svcObj, ServiceReference<?> ref)
private static ServiceRegistration<?>[]
addServiceRegistration(ServiceRegistration<?>[] regs, ServiceRegistration<?> reg)
private ServiceRegistry.UsageCount
addUsageCount(Bundle bundle, ServiceReference<?> ref, boolean isPrototype)
Utility method to update the specified bundle's usage count array to include the specified service.private static <S> java.util.SortedSet<ServiceReference<S>>
asTypedSortedSet(java.util.SortedSet<ServiceReference<?>> ss)
(package private) void
blackListHook(ServiceReference<?> sr)
private void
flushUsageCount(Bundle bundle, ServiceReference<?> ref, ServiceRegistry.UsageCount uc)
Utility method to flush the specified bundle's usage count for the specified service reference.<S> java.util.Set<ServiceReference<S>>
getHooks(java.lang.Class<S> hookClass)
Logger
getLogger()
ServiceReference<?>[]
getRegisteredServices(Bundle bundle)
<S> S
getService(Bundle bundle, ServiceReference<S> ref, boolean isPrototype)
java.util.Collection
getServiceReferences(java.lang.String className, SimpleFilter filter)
ServiceReference<?>[]
getServicesInUse(Bundle bundle)
private ServiceRegistry.UsageCount
getUsageCount(Bundle bundle, ServiceReference<?> ref, java.lang.Object svcObj)
Utility method to retrieve the specified bundle's usage count for the specified service reference.Bundle[]
getUsingBundles(ServiceReference<?> ref)
(package private) static boolean
isHook(java.lang.String[] classNames, java.lang.Class<?> hookClass, java.lang.Object svcObj)
(package private) boolean
isHookBlackListed(ServiceReference<?> sr)
ServiceRegistration<?>
registerService(BundleContext context, java.lang.String[] classNames, java.lang.Object svcObj, java.util.Dictionary dict)
private void
removeHook(ServiceReference<?> ref)
private static ServiceRegistration<?>[]
removeServiceRegistration(ServiceRegistration<?>[] regs, ServiceRegistration<?> reg)
(package private) void
servicePropertiesModified(ServiceRegistration<?> reg, java.util.Dictionary oldProps)
boolean
ungetService(Bundle bundle, ServiceReference<?> ref, java.lang.Object svcObj)
void
ungetServices(Bundle bundle)
This is a utility method to release all services being used by the specified bundle.void
unregisterService(Bundle bundle, ServiceRegistration<?> reg)
void
unregisterServices(Bundle bundle)
This method retrieves all services registrations for the specified bundle and invokes ServiceRegistration.unregister() on each one.private void
updateHook(ServiceReference<?> ref)
-
-
-
Field Detail
-
m_logger
private final Logger m_logger
-
m_currentServiceId
private long m_currentServiceId
-
m_regsMap
private final java.util.Map<Bundle,ServiceRegistration<?>[]> m_regsMap
-
m_regCapSet
private final CapabilitySet m_regCapSet
-
m_lockedRegsMap
private final java.util.Map<ServiceRegistration<?>,java.lang.Object> m_lockedRegsMap
-
m_inUseMap
private final java.util.Map<Bundle,ServiceRegistry.UsageCount[]> m_inUseMap
-
m_callbacks
private final ServiceRegistry.ServiceRegistryCallbacks m_callbacks
-
m_blackList
private final java.util.WeakHashMap<ServiceReference<?>,ServiceReference<?>> m_blackList
-
m_hookClasses
private static final java.lang.Class<?>[] m_hookClasses
-
m_allHooks
private final java.util.Map<java.lang.Class<?>,java.util.Set<ServiceReference<?>>> m_allHooks
-
-
Constructor Detail
-
ServiceRegistry
public ServiceRegistry(Logger logger, ServiceRegistry.ServiceRegistryCallbacks callbacks)
-
-
Method Detail
-
getRegisteredServices
public ServiceReference<?>[] getRegisteredServices(Bundle bundle)
-
registerService
public ServiceRegistration<?> registerService(BundleContext context, java.lang.String[] classNames, java.lang.Object svcObj, java.util.Dictionary dict)
-
unregisterService
public void unregisterService(Bundle bundle, ServiceRegistration<?> reg)
-
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 getServiceReferences(java.lang.String className, SimpleFilter filter)
-
getServicesInUse
public ServiceReference<?>[] getServicesInUse(Bundle bundle)
-
getService
public <S> S getService(Bundle bundle, ServiceReference<S> ref, boolean isPrototype)
-
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()
-
addServiceRegistration
private static ServiceRegistration<?>[] addServiceRegistration(ServiceRegistration<?>[] regs, ServiceRegistration<?> reg)
-
removeServiceRegistration
private static ServiceRegistration<?>[] removeServiceRegistration(ServiceRegistration<?>[] regs, ServiceRegistration<?> reg)
-
getUsageCount
private ServiceRegistry.UsageCount getUsageCount(Bundle bundle, ServiceReference<?> ref, java.lang.Object svcObj)
Utility method to retrieve the specified bundle's usage count for the specified service reference.- Parameters:
bundle
- The bundle whose usage counts are being searched.ref
- The service reference to find in the bundle's usage counts.- Returns:
- The associated usage count or null if not found.
-
addUsageCount
private ServiceRegistry.UsageCount addUsageCount(Bundle bundle, ServiceReference<?> ref, boolean isPrototype)
Utility method to update the specified bundle's usage count array to include the specified service. This method should only be called to add a usage count for a previously unreferenced service. If the service already has a usage count, then the existing usage count counter simply needs to be incremented.- Parameters:
bundle
- The bundle acquiring the service.ref
- The service reference of the acquired service.svcObj
- The service object of the acquired service.
-
flushUsageCount
private 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.
-
isHookBlackListed
boolean isHookBlackListed(ServiceReference<?> sr)
-
blackListHook
void blackListHook(ServiceReference<?> sr)
-
isHook
static boolean isHook(java.lang.String[] classNames, java.lang.Class<?> hookClass, java.lang.Object svcObj)
-
addHooks
private void addHooks(java.lang.String[] classNames, java.lang.Object svcObj, ServiceReference<?> ref)
-
updateHook
private void updateHook(ServiceReference<?> ref)
-
removeHook
private void removeHook(ServiceReference<?> ref)
-
getHooks
public <S> java.util.Set<ServiceReference<S>> getHooks(java.lang.Class<S> hookClass)
-
asTypedSortedSet
private static <S> java.util.SortedSet<ServiceReference<S>> asTypedSortedSet(java.util.SortedSet<ServiceReference<?>> ss)
-
-