com.springsource.util.osgi
Class ServiceRegistryProvider<T>

java.lang.Object
  extended by com.springsource.util.osgi.ServiceRegistryProvider<T>
Type Parameters:
T - parametric type
All Implemented Interfaces:
SetProvider<T>

public class ServiceRegistryProvider<T>
extends java.lang.Object
implements SetProvider<T>

This class provides a wrapper around the OSGi ServiceTracker class that lets you request all instance of a service at any time.

Concurrent Semantics
This class is thread safe.

Since:
1.5
Author:
Christopher Frost

Field Summary
private  ServiceTracker serviceTracker
           
private  java.lang.Class<T> typeClazz
           
 
Constructor Summary
ServiceRegistryProvider(org.osgi.framework.BundleContext bundleContext, java.lang.Class<T> clazz)
          Requires a bundle context to access the service registry trough.
 
Method Summary
 void close()
          Close the underlying ServiceTracker object.
 java.util.Set<T> getSet()
          Implementations of this must provide thread safe sets for iteration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serviceTracker

private final ServiceTracker serviceTracker

typeClazz

private final java.lang.Class<T> typeClazz
Constructor Detail

ServiceRegistryProvider

public ServiceRegistryProvider(org.osgi.framework.BundleContext bundleContext,
                               java.lang.Class<T> clazz)
Requires a bundle context to access the service registry trough. This should be the bundle context belonging to the code using this service, not the bundle that is publishing the services of interest.

Parameters:
bundleContext - of code using this service
clazz - Class of service
Method Detail

getSet

public java.util.Set<T> getSet()
Implementations of this must provide thread safe sets for iteration. e.g. This can be achieved by either returning a new set or one that implements thread safety with internal locking.

Specified by:
getSet in interface SetProvider<T>
Returns:
the Set of service objects

close

public void close()
Close the underlying ServiceTracker object.