Package org.apache.felix.framework
Class ServiceRegistry
java.lang.Object
org.apache.felix.framework.ServiceRegistry
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classstatic interface(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final HookRegistryprivate final ServiceRegistry.ServiceRegistryCallbacksprivate final AtomicLongCounter for the service idprivate final ConcurrentMap<Bundle, ServiceRegistry.UsageCount[]> private final Loggerprivate final CapabilitySetprivate final ConcurrentMap<Bundle, List<ServiceRegistration<?>>> -
Constructor Summary
ConstructorsConstructorDescriptionServiceRegistry(Logger logger, ServiceRegistry.ServiceRegistryCallbacks callbacks) -
Method Summary
Modifier and TypeMethodDescriptionprivate 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.ServiceReference<?>[]getRegisteredServices(Bundle bundle) Get all service references for a bundle<S> SgetService(Bundle bundle, ServiceReference<S> ref, boolean isServiceObjects) getServiceReferences(String className, SimpleFilter filter) ServiceReference<?>[]getServicesInUse(Bundle bundle) Bundle[]getUsingBundles(ServiceReference<?> ref) private void(package private) ServiceRegistry.UsageCountobtainUsageCount(Bundle bundle, ServiceReference<?> ref, Object svcObj, Boolean isPrototype) Obtain a UsageCount object, by looking for an existing one or creating a new one (if possible).registerService(Bundle bundle, String[] classNames, Object svcObj, Dictionary<?, ?> dict) Register a new service Caller must fire service event as this method is not doing it!(package private) voidservicePropertiesModified(ServiceRegistration<?> reg, Dictionary<String, ?> oldProps) booleanungetService(Bundle bundle, ServiceReference<?> ref, 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 Details
-
m_logger
-
m_currentServiceId
Counter for the service id -
m_regsMap
-
m_regCapSet
-
m_inUseMap
-
m_callbacks
-
hookRegistry
-
-
Constructor Details
-
ServiceRegistry
-
-
Method Details
-
getRegisteredServices
Get all service references for a bundle- Parameters:
bundle-- Returns:
- List with all valid service references or
null.
-
registerService
public ServiceRegistration<?> registerService(Bundle bundle, String[] classNames, Object svcObj, 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
Unregister a service- Parameters:
bundle- The bundle unregistering the servicereg- The service registration
-
ungetServices
-
unregisterServices
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
-
getServicesInUse
-
getService
-
incrementToPositiveValue
-
checkCountOverflow
private void checkCountOverflow(long c) -
ungetService
-
ungetServices
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
-
servicePropertiesModified
-
getLogger
-
obtainUsageCount
ServiceRegistry.UsageCount obtainUsageCount(Bundle bundle, ServiceReference<?> ref, Object svcObj, 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, invalid input: '{@' 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
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
-