org.ops4j.pax.swissbox.tracker
Class ServiceCollection<T>

java.lang.Object
  extended by org.ops4j.pax.swissbox.lifecycle.AbstractLifecycle
      extended by org.ops4j.pax.swissbox.tracker.ServiceCollection<T>
All Implemented Interfaces:
java.lang.Iterable<T>, Lifecycle

public class ServiceCollection<T>
extends AbstractLifecycle
implements java.lang.Iterable<T>

A collection of tracked services.

Since:
October 14, 2007
Author:
Alin Dreghiciu

Constructor Summary
ServiceCollection(org.osgi.framework.BundleContext context, java.lang.Class<T> serviceClass)
          Creates a new service tracker collection, using the specified service context and the default service collection listener.
ServiceCollection(org.osgi.framework.BundleContext context, java.lang.Class<T> serviceClass, ServiceCollectionListener<T> collectionListener)
          Creates a new service tracker collection, using the specified service context and listener.
 
Method Summary
 java.util.Iterator<T> iterator()
          Returns an iterator over the tracked services at the call point in time.
protected  void onStart()
          Creates a service tracker and opens it.
protected  void onStop()
          Closes the service tracker and releases resources.
 
Methods inherited from class org.ops4j.pax.swissbox.lifecycle.AbstractLifecycle
isStarted, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceCollection

public ServiceCollection(org.osgi.framework.BundleContext context,
                         java.lang.Class<T> serviceClass)
Creates a new service tracker collection, using the specified service context and the default service collection listener.

Parameters:
context - bundle context
serviceClass - class of the services to be tracked

ServiceCollection

public ServiceCollection(org.osgi.framework.BundleContext context,
                         java.lang.Class<T> serviceClass,
                         ServiceCollectionListener<T> collectionListener)
Creates a new service tracker collection, using the specified service context and listener. Listener can be null, case when the default service collection listener is used.

Parameters:
context - bundle context
serviceClass - class of the services to be tracked
collectionListener - service events listener
Method Detail

iterator

public java.util.Iterator<T> iterator()
Returns an iterator over the tracked services at the call point in time. Note that a susequent call can produce a different list of services as the services are dynamic. If there are no services available returns an empty iterator.

Specified by:
iterator in interface java.lang.Iterable<T>
See Also:
Iterable.iterator()

onStart

protected void onStart()
Creates a service tracker and opens it.

Specified by:
onStart in class AbstractLifecycle
See Also:
AbstractLifecycle.onStart()

onStop

protected void onStop()
Closes the service tracker and releases resources.

Specified by:
onStop in class AbstractLifecycle
See Also:
AbstractLifecycle.onStop()


Copyright © 2006-2012 OPS4J - Open Participation Software for Java. All Rights Reserved.