Class RemoteServiceTracker
- All Implemented Interfaces:
IRemoteServiceTrackerCustomizer
IRemoteService.- Since:
- 3.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final IRemoteServiceContainerAdapterIRemoteServiceContainerAdapter containerAdapter against which thisRemoteServiceTrackeris tracking.protected final ID[]Container IDs that provide the context for tracking.protected final IRemoteFilterFilter specifying search criteria for the services to track. -
Constructor Summary
ConstructorsConstructorDescriptionRemoteServiceTracker(IRemoteServiceContainerAdapter containerAdapter, ID[] containerIDs, String clazz, IRemoteServiceTrackerCustomizer customizer) Create aRemoteServiceTrackerobject on the specified class name.RemoteServiceTracker(IRemoteServiceContainerAdapter containerAdapter, ID[] containerIDs, IRemoteServiceReference reference, IRemoteServiceTrackerCustomizer customizer) Create aRemoteServiceTrackeron the specifiedIRemoteServiceReference. -
Method Summary
Modifier and TypeMethodDescriptionaddingService(IRemoteServiceReference reference) Default implementation of theIRemoteServiceTrackerCustomizer.addingServicemethod.voidclose()Close thisRemoteServiceTracker.Returns a service object for one of the services being tracked by thisRemoteServiceTrackerobject.getRemoteService(IRemoteServiceReference reference) Returns the service object for the specifiedServiceReferenceobject if the referenced service is being tracked by thisRemoteServiceTrackerobject.Returns aServiceReferenceobject for one of the services being tracked by thisRemoteServiceTrackerobject.Return an array ofServiceReferenceobjects for all services being tracked by thisRemoteServiceTrackerobject.Return an array of service objects for all services being tracked by thisRemoteServiceTrackerobject.intReturns the tracking count for thisRemoteServiceTrackerobject.voidmodifiedService(IRemoteServiceReference reference, IRemoteService remoteService) Default implementation of theServiceTrackerCustomizer.modifiedServicemethod.voidopen()Open thisRemoteServiceTrackerobject and begin tracking services.voidremove(IRemoteServiceReference reference) Remove a service from thisRemoteServiceTrackerobject.voidremovedService(IRemoteServiceReference reference, IRemoteService remoteService) Default implementation of theServiceTrackerCustomizer.removedServicemethod.intsize()Return the number of services being tracked by thisRemoteServiceTrackerobject.waitForRemoteService(long timeout) Wait for at least one service to be tracked by thisRemoteServiceTrackerobject.
-
Field Details
-
containerAdapter
IRemoteServiceContainerAdapter containerAdapter against which thisRemoteServiceTrackeris tracking. -
containerIDs
Container IDs that provide the context for tracking. -
filter
Filter specifying search criteria for the services to track.
-
-
Constructor Details
-
RemoteServiceTracker
public RemoteServiceTracker(IRemoteServiceContainerAdapter containerAdapter, ID[] containerIDs, IRemoteServiceReference reference, IRemoteServiceTrackerCustomizer customizer) Create aRemoteServiceTrackeron the specifiedIRemoteServiceReference.The remote service referenced by the specified
IRemoteServiceReferenceobject will be tracked by thisRemoteServiceTrackerobject.- Parameters:
containerAdapter-IRemoteServiceContainerAdapteragainst which the tracking is done.containerIDs- container IDsreference-IRemoteServiceReferencefor the remote service to be tracked.customizer- The customizer object to call when services are added, modified, or removed in thisRemoteServiceTrackerobject. If customizer isnull, then thisRemoteServiceTrackerobject will be used as theServiceTrackerCustomizerobject and theRemoteServiceTrackerobject will call theServiceTrackerCustomizermethods on itself.
-
RemoteServiceTracker
public RemoteServiceTracker(IRemoteServiceContainerAdapter containerAdapter, ID[] containerIDs, String clazz, IRemoteServiceTrackerCustomizer customizer) Create aRemoteServiceTrackerobject on the specified class name.Services registered under the specified class name will be tracked by this
RemoteServiceTrackerobject.- Parameters:
containerAdapter-BundleContextobject against which the tracking is done.containerIDs- container idsclazz- Class name of the services to be tracked.customizer- The customizer object to call when services are added, modified, or removed in thisRemoteServiceTrackerobject. If customizer isnull, then thisRemoteServiceTrackerobject will be used as theServiceTrackerCustomizerobject and theRemoteServiceTrackerobject will call theServiceTrackerCustomizermethods on itself.
-
-
Method Details
-
open
public void open()Open thisRemoteServiceTrackerobject and begin tracking services.Services which match the search criteria specified when this
RemoteServiceTrackerobject was created are now tracked by thisRemoteServiceTrackerobject.- Throws:
IllegalStateException- if theBundleContextobject with which thisRemoteServiceTrackerobject was created is no longer valid.- Since:
- 1.3
-
close
public void close()Close thisRemoteServiceTracker.This method should be called when this
RemoteServiceTrackerobject should end the tracking of services. -
addingService
Default implementation of theIRemoteServiceTrackerCustomizer.addingServicemethod.This method is only called when this
RemoteServiceTrackerobject has been constructed with anull IRemoteServiceTrackerCustomizerargument. The default implementation returns the result of callinggetService, on theBundleContextobject with which thisRemoteServiceTrackerobject was created, passing the specifiedServiceReferenceobject.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.
- Specified by:
addingServicein interfaceIRemoteServiceTrackerCustomizer- Parameters:
reference- Reference to service being added to thisRemoteServiceTrackerobject.- Returns:
- The IRemoteService object to be tracked for the service added to this
RemoteServiceTrackerobject. - See Also:
-
modifiedService
Default implementation of theServiceTrackerCustomizer.modifiedServicemethod.This method is only called when this
RemoteServiceTrackerobject has been constructed with anull ServiceTrackerCustomizerargument. The default implementation does nothing.- Specified by:
modifiedServicein interfaceIRemoteServiceTrackerCustomizer- Parameters:
reference- Reference to modified service.remoteService- The service object for the modified service.- See Also:
-
removedService
Default implementation of theServiceTrackerCustomizer.removedServicemethod.This method is only called when this
RemoteServiceTrackerobject has been constructed with anull ServiceTrackerCustomizerargument. The default implementation callsungetService, on theBundleContextobject with which thisRemoteServiceTrackerobject was created, passing the specifiedServiceReferenceobject.This method can be overridden in a subclass. If the default implementation of
addingServicemethod was used, this method must unget the service.- Specified by:
removedServicein interfaceIRemoteServiceTrackerCustomizer- Parameters:
reference- Reference to removed service.remoteService- The service object for the removed service.- See Also:
-
waitForRemoteService
Wait for at least one service to be tracked by thisRemoteServiceTrackerobject.It is strongly recommended that
waitForServiceis not used during the calling of theBundleActivatormethods.BundleActivatormethods are expected to complete in a short period of time.- Parameters:
timeout- time interval in milliseconds to wait. If zero, the method will wait indefinitely.- Returns:
- Returns the result of
getService(). - Throws:
InterruptedException- If another thread has interrupted the current thread.IllegalArgumentException- If the value of timeout is negative.
-
getRemoteServiceReferences
Return an array ofServiceReferenceobjects for all services being tracked by thisRemoteServiceTrackerobject.- Returns:
- Array of
ServiceReferenceobjects ornullif no service are being tracked.
-
getRemoteServiceReference
Returns aServiceReferenceobject for one of the services being tracked by thisRemoteServiceTrackerobject.If multiple services are being tracked, the service with the highest ranking (as specified in its
service.rankingproperty) is returned.If there is a tie in ranking, the service with the lowest service ID (as specified in its
service.idproperty); that is, the service that was registered first is returned.This is the same algorithm used by
BundleContext.getServiceReference.- Returns:
ServiceReferenceobject ornullif no service is being tracked.- Since:
- 1.1
-
getRemoteService
Returns the service object for the specifiedServiceReferenceobject if the referenced service is being tracked by thisRemoteServiceTrackerobject.- Parameters:
reference- Reference to the desired service.- Returns:
- Service object or
nullif the service referenced by the specifiedServiceReferenceobject is not being tracked.
-
getRemoteServices
Return an array of service objects for all services being tracked by thisRemoteServiceTrackerobject.- Returns:
- Array of service objects or
nullif no service are being tracked.
-
getRemoteService
Returns a service object for one of the services being tracked by thisRemoteServiceTrackerobject.If any services are being tracked, this method returns the result of calling
getService(getServiceReference()).- Returns:
- Service object or
nullif no service is being tracked.
-
remove
Remove a service from thisRemoteServiceTrackerobject. The specified service will be removed from thisRemoteServiceTrackerobject. If the specified service was being tracked then theServiceTrackerCustomizer.removedServicemethod will be called for that service.- Parameters:
reference- Reference to the service to be removed.
-
size
public int size()Return the number of services being tracked by thisRemoteServiceTrackerobject.- Returns:
- Number of services being tracked.
-
getTrackingCount
public int getTrackingCount()Returns the tracking count for thisRemoteServiceTrackerobject. The tracking count is initialized to 0 when thisRemoteServiceTrackerobject is opened. Every time a service is added, modified or removed from thisRemoteServiceTrackerobject the tracking count is incremented.The tracking count can be used to determine if this
RemoteServiceTrackerobject 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 thisRemoteServiceTrackerobject since the previous tracking count was collected.- Returns:
- The tracking count for this
RemoteServiceTrackerobject or -1 if thisRemoteServiceTrackerobject is not open. - Since:
- 1.2
-