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 Summary
Fields Modifier and Type Field Description protected IRemoteServiceContainerAdapter
containerAdapter
IRemoteServiceContainerAdapter containerAdapter against which thisRemoteServiceTracker
is tracking.protected ID[]
containerIDs
Container IDs that provide the context for tracking.protected IRemoteFilter
filter
Filter specifying search criteria for the services to track.
-
Constructor Summary
Constructors Constructor Description RemoteServiceTracker(IRemoteServiceContainerAdapter containerAdapter, ID[] containerIDs, String clazz, IRemoteServiceTrackerCustomizer customizer)
Create aRemoteServiceTracker
object on the specified class name.RemoteServiceTracker(IRemoteServiceContainerAdapter containerAdapter, ID[] containerIDs, IRemoteServiceReference reference, IRemoteServiceTrackerCustomizer customizer)
Create aRemoteServiceTracker
on the specifiedIRemoteServiceReference
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IRemoteService
addingService(IRemoteServiceReference reference)
Default implementation of theIRemoteServiceTrackerCustomizer.addingService
method.void
close()
Close thisRemoteServiceTracker
.IRemoteService
getRemoteService()
Returns a service object for one of the services being tracked by thisRemoteServiceTracker
object.IRemoteService
getRemoteService(IRemoteServiceReference reference)
Returns the service object for the specifiedServiceReference
object if the referenced service is being tracked by thisRemoteServiceTracker
object.IRemoteServiceReference
getRemoteServiceReference()
Returns aServiceReference
object for one of the services being tracked by thisRemoteServiceTracker
object.IRemoteServiceReference[]
getRemoteServiceReferences()
Return an array ofServiceReference
objects for all services being tracked by thisRemoteServiceTracker
object.IRemoteService[]
getRemoteServices()
Return an array of service objects for all services being tracked by thisRemoteServiceTracker
object.int
getTrackingCount()
Returns the tracking count for thisRemoteServiceTracker
object.void
modifiedService(IRemoteServiceReference reference, IRemoteService remoteService)
Default implementation of theServiceTrackerCustomizer.modifiedService
method.void
open()
Open thisRemoteServiceTracker
object and begin tracking services.void
remove(IRemoteServiceReference reference)
Remove a service from thisRemoteServiceTracker
object.void
removedService(IRemoteServiceReference reference, IRemoteService remoteService)
Default implementation of theServiceTrackerCustomizer.removedService
method.int
size()
Return the number of services being tracked by thisRemoteServiceTracker
object.IRemoteService
waitForRemoteService(long timeout)
Wait for at least one service to be tracked by thisRemoteServiceTracker
object.
-
-
-
Field Detail
-
containerAdapter
protected final IRemoteServiceContainerAdapter containerAdapter
IRemoteServiceContainerAdapter containerAdapter against which thisRemoteServiceTracker
is tracking.
-
containerIDs
protected final ID[] containerIDs
Container IDs that provide the context for tracking.
-
filter
protected final IRemoteFilter filter
Filter specifying search criteria for the services to track.
-
-
Constructor Detail
-
RemoteServiceTracker
public RemoteServiceTracker(IRemoteServiceContainerAdapter containerAdapter, ID[] containerIDs, IRemoteServiceReference reference, IRemoteServiceTrackerCustomizer customizer)
Create aRemoteServiceTracker
on the specifiedIRemoteServiceReference
.The remote service referenced by the specified
IRemoteServiceReference
object will be tracked by thisRemoteServiceTracker
object.- Parameters:
containerAdapter
-IRemoteServiceContainerAdapter
against which the tracking is done.containerIDs
- container IDsreference
-IRemoteServiceReference
for the remote service to be tracked.customizer
- The customizer object to call when services are added, modified, or removed in thisRemoteServiceTracker
object. If customizer isnull
, then thisRemoteServiceTracker
object will be used as theServiceTrackerCustomizer
object and theRemoteServiceTracker
object will call theServiceTrackerCustomizer
methods on itself.
-
RemoteServiceTracker
public RemoteServiceTracker(IRemoteServiceContainerAdapter containerAdapter, ID[] containerIDs, String clazz, IRemoteServiceTrackerCustomizer customizer)
Create aRemoteServiceTracker
object on the specified class name.Services registered under the specified class name will be tracked by this
RemoteServiceTracker
object.- Parameters:
containerAdapter
-BundleContext
object 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 thisRemoteServiceTracker
object. If customizer isnull
, then thisRemoteServiceTracker
object will be used as theServiceTrackerCustomizer
object and theRemoteServiceTracker
object will call theServiceTrackerCustomizer
methods on itself.
-
-
Method Detail
-
open
public void open()
Open thisRemoteServiceTracker
object and begin tracking services.Services which match the search criteria specified when this
RemoteServiceTracker
object was created are now tracked by thisRemoteServiceTracker
object.- Throws:
IllegalStateException
- if theBundleContext
object with which thisRemoteServiceTracker
object was created is no longer valid.- Since:
- 1.3
-
close
public void close()
Close thisRemoteServiceTracker
.This method should be called when this
RemoteServiceTracker
object should end the tracking of services.
-
addingService
public IRemoteService addingService(IRemoteServiceReference reference)
Default implementation of theIRemoteServiceTrackerCustomizer.addingService
method.This method is only called when this
RemoteServiceTracker
object has been constructed with anull IRemoteServiceTrackerCustomizer
argument. The default implementation returns the result of callinggetService
, on theBundleContext
object with which thisRemoteServiceTracker
object was created, passing the specifiedServiceReference
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.
- Specified by:
addingService
in interfaceIRemoteServiceTrackerCustomizer
- Parameters:
reference
- Reference to service being added to thisRemoteServiceTracker
object.- Returns:
- The IRemoteService object to be tracked for the service added to this
RemoteServiceTracker
object. - See Also:
IRemoteServiceTrackerCustomizer
-
modifiedService
public void modifiedService(IRemoteServiceReference reference, IRemoteService remoteService)
Default implementation of theServiceTrackerCustomizer.modifiedService
method.This method is only called when this
RemoteServiceTracker
object has been constructed with anull ServiceTrackerCustomizer
argument. The default implementation does nothing.- Specified by:
modifiedService
in interfaceIRemoteServiceTrackerCustomizer
- Parameters:
reference
- Reference to modified service.remoteService
- The service object for the modified service.- See Also:
IRemoteServiceTrackerCustomizer
-
removedService
public void removedService(IRemoteServiceReference reference, IRemoteService remoteService)
Default implementation of theServiceTrackerCustomizer.removedService
method.This method is only called when this
RemoteServiceTracker
object has been constructed with anull ServiceTrackerCustomizer
argument. The default implementation callsungetService
, on theBundleContext
object with which thisRemoteServiceTracker
object was created, passing the specifiedServiceReference
object.This method can be overridden in a subclass. If the default implementation of
addingService
method was used, this method must unget the service.- Specified by:
removedService
in interfaceIRemoteServiceTrackerCustomizer
- Parameters:
reference
- Reference to removed service.remoteService
- The service object for the removed service.- See Also:
IRemoteServiceTrackerCustomizer
-
waitForRemoteService
public IRemoteService waitForRemoteService(long timeout) throws InterruptedException
Wait for at least one service to be tracked by thisRemoteServiceTracker
object.It is strongly recommended that
waitForService
is not used during the calling of theBundleActivator
methods.BundleActivator
methods 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
public IRemoteServiceReference[] getRemoteServiceReferences()
Return an array ofServiceReference
objects for all services being tracked by thisRemoteServiceTracker
object.- Returns:
- Array of
ServiceReference
objects ornull
if no service are being tracked.
-
getRemoteServiceReference
public IRemoteServiceReference getRemoteServiceReference()
Returns aServiceReference
object for one of the services being tracked by thisRemoteServiceTracker
object.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
.- Returns:
ServiceReference
object ornull
if no service is being tracked.- Since:
- 1.1
-
getRemoteService
public IRemoteService getRemoteService(IRemoteServiceReference reference)
Returns the service object for the specifiedServiceReference
object if the referenced service is being tracked by thisRemoteServiceTracker
object.- Parameters:
reference
- Reference to the desired service.- Returns:
- Service object or
null
if the service referenced by the specifiedServiceReference
object is not being tracked.
-
getRemoteServices
public IRemoteService[] getRemoteServices()
Return an array of service objects for all services being tracked by thisRemoteServiceTracker
object.- Returns:
- Array of service objects or
null
if no service are being tracked.
-
getRemoteService
public IRemoteService getRemoteService()
Returns a service object for one of the services being tracked by thisRemoteServiceTracker
object.If any services are being tracked, this method returns the result of calling
getService(getServiceReference())
.- Returns:
- Service object or
null
if no service is being tracked.
-
remove
public void remove(IRemoteServiceReference reference)
Remove a service from thisRemoteServiceTracker
object. The specified service will be removed from thisRemoteServiceTracker
object. If the specified service was being tracked then theServiceTrackerCustomizer.removedService
method 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 thisRemoteServiceTracker
object.- Returns:
- Number of services being tracked.
-
getTrackingCount
public int getTrackingCount()
Returns the tracking count for thisRemoteServiceTracker
object. The tracking count is initialized to 0 when thisRemoteServiceTracker
object is opened. Every time a service is added, modified or removed from thisRemoteServiceTracker
object the tracking count is incremented.The tracking count can be used to determine if this
RemoteServiceTracker
object 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 thisRemoteServiceTracker
object since the previous tracking count was collected.- Returns:
- The tracking count for this
RemoteServiceTracker
object or -1 if thisRemoteServiceTracker
object is not open. - Since:
- 1.2
-
-