|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.felix.ipojo.util.Tracker
public class Tracker
Utility class close to the OSGi Service Tracker. This class is used when tracking dynamic services is required.
Field Summary | |
---|---|
protected BundleContext |
m_context
The bundle context against which this Tracker object is tracking. |
protected TrackerCustomizer |
m_customizer
The TrackerCustomizer object for this tracker. |
protected Filter |
m_filter
the filter specifying search criteria for the services to track. |
protected String |
m_listenerFilter
The filter string for use when adding the ServiceListener. |
Constructor Summary | |
---|---|
Tracker(BundleContext context,
Filter filter,
TrackerCustomizer customizer)
Creates a Tracker object on the specified Filter object. |
|
Tracker(BundleContext context,
ServiceReference reference,
TrackerCustomizer customizer)
Creates a Tracker object on the specified ServiceReference object. |
|
Tracker(BundleContext context,
String clazz,
TrackerCustomizer customizer)
Creates a Tracker object on the specified class name. |
Method Summary | |
---|---|
void |
addedService(ServiceReference reference)
Default implementation of the TrackerCustomizer.addedService method. |
boolean |
addingService(ServiceReference reference)
Default implementation of the TrackerCustomizer.addingService method. |
void |
close()
Closes this Tracker object. |
Object |
getService()
Returns a service object for one of the services being tracked by this Tracker object. |
Object |
getService(ServiceReference reference)
Returns the service object for the specified ServiceReference object if the referenced service is being tracked by this Tracker object. |
ServiceReference |
getServiceReference()
Returns a ServiceReference object for one of the services being tracked by this Tracker object. |
ServiceReference[] |
getServiceReferences()
Returns an array of ServiceReference objects for all services being tracked by this Tracker object. |
List |
getServiceReferencesList()
Gets the list of stored service reference. |
Object[] |
getServices()
Returns an array of service objects for all services being tracked by this Tracker object. |
List |
getUsedServiceReferences()
Returns the list of references used by the tracker. |
void |
modifiedService(ServiceReference reference,
Object service)
Default implementation of the TrackerCustomizer.modifiedService method. |
void |
open()
Opens this Tracker object and begin tracking services. |
void |
remove(ServiceReference reference)
Removes a service from this Tracker object. |
void |
removedService(ServiceReference reference,
Object service)
Default implementation of the TrackerCustomizer.removedService method. |
int |
size()
Returns the number of services being tracked by this Tracker object. |
void |
ungetService(ServiceReference reference)
Ungets the given service reference. |
Object |
waitForService(long timeout)
Waits for at least one service to be tracked by this Tracker object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected BundleContext m_context
protected Filter m_filter
protected TrackerCustomizer m_customizer
protected String m_listenerFilter
Constructor Detail |
---|
public Tracker(BundleContext context, ServiceReference reference, TrackerCustomizer customizer)
context
- The BundleContext object against which the tracking is done.reference
- The ServiceReference object for the service to be tracked.customizer
- The customizer object to call when services are added, modified, or removed in this Tracker object. If customizer is null, then this Tracker object will be used as
the TrackerCustomizer object and the Tracker object will call the TrackerCustomizer methods on itself.public Tracker(BundleContext context, String clazz, TrackerCustomizer customizer)
context
- the BundleContext object against which the tracking is done.clazz
- the Class name of the services to be tracked.customizer
- the customizer object to call when services are added, modified, or removed in this Tracker object. If customizer is null, then this Tracker object will be used as
the TrackerCustomizer object and the Tracker object will call the TrackerCustomizer methods on itself.public Tracker(BundleContext context, Filter filter, TrackerCustomizer customizer)
Services which match the specified Filter object will be tracked by this Tracker object.
context
- the BundleContext object against which the tracking is done.filter
- the Filter object to select the services to be tracked.customizer
- The customizer object to call when services are added, modified, or removed in this Tracker object. If customizer is null, then this Tracker object will be used as the
TrackerCustomizer object and the Tracker object will call the TrackerCustomizer methods on itself.Method Detail |
---|
public void open()
Services which match the search criteria specified when this Tracker object was created are now tracked by this Tracker object.
public void close()
This method should be called when this Tracker object should end the tracking of services.
public boolean addingService(ServiceReference reference)
This method is only called when this Tracker object has been constructed with a null TrackerCustomizer argument. The default implementation returns the result of calling getService, on the BundleContext object with which this Tracker object was created, passing the specified ServiceReference object.
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 that will unget the service.
addingService
in interface TrackerCustomizer
reference
- the Reference to service being added to this Tracker object.
TrackerCustomizer
public void addedService(ServiceReference reference)
addedService
in interface TrackerCustomizer
reference
- the added reference.TrackerCustomizer.addedService(org.osgi.framework.ServiceReference)
public void modifiedService(ServiceReference reference, Object service)
This method is only called when this Tracker object has been constructed with a null TrackerCustomizer argument. The default implementation does nothing.
modifiedService
in interface TrackerCustomizer
reference
- the Reference to modified service.service
- The service object for the modified service.TrackerCustomizer
public void removedService(ServiceReference reference, Object service)
This method is only called when this Tracker object has been constructed with a null TrackerCustomizer argument. The default implementation calls ungetService, on the BundleContext object with which this Tracker object was created, passing the specified ServiceReference object.
This method can be overridden in a subclass. If the default implementation of addingService method was used, this method must unget the service.
removedService
in interface TrackerCustomizer
reference
- the Reference to removed service.service
- The service object for the removed service.TrackerCustomizer
public Object waitForService(long timeout) throws InterruptedException
It is strongly recommended that waitForService is not used during the calling of the BundleActivator methods. BundleActivator methods are expected to complete in a short period of time.
timeout
- the time interval in milliseconds to wait. If zero, the method will wait indefinately.
InterruptedException
- If another thread has interrupted the current thread.public ServiceReference[] getServiceReferences()
null
if no service are being tracked.public List getServiceReferencesList()
public List getUsedServiceReferences()
public ServiceReference getServiceReference()
public Object getService(ServiceReference reference)
reference
- the Reference to the desired service.
null
if the service referenced by the specified ServiceReference object is not being tracked.public void ungetService(ServiceReference reference)
reference
- the service reference to unget.public Object[] getServices()
null
if no service are being tracked.public Object getService()
If any services are being tracked, this method returns the result of calling getService(getServiceReference()).
null
if no service is being tracked.public void remove(ServiceReference reference)
reference
- the Reference to the service to be removed.public int size()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |