Class AbstractCyActivator

java.lang.Object
org.cytoscape.service.util.AbstractCyActivator
All Implemented Interfaces:
BundleActivator
Direct Known Subclasses:
CyActivator

public abstract class AbstractCyActivator extends Object implements BundleActivator
A simple BundleActivator with convenience methods for registering OSGi services and either getting references to single services or registering interest in all services of a specified type. Users should extend this class and implement the start(BundleContext bc) method. Methods in an AbstractCyActivator implementation should return quickly and should not block for user input.

Cytoscape Backwards Compatibility (Abstract Class): This class is abstract and meant to be extended by users. This means that we may add methods for minor version updates. Methods will only be removed for major version updates.

Module: service-api

To use this in your app, include the following dependency in your POM:

<dependency>
    <groupId>org.cytoscape</groupId>
    <artifactId>service-api</artifactId>
</dependency>
  • Constructor Details

    • AbstractCyActivator

      public AbstractCyActivator()
      Constructor.
  • Method Details

    • stop

      public final void stop(BundleContext bc)
      A default implementation of the BundleActivator.stop() method that cleans up any services registered, services gotten, or services being listened for as determined by calls to the utility methods provided by this class. If you register a service, get a service, or listen for services outside yourself using normal calls to the OSGi API, you will need to clean everything up yourself!
      Specified by:
      stop in interface BundleActivator
    • shutDown

      public void shutDown()
      Cleans up resources used by the app. If the app creates threads, adds menu items via Swing, or performs any other operation that modifies the environment, this method this method should be overridden to perform any necessary clean up.
    • getService

      protected final <S> S getService(BundleContext bc, 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.
      Type Parameters:
      S - The generic type of the class defining the type of service desired.
      Parameters:
      bc - The BundleContext used to find services.
      serviceClass - The class defining the type of service desired.
      Returns:
      A reference to a service of type serviceClass.
      Throws:
      RuntimeException - If the requested service can't be found.
    • getService

      protected final <S> S getService(BundleContext bc, 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.
      Type Parameters:
      S - The generic type of the class defining the type of service desired.
      Parameters:
      bc - The BundleContext used to find services.
      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.
      Throws:
      RuntimeException - If the requested service can't be found.
    • registerServiceListener

      protected final void registerServiceListener(BundleContext bc, 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.
      Parameters:
      bc - The BundleContext used to find services.
      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

      protected final void registerServiceListener(BundleContext bc, 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.
      Parameters:
      bc - The BundleContext used to find services.
      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

      protected final void registerServiceListener(BundleContext bc, 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.
      Parameters:
      bc - The BundleContext used to find services.
      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

      protected <S> void registerServiceListener(BundleContext bc, BiConsumer<S,​Map<String,​String>> registerConsumer, BiConsumer<S,​Map<String,​String>> unregisterConsumer, Class<S> 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.
       public class MyServiceListener {
          public void addService(MyService s, Map<String,String> props) { ... }
          public void removeService(MyService s, Map<String,String> props { ... }
       }
       
       registerServiceListener(bc, myServiceListener::addService, myServiceListener::removeService, MyService.class);
       
      Parameters:
      bc - The BundleContext used to find services.
      registerConsumer - A reference to the method to be called when a service is registered.
      unregisterConsumer - A reference to the method to be called when a service is unregistered.
      serviceClass - The class defining the type of service desired.
    • registerServiceListener

      protected <S> void registerServiceListener(BundleContext bc, BiConsumer<S,​Map<String,​String>> registerConsumer, BiConsumer<S,​Map<String,​String>> unregisterConsumer, Class<S> 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.
       public class MyServiceListener {
          public void addService(MyService s, Map<String,String< props) { ... }
          public void removeService(MyService s, Map<String,String> props { ... }
       }
       
       registerServiceListener(bc, myServiceListener::addService, myServiceListener::removeService, MyService.class);
       
      Parameters:
      bc - The BundleContext used to find services.
      registerConsumer - A reference to the method to be called when a service is registered.
      unregisterConsumer - A reference to 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

      protected final void registerServiceListener(BundleContext bc, 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.
      Parameters:
      bc - The BundleContext used to find services.
      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.
    • registerAllServices

      protected final void registerAllServices(BundleContext bc, Object service, Properties props)
      A utility method that registers the specified service object as an OSGi service for all interfaces that the object implements. 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.
      Parameters:
      bc - The BundleContext used to find services.
      service - The object to be registered as one or more services.
      props - The service properties to be registered with each service.
    • registerAllServices

      protected final void registerAllServices(BundleContext bc, Object service)
    • registerService

      protected final void registerService(BundleContext bc, Object service, Class<?> serviceClass, Properties props)
      A utility method that registers the specified service object as an OSGi service of the specified type.
      Parameters:
      bc - The BundleContext used to find services.
      service - The object to be registered as one or more services.
      serviceClass - The class defining the type of service to be registered.
      props - The service properties to be registered with each service.
    • registerService

      protected final void registerService(BundleContext bc, Object service, Class<?> serviceClass)