Class RemoteServiceTracker
- java.lang.Object
- 
- org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker
 
- 
- All Implemented Interfaces:
- IRemoteServiceTrackerCustomizer
 
 public class RemoteServiceTracker extends Object implements IRemoteServiceTrackerCustomizer Remote service tracker. Implementation of ServiceTracker for the ECF remoteservices API. The getRemoteService() method returns instances ofIRemoteService.- Since:
- 3.0
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected IRemoteServiceContainerAdaptercontainerAdapterIRemoteServiceContainerAdapter containerAdapter against which thisRemoteServiceTrackeris tracking.protected ID[]containerIDsContainer IDs that provide the context for tracking.protected IRemoteFilterfilterFilter specifying search criteria for the services to track.
 - 
Constructor SummaryConstructors Constructor Description RemoteServiceTracker(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 SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description IRemoteServiceaddingService(IRemoteServiceReference reference)Default implementation of theIRemoteServiceTrackerCustomizer.addingServicemethod.voidclose()Close thisRemoteServiceTracker.IRemoteServicegetRemoteService()Returns a service object for one of the services being tracked by thisRemoteServiceTrackerobject.IRemoteServicegetRemoteService(IRemoteServiceReference reference)Returns the service object for the specifiedServiceReferenceobject if the referenced service is being tracked by thisRemoteServiceTrackerobject.IRemoteServiceReferencegetRemoteServiceReference()Returns aServiceReferenceobject for one of the services being tracked by thisRemoteServiceTrackerobject.IRemoteServiceReference[]getRemoteServiceReferences()Return an array ofServiceReferenceobjects for all services being tracked by thisRemoteServiceTrackerobject.IRemoteService[]getRemoteServices()Return an array of service objects for all services being tracked by thisRemoteServiceTrackerobject.intgetTrackingCount()Returns 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.IRemoteServicewaitForRemoteService(long timeout)Wait for at least one service to be tracked by thisRemoteServiceTrackerobject.
 
- 
- 
- 
Field Detail- 
containerAdapterprotected final IRemoteServiceContainerAdapter containerAdapter IRemoteServiceContainerAdapter containerAdapter against which thisRemoteServiceTrackeris tracking.
 - 
containerIDsprotected final ID[] containerIDs Container IDs that provide the context for tracking.
 - 
filterprotected final IRemoteFilter filter Filter specifying search criteria for the services to track.
 
- 
 - 
Constructor Detail- 
RemoteServiceTrackerpublic 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 IDs
- reference-- IRemoteServiceReferencefor the remote service to be tracked.
- customizer- The customizer object to call when services are added, modified, or removed in this- RemoteServiceTrackerobject. If customizer is- null, then this- RemoteServiceTrackerobject will be used as the- ServiceTrackerCustomizerobject and the- RemoteServiceTrackerobject will call the- ServiceTrackerCustomizermethods on itself.
 
 - 
RemoteServiceTrackerpublic 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 ids
- clazz- Class name of the services to be tracked.
- customizer- The customizer object to call when services are added, modified, or removed in this- RemoteServiceTrackerobject. If customizer is- null, then this- RemoteServiceTrackerobject will be used as the- ServiceTrackerCustomizerobject and the- RemoteServiceTrackerobject will call the- ServiceTrackerCustomizermethods on itself.
 
 
- 
 - 
Method Detail- 
openpublic 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 the- BundleContextobject with which this- RemoteServiceTrackerobject was created is no longer valid.
- Since:
- 1.3
 
 - 
closepublic void close() Close thisRemoteServiceTracker.This method should be called when this RemoteServiceTrackerobject should end the tracking of services.
 - 
addingServicepublic IRemoteService addingService(IRemoteServiceReference reference) 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 interface- IRemoteServiceTrackerCustomizer
- Parameters:
- reference- Reference to service being added to this- RemoteServiceTrackerobject.
- Returns:
- The IRemoteService object to be tracked for the service added to this
         RemoteServiceTrackerobject.
- See Also:
- IRemoteServiceTrackerCustomizer
 
 - 
modifiedServicepublic void modifiedService(IRemoteServiceReference reference, IRemoteService remoteService) 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 interface- IRemoteServiceTrackerCustomizer
- Parameters:
- reference- Reference to modified service.
- remoteService- The service object for the modified service.
- See Also:
- IRemoteServiceTrackerCustomizer
 
 - 
removedServicepublic void removedService(IRemoteServiceReference reference, IRemoteService remoteService) 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 interface- IRemoteServiceTrackerCustomizer
- Parameters:
- reference- Reference to removed service.
- remoteService- The service object for the removed service.
- See Also:
- IRemoteServiceTrackerCustomizer
 
 - 
waitForRemoteServicepublic IRemoteService waitForRemoteService(long timeout) throws InterruptedException 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.
 
 - 
getRemoteServiceReferencespublic IRemoteServiceReference[] getRemoteServiceReferences() Return an array ofServiceReferenceobjects for all services being tracked by thisRemoteServiceTrackerobject.- Returns:
- Array of ServiceReferenceobjects ornullif no service are being tracked.
 
 - 
getRemoteServiceReferencepublic IRemoteServiceReference 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 or- nullif no service is being tracked.
- Since:
- 1.1
 
 - 
getRemoteServicepublic IRemoteService getRemoteService(IRemoteServiceReference reference) 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.
 
 - 
getRemoteServicespublic IRemoteService[] 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.
 
 - 
getRemoteServicepublic IRemoteService 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.
 
 - 
removepublic void remove(IRemoteServiceReference reference) 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.
 
 - 
sizepublic int size() Return the number of services being tracked by thisRemoteServiceTrackerobject.- Returns:
- Number of services being tracked.
 
 - 
getTrackingCountpublic 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
 
 
- 
 
-