org.robokind.api.common.osgi
Class ClassTracker<T>

java.lang.Object
  extended by org.robokind.api.common.osgi.ClassTracker<T>
Type Parameters:
T - type of services to track

public class ClassTracker<T>
extends Object

A generic wrapper for the ServiceTracker Tracks all services registered to the OSGi framework with the given type and matching the given filter

Author:
Matthew Stevenson

Constructor Summary
ClassTracker(org.osgi.framework.BundleContext context, String className, String filter)
          Creates a new tracker for the given class, and begins tracking.
ClassTracker(org.osgi.framework.BundleContext context, String className, String filter, org.osgi.util.tracker.ServiceTrackerCustomizer customizer)
          Creates a new tracker for the given class, and begins tracking.
ClassTracker(String className)
          Creates a new tracker for the given class.
 
Method Summary
static
<C> ClassTracker<C>
build(Class<C> clazz, Properties props)
           
static
<C> ClassTracker<C>
build(Class<C> clazz, String filter)
           
 void close()
           
 String getFilter()
          Gets the filter for the service properties.
 List<T> getServices()
          Returns a list of register services being tracked.
 T getTopService()
          Returns the top service being tracked.
 boolean init()
          Call to initialize the ClassTracker after setting the BundleContext, filter (optional), and customizer (optional).
 void setContext(org.osgi.framework.BundleContext context)
          Sets the BundleContext to monitor.
 void setCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer cust)
          Sets the customizer
 void setFilter(String filter)
          Sets the filter for the service properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassTracker

public ClassTracker(String className)
Creates a new tracker for the given class. init() must be called before the ClassTracker begins tracking.

Parameters:
className - name of the class to track

ClassTracker

public ClassTracker(org.osgi.framework.BundleContext context,
                    String className,
                    String filter)
             throws IllegalArgumentException
Creates a new tracker for the given class, and begins tracking. There is no need to call init()

Parameters:
className - name of the class to track
Throws:
IllegalArgumentException

ClassTracker

public ClassTracker(org.osgi.framework.BundleContext context,
                    String className,
                    String filter,
                    org.osgi.util.tracker.ServiceTrackerCustomizer customizer)
             throws IllegalArgumentException
Creates a new tracker for the given class, and begins tracking. There is no need to call init()

Parameters:
className - name of the class to track
Throws:
IllegalArgumentException
Method Detail

build

public static <C> ClassTracker<C> build(Class<C> clazz,
                                        String filter)

build

public static <C> ClassTracker<C> build(Class<C> clazz,
                                        Properties props)

setContext

public void setContext(org.osgi.framework.BundleContext context)
Sets the BundleContext to monitor.

Parameters:
context - BundleContext to monitor

setFilter

public void setFilter(String filter)
Sets the filter for the service properties.

Parameters:
filter - filter service properties must match to be tracked

getFilter

public String getFilter()
Gets the filter for the service properties.

Returns:
filter for the service properties

setCustomizer

public void setCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer cust)
Sets the customizer

Parameters:
cust - the new customizer

init

public boolean init()
Call to initialize the ClassTracker after setting the BundleContext, filter (optional), and customizer (optional).

Returns:
true if successful

close

public void close()

getServices

public List<T> getServices()
Returns a list of register services being tracked.

Returns:
list of register services being tracked or null if uninitialized

getTopService

public T getTopService()
Returns the top service being tracked.

Returns:
the top service being tracked, or null if uninitialized or no services are found


Copyright © 2011-2013. All Rights Reserved.