nl.lxtreme.ols.util.osgi
Class WhiteboardHelper<T>

java.lang.Object
  extended by org.osgi.util.tracker.ServiceTracker
      extended by nl.lxtreme.ols.util.osgi.WhiteboardHelper<T>
All Implemented Interfaces:
org.osgi.util.tracker.ServiceTrackerCustomizer

public class WhiteboardHelper<T>
extends org.osgi.util.tracker.ServiceTracker

Provides a helper class for easy implementation of the whiteboard pattern as used in OSGi.


Nested Class Summary
static interface WhiteboardHelper.Visitor<T>
          To be implemented by the class that wants to obtain a reference to a certain service.
 
Field Summary
 
Fields inherited from class org.osgi.util.tracker.ServiceTracker
context, filter
 
Constructor Summary
WhiteboardHelper(org.osgi.framework.BundleContext aContext, Class<T> aServiceClass)
          Creates a new WhiteboardHelper instance.
WhiteboardHelper(org.osgi.framework.BundleContext aContext, org.osgi.framework.Filter aFilter)
          Creates a new WhiteboardHelper instance.
 
Method Summary
 void accept(WhiteboardHelper.Visitor<? super T> aVisitor)
          Called to invoke the given WhiteboardHelper.Visitor for each found service.
 void acceptFirst(WhiteboardHelper.Visitor<? super T> aVisitor)
          Called to invoke the given WhiteboardHelper.Visitor for the first found service.
 T getService()
          
 
Methods inherited from class org.osgi.util.tracker.ServiceTracker
addingService, close, getService, getServiceReference, getServiceReferences, getServices, getTrackingCount, modifiedService, open, open, remove, removedService, size, waitForService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WhiteboardHelper

public WhiteboardHelper(org.osgi.framework.BundleContext aContext,
                        Class<T> aServiceClass)
Creates a new WhiteboardHelper instance.

Parameters:
aContext - the bundle context to use;
aServiceClass - the class of the service we should track, cannot be null.

WhiteboardHelper

public WhiteboardHelper(org.osgi.framework.BundleContext aContext,
                        org.osgi.framework.Filter aFilter)
Creates a new WhiteboardHelper instance.

Parameters:
aContext - the bundle context to use;
aFilter - the filter to use while filtering on the services, cannot be null;
Method Detail

accept

public final void accept(WhiteboardHelper.Visitor<? super T> aVisitor)
Called to invoke the given WhiteboardHelper.Visitor for each found service.

Parameters:
aVisitor - the visitor to call for each found service, cannot be null.
Throws:
IllegalArgumentException - in case the given visitor was null.

acceptFirst

public final void acceptFirst(WhiteboardHelper.Visitor<? super T> aVisitor)
Called to invoke the given WhiteboardHelper.Visitor for the first found service.

Parameters:
aVisitor - the visitor to call for the first found service, cannot be null.
Throws:
IllegalArgumentException - in case the given visitor was null.

getService

public T getService()

Overrides:
getService in class org.osgi.util.tracker.ServiceTracker


Copyright © 2012 L'Xtreme IT consultancy. All Rights Reserved.