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

java.lang.Object
  extended by org.robokind.api.common.property.PropertyChangeNotifier
      extended by org.robokind.api.common.osgi.SingleServiceListener<T>
Type Parameters:
T - type of service to listen for
All Implemented Interfaces:
EventListener, org.osgi.framework.ServiceListener, PropertyChangeSource

public class SingleServiceListener<T>
extends PropertyChangeNotifier
implements org.osgi.framework.ServiceListener

Listens to the OSGi Service Registry for a single service, and provides service registration hooks.

Author:
Matthew Stevenson

Field Summary
static String PROP_SERVICE_MODIFIED
          Property change event name for the service being modified
static String PROP_SERVICE_REMOVED
          Property change event name for the service becoming unavailabe
static String PROP_SERVICE_TRACKED
          Property change event name for the service becoming available
 
Constructor Summary
SingleServiceListener(Class<T> clazz, org.osgi.framework.BundleContext context, String serviceFilter)
          Creates a new SingleServiceListener.
 
Method Summary
 void dispose()
          Releases the service, stops listening to the Serivce Registry, and removes all PropertyChangeListeners.
 String getFilterString()
          Returns the optional OSGi filter string, null if not set.
 T getService()
          Returns the service being tracked, null if no service is found.
 Class<T> getServiceClass()
          Returns the class of the service
 org.osgi.framework.ServiceReference getServiceReference()
          Returns a reference to the service being tracked.
 void releaseService()
          Releases the service, decrementing the usage count for the ServiceReference being tracked.
 void serviceChanged(org.osgi.framework.ServiceEvent se)
           
 boolean start()
          Starts listening for the desired services.
 void stop()
          Releases the service and stops listening.
 
Methods inherited from class org.robokind.api.common.property.PropertyChangeNotifier
addPropertyChangeListener, addPropertyChangeListener, clearAllListeners, clearListeners, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, hasListeners, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_SERVICE_TRACKED

public static final String PROP_SERVICE_TRACKED
Property change event name for the service becoming available

See Also:
Constant Field Values

PROP_SERVICE_MODIFIED

public static final String PROP_SERVICE_MODIFIED
Property change event name for the service being modified

See Also:
Constant Field Values

PROP_SERVICE_REMOVED

public static final String PROP_SERVICE_REMOVED
Property change event name for the service becoming unavailabe

See Also:
Constant Field Values
Constructor Detail

SingleServiceListener

public SingleServiceListener(Class<T> clazz,
                             org.osgi.framework.BundleContext context,
                             String serviceFilter)
Creates a new SingleServiceListener.

Parameters:
clazz - class of the service
context - BundleContext for accessing the Service Registry
serviceFilter - optional OSGi filter String to match
Throws:
NullPointerException - if clazz or context are null
Method Detail

getServiceReference

public org.osgi.framework.ServiceReference getServiceReference()
Returns a reference to the service being tracked. Returns null if the service is not available.

Returns:
reference to the service being tracked, null if the service is not available

getServiceClass

public Class<T> getServiceClass()
Returns the class of the service

Returns:
class of the service

getFilterString

public String getFilterString()
Returns the optional OSGi filter string, null if not set.

Returns:
optional OSGi filter string, null if not set

getService

public T getService()
Returns the service being tracked, null if no service is found.

Returns:
service being tracked, null if no service is found

releaseService

public void releaseService()
Releases the service, decrementing the usage count for the ServiceReference being tracked. Notifies listeners that the service is no longer available.


start

public boolean start()
Starts listening for the desired services.

Returns:
true is successful, false if it failed

stop

public void stop()
Releases the service and stops listening.


dispose

public void dispose()
Releases the service, stops listening to the Serivce Registry, and removes all PropertyChangeListeners.


serviceChanged

public void serviceChanged(org.osgi.framework.ServiceEvent se)
Specified by:
serviceChanged in interface org.osgi.framework.ServiceListener


Copyright © 2011-2013. All Rights Reserved.