Class ServiceRegistry


  • public class ServiceRegistry
    extends java.lang.Object
    • 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 service
        classNames - The service class names
        svcObj - The service object
        dict - Optional service properties
        Returns:
        Service registration
      • unregisterService

        public void unregisterService​(Bundle bundle,
                                      ServiceRegistration<?> reg)
        Unregister a service
        Parameters:
        bundle - The bundle unregistering the service
        reg - The service registration
      • 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)
      • 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.
      • 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 the m_inUseMap. If one is found then this is returned, otherwise a UsageCount object will be created, but this can only be done if the isPrototype parameter is not null. If isPrototype is TRUE then 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 - TRUE if 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 use null.
        Returns:
        The UsageCount object if it could be obtained, or null otherwise.
      • 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.