Class SortingServiceTracker<T>
- java.lang.Object
-
- org.osgi.util.tracker.ServiceTracker<T,T>
-
- org.apache.sling.commons.osgi.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 Summary
Constructors Constructor Description SortingServiceTracker(BundleContext context, String clazz)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
addingService(ServiceReference<T> reference)
Default implementation of theServiceTrackerCustomizer.addingService
method.List<ServiceReference<T>>
getSortedServiceReferences()
Return a sorted list of the services references.List<T>
getSortedServices()
Return a sorted list of the services.void
modifiedService(ServiceReference<T> reference, T service)
Default implementation of theServiceTrackerCustomizer.modifiedService
method.void
removedService(ServiceReference<T> reference, T service)
Default implementation of theServiceTrackerCustomizer.removedService
method.-
Methods inherited from class org.osgi.util.tracker.ServiceTracker
close, getService, getService, getServiceReference, getServiceReferences, getServices, getServices, getTracked, getTrackingCount, isEmpty, open, open, remove, size, waitForService
-
-
-
-
Constructor Detail
-
SortingServiceTracker
public SortingServiceTracker(BundleContext context, String clazz)
Constructor- Parameters:
context
- Bundle contextclazz
- Class
-
-
Method Detail
-
removedService
public void removedService(ServiceReference<T> reference, T service)
Description copied from class:ServiceTracker
Default implementation of theServiceTrackerCustomizer.removedService
method.This method is only called when this
ServiceTracker
has been constructed with anull ServiceTrackerCustomizer
argument.This implementation calls
ungetService
, on theBundleContext
with which thisServiceTracker
was created, passing the specifiedServiceReference
.This method can be overridden in a subclass. If the default implementation of
addingService
method was used, this method must unget the service.- Specified by:
removedService
in interfaceServiceTrackerCustomizer<T,T>
- Overrides:
removedService
in classServiceTracker<T,T>
- Parameters:
reference
- The reference to removed service.service
- The service object for the removed service.- See Also:
ServiceTracker.removedService(org.osgi.framework.ServiceReference, java.lang.Object)
-
modifiedService
public void modifiedService(ServiceReference<T> reference, T service)
Description copied from class:ServiceTracker
Default implementation of theServiceTrackerCustomizer.modifiedService
method.This method is only called when this
ServiceTracker
has been constructed with anull ServiceTrackerCustomizer
argument.This implementation does nothing.
- Specified by:
modifiedService
in interfaceServiceTrackerCustomizer<T,T>
- Overrides:
modifiedService
in classServiceTracker<T,T>
- Parameters:
reference
- The reference to modified service.service
- The service object for the modified service.- See Also:
ServiceTrackerCustomizer.modifiedService(org.osgi.framework.ServiceReference, java.lang.Object)
-
addingService
public T addingService(ServiceReference<T> reference)
Description copied from class:ServiceTracker
Default implementation of theServiceTrackerCustomizer.addingService
method.This method is only called when this
ServiceTracker
has been constructed with anull ServiceTrackerCustomizer
argument.This implementation returns the result of calling
getService
, on theBundleContext
with which thisServiceTracker
was created, passing the specifiedServiceReference
.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 interfaceServiceTrackerCustomizer<T,T>
- Overrides:
addingService
in classServiceTracker<T,T>
- Parameters:
reference
- The reference to the service being added to thisServiceTracker
.- Returns:
- The service object to be tracked for the service added to this
ServiceTracker
. - See Also:
ServiceTrackerCustomizer.addingService(org.osgi.framework.ServiceReference)
-
getSortedServices
public List<T> getSortedServices()
Return a sorted list of the services.- Returns:
- Service list
-
getSortedServiceReferences
public List<ServiceReference<T>> getSortedServiceReferences()
Return a sorted list of the services references.- Returns:
- Service list
-
-