|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.felix.dependencymanager.ServiceTracker
public class ServiceTracker
TODO copied this from the OSGi specification, but it's not clear if that is allowed or not, for now I modified as little as possible but I might integrate only the parts I want as soon as this code is finished. Perhaps it would be better to borrow the Knopflerfish implementation here.
Field Summary | |
---|---|
protected org.osgi.framework.BundleContext |
context
Bundle context this ServiceTracker object is tracking against. |
protected org.osgi.framework.Filter |
filter
Filter specifying search criteria for the services to track. |
Constructor Summary | |
---|---|
ServiceTracker(org.osgi.framework.BundleContext context,
org.osgi.framework.Filter filter,
ServiceTrackerCustomizer customizer)
Create a ServiceTracker object on the specified Filter object. |
|
ServiceTracker(org.osgi.framework.BundleContext context,
org.osgi.framework.ServiceReference reference,
ServiceTrackerCustomizer customizer)
Create a ServiceTracker object on the specified ServiceReference object. |
|
ServiceTracker(org.osgi.framework.BundleContext context,
java.lang.String clazz,
ServiceTrackerCustomizer customizer)
Create a ServiceTracker object on the specified class name. |
Method Summary | |
---|---|
void |
addedService(org.osgi.framework.ServiceReference ref,
java.lang.Object service)
|
java.lang.Object |
addingService(org.osgi.framework.ServiceReference reference)
Default implementation of the ServiceTrackerCustomizer.addingService method. |
void |
close()
Close this ServiceTracker object. |
protected void |
finalize()
Properly close this ServiceTracker object when finalized. |
java.lang.Object |
getService()
Returns a service object for one of the services being tracked by this ServiceTracker object. |
java.lang.Object |
getService(org.osgi.framework.ServiceReference reference)
Returns the service object for the specified ServiceReference object if the referenced service is being tracked by this ServiceTracker object. |
org.osgi.framework.ServiceReference |
getServiceReference()
Returns a ServiceReference object for one of the services being tracked by this ServiceTracker object. |
org.osgi.framework.ServiceReference[] |
getServiceReferences()
Return an array of ServiceReference objects for all services being tracked by this ServiceTracker object. |
java.lang.Object[] |
getServices()
Return an array of service objects for all services being tracked by this ServiceTracker object. |
int |
getTrackingCount()
Returns the tracking count for this ServiceTracker object. |
void |
modifiedService(org.osgi.framework.ServiceReference reference,
java.lang.Object service)
Default implementation of the ServiceTrackerCustomizer.modifiedService method. |
void |
open()
Open this ServiceTracker object and begin tracking services. |
void |
remove(org.osgi.framework.ServiceReference reference)
Remove a service from this ServiceTracker object. |
void |
removedService(org.osgi.framework.ServiceReference reference,
java.lang.Object object)
Default implementation of the ServiceTrackerCustomizer.removedService method. |
int |
size()
Return the number of services being tracked by this ServiceTracker object. |
java.lang.Object |
waitForService(long timeout)
Wait for at least one service to be tracked by this ServiceTracker object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final org.osgi.framework.BundleContext context
protected final org.osgi.framework.Filter filter
Constructor Detail |
---|
public ServiceTracker(org.osgi.framework.BundleContext context, org.osgi.framework.ServiceReference reference, ServiceTrackerCustomizer customizer)
The service referenced by the specified ServiceReference object will be tracked by this ServiceTracker object.
context
- BundleContext object against which the tracking is done.reference
- ServiceReference object for the service to be tracked.customizer
- The customizer object to call when services are
added, modified, or removed in this ServiceTracker object.
If customizer is null, then this ServiceTracker object will be used
as the ServiceTrackerCustomizer object and the ServiceTracker
object will call the ServiceTrackerCustomizer methods on itself.public ServiceTracker(org.osgi.framework.BundleContext context, java.lang.String clazz, ServiceTrackerCustomizer customizer)
Services registered under the specified class name will be tracked by this ServiceTracker object.
context
- BundleContext object against which the tracking is done.clazz
- Class name of the services to be tracked.customizer
- The customizer object to call when services are
added, modified, or removed in this ServiceTracker object.
If customizer is null, then this ServiceTracker object will be used
as the ServiceTrackerCustomizer object and the ServiceTracker object
will call the ServiceTrackerCustomizer methods on itself.public ServiceTracker(org.osgi.framework.BundleContext context, org.osgi.framework.Filter filter, ServiceTrackerCustomizer customizer)
Services which match the specified Filter object will be tracked by this ServiceTracker object.
context
- BundleContext object against which the tracking is done.filter
- Filter object to select the services to be tracked.customizer
- The customizer object to call when services are
added, modified, or removed in this ServiceTracker object.
If customizer is null, then this ServiceTracker object will be used
as the ServiceTrackerCustomizer object and the ServiceTracker
object will call the ServiceTrackerCustomizer methods on itself.Method Detail |
---|
public void open()
Services which match the search criteria specified when this ServiceTracker object was created are now tracked by this ServiceTracker object.
java.lang.IllegalStateException
- if the BundleContext
object with which this ServiceTracker object was created is no longer valid.public void close()
This method should be called when this ServiceTracker object should end the tracking of services.
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public java.lang.Object addingService(org.osgi.framework.ServiceReference reference)
This method is only called when this ServiceTracker object has been constructed with a null ServiceTrackerCustomizer argument. The default implementation returns the result of calling getService, on the BundleContext object with which this ServiceTracker 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 ServiceTrackerCustomizer
reference
- Reference to service being added to this
ServiceTracker object.
ServiceTrackerCustomizer
public void addedService(org.osgi.framework.ServiceReference ref, java.lang.Object service)
addedService
in interface ServiceTrackerCustomizer
public void modifiedService(org.osgi.framework.ServiceReference reference, java.lang.Object service)
This method is only called when this ServiceTracker object has been constructed with a null ServiceTrackerCustomizer argument. The default implementation does nothing.
modifiedService
in interface ServiceTrackerCustomizer
reference
- Reference to modified service.service
- The service object for the modified service.ServiceTrackerCustomizer
public void removedService(org.osgi.framework.ServiceReference reference, java.lang.Object object)
This method is only called when this ServiceTracker object has been constructed with a null ServiceTrackerCustomizer argument. The default implementation calls ungetService, on the BundleContext object with which this ServiceTracker 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 ServiceTrackerCustomizer
reference
- Reference to removed service.object
- The service object for the removed service.ServiceTrackerCustomizer
public java.lang.Object waitForService(long timeout) throws java.lang.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
- time interval in milliseconds to wait. If zero,
the method will wait indefinately.
java.lang.IllegalArgumentException
- If the value of timeout is
negative.
java.lang.InterruptedException
public org.osgi.framework.ServiceReference[] getServiceReferences()
public java.lang.Object[] getServices()
public org.osgi.framework.ServiceReference getServiceReference()
If multiple services are being tracked, the service with the highest ranking (as specified in its service.ranking property) is returned.
If there is a tie in ranking, the service with the lowest service ID (as specified in its service.id property); that is, the service that was registered first is returned.
This is the same algorithm used by BundleContext.getServiceReference.
public java.lang.Object getService(org.osgi.framework.ServiceReference reference)
reference
- Reference to the desired service.
public java.lang.Object getService()
If any services are being tracked, this method returns the result of calling getService(getServiceReference()).
public void remove(org.osgi.framework.ServiceReference reference)
reference
- Reference to the service to be removed.public int size()
public int getTrackingCount()
The tracking count can be used to determine if this ServiceTracker object has added 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 or removed from this ServiceTracker object since the previous tracking count was collected.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |