Class ServiceRegistry


  • public class ServiceRegistry
    extends java.lang.Object
    • Method Detail

      • registerService

        public ServiceRegistration<?> registerService​(BundleContext context,
                                                      java.lang.String[] classNames,
                                                      java.lang.Object svcObj,
                                                      java.util.Dictionary dict)
      • 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)
      • 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()
      • 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.
      • 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)
      • getHooks

        public <S> java.util.Set<ServiceReference<S>> getHooks​(java.lang.Class<S> hookClass)