Class CyServiceRegistrarImpl

  • All Implemented Interfaces:
    CyServiceRegistrar

    public class CyServiceRegistrarImpl
    extends Object
    implements CyServiceRegistrar
    Implementation of CyServiceRegistrar. This is part of service-api instead of service-impl. This class uses code from ServiceUtil, which is also used by AbstractCyActivator. This class has to be part of service-api so that it can use ServiceUtil.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <S> S getService​(Class<S> serviceClass)
      A method that attempts to get a service of the specified type.
      <S> S getService​(Class<S> serviceClass, String filter)
      A method that attempts to get a service of the specified type and that passes the specified filter.
      void registerAllServices​(Object service, Properties props)
      This method registers an object as an OSGi service for all interfaces that the object implements and with the specified properties.
      void registerService​(Object service, Class serviceClass, Properties props)
      This method registers an object as an OSGi service with the specified service interface and properties.
      void registerServiceListener​(Object listener, String registerMethodName, String unregisterMethodName, Class<?> serviceClass)
      A method that will cause the specified register/unregister methods on the listener object to be called any time that a service of the specified type is registered or unregistered.
      void registerServiceListener​(Object listener, String registerMethodName, String unregisterMethodName, Class<?> serviceClass, Class<?> methodClass)
      A method that will cause the specified register/unregister methods on the listener object to be called any time that a service of the specified type is registered or unregistered.
      void registerServiceListener​(Object listener, String registerMethodName, String unregisterMethodName, Class<?> serviceClass, Class<?> methodClass, String additionalFilter)
      A method that will cause the specified register/unregister methods on the listener object to be called any time that a service of the specified type is registered or unregistered.
      void registerServiceListener​(Object listener, String registerMethodName, String unregisterMethodName, Class<?> serviceClass, String additionalFilter)
      A method that will cause the specified register/unregister methods on the listener object to be called any time that a service of the specified type is registered or unregistered.
      void unregisterAllServices​(Object o)
      This method unregisters an object as all OSGi service interfaces that the object implements.
      void unregisterService​(Object o, Class c)
      This method unregisters an object as an OSGi service for the specified service interface.
    • Constructor Detail

      • CyServiceRegistrarImpl

        public CyServiceRegistrarImpl​(BundleContext bc)
    • Method Detail

      • registerAllServices

        public void registerAllServices​(Object service,
                                        Properties props)
        This method registers an object as an OSGi service for all interfaces that the object implements and with the specified properties. Note that this method will NOT register services for any packages with names that begin with "java", which is an effort to avoid registering meaningless services for core Java APIs.
        Specified by:
        registerAllServices in interface CyServiceRegistrar
        Parameters:
        service - The object to be registered as a service for all interfaces that the object implements.
        props - The service properties.
      • registerService

        public void registerService​(Object service,
                                    Class serviceClass,
                                    Properties props)
        This method registers an object as an OSGi service with the specified service interface and properties.
        Specified by:
        registerService in interface CyServiceRegistrar
        Parameters:
        service - The object to be registered as a service.
        serviceClass - The service interface the object should be registered as.
        props - The service properties.
      • unregisterAllServices

        public void unregisterAllServices​(Object o)
        This method unregisters an object as all OSGi service interfaces that the object implements.
        Specified by:
        unregisterAllServices in interface CyServiceRegistrar
        Parameters:
        o - The object to be unregistered for services it provides.
      • unregisterService

        public void unregisterService​(Object o,
                                      Class c)
        This method unregisters an object as an OSGi service for the specified service interface.
        Specified by:
        unregisterService in interface CyServiceRegistrar
        Parameters:
        o - The object to be unregistered as a service.
        c - The service interface the object should be unregistered as.
      • getService

        public <S> S getService​(Class<S> serviceClass)
        A method that attempts to get a service of the specified type. If an appropriate service is not found, an exception will be thrown.
        Specified by:
        getService in interface CyServiceRegistrar
        Type Parameters:
        S - The generic type of the class defining the type of service desired.
        Parameters:
        serviceClass - The class defining the type of service desired.
        Returns:
        A reference to a service of type serviceClass.
      • getService

        public <S> S getService​(Class<S> serviceClass,
                                String filter)
        A method that attempts to get a service of the specified type and that passes the specified filter. If an appropriate service is not found, an exception will be thrown.
        Specified by:
        getService in interface CyServiceRegistrar
        Type Parameters:
        S - The generic type of the class defining the type of service desired.
        Parameters:
        serviceClass - The class defining the type of service desired.
        filter - The string defining the filter the service must pass. See OSGi's service filtering syntax for more detail.
        Returns:
        A reference to a service of type serviceClass that passes the specified filter.
      • registerServiceListener

        public void registerServiceListener​(Object listener,
                                            String registerMethodName,
                                            String unregisterMethodName,
                                            Class<?> serviceClass,
                                            Class<?> methodClass,
                                            String additionalFilter)
        A method that will cause the specified register/unregister methods on the listener object to be called any time that a service of the specified type is registered or unregistered.
        Specified by:
        registerServiceListener in interface CyServiceRegistrar
        Parameters:
        listener - Your object listening for service registrations.
        registerMethodName - The name of the method to be called when a service is registered.
        unregisterMethodName - The name of the method to be called when a service is unregistered.
        serviceClass - The class defining the type of service desired.
        methodClass - There are situations where, because of the use of generics and type erasure that the serviceClass is a subclass of the class used by the registration method, in which case, this extra argument allows that class to be specified.
        additionalFilter - An additional filter to be applied to the OSGi services
      • registerServiceListener

        public void registerServiceListener​(Object listener,
                                            String registerMethodName,
                                            String unregisterMethodName,
                                            Class<?> serviceClass)
        A method that will cause the specified register/unregister methods on the listener object to be called any time that a service of the specified type is registered or unregistered.
        Specified by:
        registerServiceListener in interface CyServiceRegistrar
        Parameters:
        listener - Your object listening for service registrations.
        registerMethodName - The name of the method to be called when a service is registered.
        unregisterMethodName - The name of the method to be called when a service is unregistered.
        serviceClass - The class defining the type of service desired.
      • registerServiceListener

        public void registerServiceListener​(Object listener,
                                            String registerMethodName,
                                            String unregisterMethodName,
                                            Class<?> serviceClass,
                                            String additionalFilter)
        A method that will cause the specified register/unregister methods on the listener object to be called any time that a service of the specified type is registered or unregistered.
        Specified by:
        registerServiceListener in interface CyServiceRegistrar
        Parameters:
        listener - Your object listening for service registrations.
        registerMethodName - The name of the method to be called when a service is registered.
        unregisterMethodName - The name of the method to be called when a service is unregistered.
        serviceClass - The class defining the type of service desired.
        additionalFilter - An additional filter to be applied to the OSGi services
      • registerServiceListener

        public void registerServiceListener​(Object listener,
                                            String registerMethodName,
                                            String unregisterMethodName,
                                            Class<?> serviceClass,
                                            Class<?> methodClass)
        A method that will cause the specified register/unregister methods on the listener object to be called any time that a service of the specified type is registered or unregistered.
        Specified by:
        registerServiceListener in interface CyServiceRegistrar
        Parameters:
        listener - Your object listening for service registrations.
        registerMethodName - The name of the method to be called when a service is registered.
        unregisterMethodName - The name of the method to be called when a service is unregistered.
        serviceClass - The class defining the type of service desired.
        methodClass - There are situations where, because of the use of generics and type erasure that the serviceClass is a subclass of the class used by the registration method, in which case, this extra argument allows that class to be specified.