S
- T
- public class ServiceTracker<S,T,U extends org.osgi.framework.ServiceEvent>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
(package private) class |
ServiceTracker.AbstractTracked<S,T,R>
Abstract class to track items.
|
private class |
ServiceTracker.Tracked
Inner class which subclasses AbstractTracked.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
active
whether the DependencyManager is getting the service immediately.
|
private java.lang.String |
classFilterString |
protected org.osgi.framework.BundleContext |
context
The Bundle Context used by this
ServiceTracker . |
(package private) ServiceTrackerCustomizer<S,T,U> |
customizer
The
ServiceTrackerCustomizer for this tracker. |
(package private) static boolean |
DEBUG |
protected org.osgi.framework.Filter |
eventFilter
The Filter used by this
ServiceTracker which specifies the search
criteria for the services to track. |
private ExtendedServiceListenerContext<U> |
extendedServiceListenerContext |
(package private) java.lang.String |
initialReferenceFilterString
Filter string for use when adding the ServiceListener.
|
private ServiceTracker.Tracked |
tracked
Tracked services:
ServiceReference -> customized Object and
ServiceListener object |
Constructor and Description |
---|
ServiceTracker(org.osgi.framework.BundleContext context,
ServiceTrackerCustomizer<S,T,U> customizer,
boolean initialActive,
ExtendedServiceListenerContext<U> bundleComponentActivator,
org.osgi.framework.Filter eventFilter,
java.lang.String classFilterString,
java.lang.String initialReferenceFilterString)
Create a
ServiceTracker on the specified Filter object. |
Modifier and Type | Method and Description |
---|---|
T |
addingService(org.osgi.framework.ServiceReference<S> reference,
int trackingCount)
Default implementation of the
ServiceTrackerCustomizer.addingService method. |
java.util.SortedMap<org.osgi.framework.ServiceReference<S>,T> |
close(java.util.concurrent.atomic.AtomicInteger trackingCount)
Close this
ServiceTracker . |
void |
completeClose(java.util.Map<org.osgi.framework.ServiceReference<S>,T> toUntrack) |
(package private) void |
deactivate() |
private org.osgi.framework.ServiceReference<S>[] |
getInitialReferences(java.lang.String className,
java.lang.String filterString)
Returns the list of initial
ServiceReference s that will be
tracked by this ServiceTracker . |
T |
getService(org.osgi.framework.ServiceReference<S> reference)
Returns the service object for the specified
ServiceReference if
the specified referenced service is being tracked by this
ServiceTracker . |
int |
getServiceCount() |
org.osgi.framework.ServiceReference<S>[] |
getServiceReferences()
Return an array of
ServiceReference s for all services being
tracked by this ServiceTracker . |
java.lang.Object[] |
getServices()
Return an array of service objects for all services being tracked by this
ServiceTracker . |
T[] |
getServices(T[] array)
Return an array of service objects for all services being tracked by this
ServiceTracker . |
java.util.SortedMap<org.osgi.framework.ServiceReference<S>,T> |
getTracked(java.lang.Boolean activate,
java.util.concurrent.atomic.AtomicInteger trackingCount)
Return a
SortedMap of the ServiceReference s and service
objects for all services being tracked by this ServiceTracker . |
int |
getTrackingCount()
Returns the tracking count for this
ServiceTracker . |
boolean |
isActive() |
boolean |
isEmpty()
Return if this
ServiceTracker is empty. |
(package private) void |
modified()
Called by the Tracked object whenever the set of tracked services is
modified.
|
void |
modifiedService(org.osgi.framework.ServiceReference<S> reference,
T service,
int trackingCount)
Default implementation of the
ServiceTrackerCustomizer.modifiedService method. |
void |
open(java.util.concurrent.atomic.AtomicInteger trackingCount)
Open this
ServiceTracker and begin tracking services. |
void |
open(boolean trackAllServices,
java.util.concurrent.atomic.AtomicInteger trackingCount)
Open this
ServiceTracker and begin tracking services. |
void |
remove(org.osgi.framework.ServiceReference<S> reference)
Remove a service from this
ServiceTracker . |
void |
removedService(org.osgi.framework.ServiceReference<S> reference,
T service,
int trackingCount)
Default implementation of the
ServiceTrackerCustomizer.removedService method. |
int |
size()
Return the number of services being tracked by this
ServiceTracker . |
ServiceTracker.Tracked |
tracked()
Accessor method for the current Tracked object.
|
static final boolean DEBUG
protected final org.osgi.framework.BundleContext context
ServiceTracker
.protected final org.osgi.framework.Filter eventFilter
ServiceTracker
which specifies the search
criteria for the services to track.final ServiceTrackerCustomizer<S,T,U extends org.osgi.framework.ServiceEvent> customizer
ServiceTrackerCustomizer
for this tracker.final java.lang.String initialReferenceFilterString
private volatile ServiceTracker.Tracked tracked
ServiceReference
-> customized Object and
ServiceListener
objectprivate boolean active
private ExtendedServiceListenerContext<U extends org.osgi.framework.ServiceEvent> extendedServiceListenerContext
private java.lang.String classFilterString
public ServiceTracker(org.osgi.framework.BundleContext context, ServiceTrackerCustomizer<S,T,U> customizer, boolean initialActive, ExtendedServiceListenerContext<U> bundleComponentActivator, org.osgi.framework.Filter eventFilter, java.lang.String classFilterString, java.lang.String initialReferenceFilterString)
ServiceTracker
on the specified Filter
object.
Services which match the specified Filter
object will be tracked
by this ServiceTracker
.
context
- The BundleContext
against which the tracking is
done.customizer
- The customizer object to call when services are added,
modified, or removed in this ServiceTracker
. If customizer
is null, then this ServiceTracker
will be used as the
ServiceTrackerCustomizer
and this ServiceTracker
will call the ServiceTrackerCustomizer
methods on itself.initialActive
- Initial active state of the tracker.bundleComponentActivator
- TODOeventFilter
- The Filter
to select the services to be tracked.classFilterString
- TODOinitialReferenceFilterString
- TODOpublic ServiceTracker.Tracked tracked()
public void open(java.util.concurrent.atomic.AtomicInteger trackingCount)
ServiceTracker
and begin tracking services.
This implementation calls open(false)
.
trackingCount
- java.lang.IllegalStateException
- If the BundleContext
with
which this ServiceTracker
was created is no longer valid.open(boolean, java.util.concurrent.atomic.AtomicInteger)
public void open(boolean trackAllServices, java.util.concurrent.atomic.AtomicInteger trackingCount)
ServiceTracker
and begin tracking services.
Services which match the search criteria specified when this
ServiceTracker
was created are now tracked by this
ServiceTracker
.
trackAllServices
- If true
, then this ServiceTracker
will track all matching services regardless of class loader
accessibility. If false
, then this ServiceTracker
will only track matching services which are class loader
accessible to the bundle whose BundleContext
is used by
this ServiceTracker
.trackingCount
- java.lang.IllegalStateException
- If the BundleContext
with
which this ServiceTracker
was created is no longer valid.private org.osgi.framework.ServiceReference<S>[] getInitialReferences(java.lang.String className, java.lang.String filterString) throws org.osgi.framework.InvalidSyntaxException
ServiceReference
s that will be
tracked by this ServiceTracker
.className
- The class name with which the service was registered, or
null
for all services.filterString
- The filter criteria or null
for all services.ServiceReference
s.org.osgi.framework.InvalidSyntaxException
- If the specified filterString has an
invalid syntax.public java.util.SortedMap<org.osgi.framework.ServiceReference<S>,T> close(java.util.concurrent.atomic.AtomicInteger trackingCount)
ServiceTracker
.
This method should be called when this ServiceTracker
should end
the tracking of services.
This implementation calls getServiceReferences()
to get the list
of tracked services to remove.
trackingCount
- public void completeClose(java.util.Map<org.osgi.framework.ServiceReference<S>,T> toUntrack)
public T addingService(org.osgi.framework.ServiceReference<S> reference, int trackingCount)
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.
reference
- The reference to the service being added to this
ServiceTracker
.ServiceTracker
.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference
public void modifiedService(org.osgi.framework.ServiceReference<S> reference, T service, int trackingCount)
ServiceTrackerCustomizer.modifiedService
method.
This method is only called when this ServiceTracker
has been
constructed with a null ServiceTrackerCustomizer
argument.
This implementation does nothing.
reference
- The reference to modified service.service
- The service object for the modified service.ServiceTrackerCustomizer.modifiedService(org.osgi.framework.ServiceReference, Object, int, ServiceEvent)
public void removedService(org.osgi.framework.ServiceReference<S> reference, T service, int trackingCount)
ServiceTrackerCustomizer.removedService
method.
This method is only called when this ServiceTracker
has been
constructed with a null ServiceTrackerCustomizer
argument.
This implementation calls ungetService
, on the
BundleContext
with which this ServiceTracker
was created,
passing the specified ServiceReference
.
This method can be overridden in a subclass. If the default
implementation of addingService
method was used, this method must unget the service.
reference
- The reference to removed service.service
- The service object for the removed service.ServiceTrackerCustomizer.removedService(org.osgi.framework.ServiceReference, Object, int, ServiceEvent)
public org.osgi.framework.ServiceReference<S>[] getServiceReferences()
ServiceReference
s for all services being
tracked by this ServiceTracker
.ServiceReference
s or null
if no services
are being tracked.public T getService(org.osgi.framework.ServiceReference<S> reference)
ServiceReference
if
the specified referenced service is being tracked by this
ServiceTracker
.reference
- The reference to the desired service.null
if the service referenced by the
specified ServiceReference
is not being tracked.public java.lang.Object[] getServices()
ServiceTracker
.
This implementation calls getServiceReferences()
to get the list
of references for the tracked services and then calls
getService(ServiceReference)
for each reference to get the
tracked service object.
null
if no services are
being tracked.public void remove(org.osgi.framework.ServiceReference<S> reference)
ServiceTracker
.
The specified service will be removed from this ServiceTracker
.
If the specified service was being tracked then the
ServiceTrackerCustomizer.removedService
method will be called for
that service.reference
- The reference to the service to be removed.public int size()
ServiceTracker
.public int getTrackingCount()
ServiceTracker
.
The tracking count is initialized to 0 when this ServiceTracker
is opened. Every time a service is added, modified or removed from this
ServiceTracker
, the tracking count is incremented.
The tracking count can be used to determine if this
ServiceTracker
has added, modified or removed a service by
comparing a tracking count value previously collected with the current
tracking count value. If the value has not changed, then no service has
been added, modified or removed from this ServiceTracker
since
the previous tracking count was collected.
ServiceTracker
or -1 if this
ServiceTracker
is not open.void modified()
public java.util.SortedMap<org.osgi.framework.ServiceReference<S>,T> getTracked(java.lang.Boolean activate, java.util.concurrent.atomic.AtomicInteger trackingCount)
SortedMap
of the ServiceReference
s and service
objects for all services being tracked by this ServiceTracker
.
The map is sorted in reverse natural order of ServiceReference
.
That is, the first entry is the service with the highest ranking and the
lowest service id.activate
- trackingCount
- SortedMap
with the ServiceReference
s and
service objects for all services being tracked by this
ServiceTracker
. If no services are being tracked, then
the returned map is empty.void deactivate()
public boolean isEmpty()
ServiceTracker
is empty.true
if this ServiceTracker
is not tracking any
services.public int getServiceCount()
public boolean isActive()
public T[] getServices(T[] array)
ServiceTracker
. The runtime type of the returned array is that of
the specified array.
This implementation calls getServiceReferences()
to get the list
of references for the tracked services and then calls
getService(ServiceReference)
for each reference to get the
tracked service object.
array
- An array into which the tracked service objects will be
stored, if the array is large enough.null
. If the specified array is not large enough
to hold the result, a new array is created and returned.