Class SortingServiceTracker<T>

  • All Implemented Interfaces:
    ServiceTrackerCustomizer<T,​T>

    public class SortingServiceTracker<T>
    extends ServiceTracker<T,​T>
    Implementation providing a sorted list of services by service ranking.
    • Constructor Detail

      • SortingServiceTracker

        public SortingServiceTracker​(BundleContext context,
                                     java.lang.String clazz)
        Constructor
        Parameters:
        context - Bundle context
        clazz - Class
    • Method Detail

      • addingService

        public T addingService​(ServiceReference<T> reference)
        Description copied from class: ServiceTracker
        Default implementation of the ServiceTrackerCustomizer.addingService method.

        This method is only called when this ServiceTracker has been constructed with a null ServiceTrackerCustomizer argument.

        This implementation returns the result of calling getService, on the BundleContext with which this ServiceTracker was created, passing the specified ServiceReference.

        This method can be overridden in a subclass to customize the service object to be tracked for the service being added. In that case, take care not to rely on the default implementation of removedService to unget the service.

        Specified by:
        addingService in interface ServiceTrackerCustomizer<T,​T>
        Overrides:
        addingService in class ServiceTracker<T,​T>
        Parameters:
        reference - The reference to the service being added to this ServiceTracker.
        Returns:
        The service object to be tracked for the service added to this ServiceTracker.
        See Also:
        ServiceTrackerCustomizer.addingService(org.osgi.framework.ServiceReference)
      • getSortedServices

        public java.util.List<T> getSortedServices()
        Return a sorted list of the services.
        Returns:
        Service list
      • getSortedServiceReferences

        public java.util.List<ServiceReference<T>> getSortedServiceReferences()
        Return a sorted list of the services references.
        Returns:
        Service list