Class ServiceSelector<T>

java.lang.Object
ddf.catalog.util.impl.ServiceSelector<T>
Type Parameters:
T - - The type of the service to be served up by this implementation of ServiceSelector ServiceSelectionStrategy ServiceSelectorConverter ServiceComparator

public class ServiceSelector<T> extends Object
The ServiceSelector maintains a sorted set of bound OSGi services and provides user access to those services. It covers 2 use-cases: point-to-point and pub-sub.

In the point-to-point scenario a user needs to select a single service from the set of available services. The appropriate service to select is determined by the ServiceSelectionStrategy implementation that is provided to the ServiceSelector constructor. It can be retrieved by calling the 'getService()' method.

In the pub-sub scenario, the user needs to access all of the service implementations in the internal set. An unmodifiable view of the internal set can be retrieved by a call to 'getAllServices()'.

In both scenarios, the set order is determined by the Comparator object supplied to the ServiceSelector at creation.

OSGi requires a type converter to be registered for this class. Typically, it will also be used a reference-listener.

Example:

 
 
  • Constructor Details

    • ServiceSelector

      public ServiceSelector()
      This default constructor is equivalent to calling: new ServiceSelector(new ddf.catalog.util.impl.ServiceComparator(), new FirstElementServiceSelectionStrategy())
    • ServiceSelector

      public ServiceSelector(Comparator serviceComparator)
      This constructor allows the user to set the comparator to be used by this ServiceSelector which allows them to set the internal set order. It uses a FirstElementServiceSelectionStrategy.
      Parameters:
      serviceComparator - - The comparator used to determine the internal set order.
    • ServiceSelector

      public ServiceSelector(ServiceSelectionStrategy serviceSelectionStrategy)
    • ServiceSelector

      public ServiceSelector(Comparator serviceComparator, ServiceSelectionStrategy serviceSelectionStrategy)
  • Method Details

    • getService

      public T getService()
    • getAllServices

      public SortedSet<org.osgi.framework.ServiceReference<T>> getAllServices()
    • bindService

      public void bindService(org.osgi.framework.ServiceReference serviceReference)
    • unbindService

      public void unbindService(org.osgi.framework.ServiceReference serviceReference)