org.robokind.api.common.osgi.lifecycle
Class OSGiComponent<T>

java.lang.Object
  extended by org.robokind.api.common.property.PropertyChangeNotifier
      extended by org.robokind.api.common.osgi.lifecycle.OSGiComponent<T>
Type Parameters:
T - type of the service to be launched
All Implemented Interfaces:
ManagedService<T>, PropertyChangeSource

public class OSGiComponent<T>
extends PropertyChangeNotifier
implements ManagedService<T>

An OSGi Service managed with a ServiceLifecycleProvider. Creates a ServiceDependenciesTracker to drive the service lifecycle from the OSGi Service Registry. The the service lifecycle changes, the OSGiComponent registers/unregisters the managed service in the OSGi ServiceRegistry. An OSGiComponent Registers itself to the OSGi ServiceRegistry when started.

Author:
Matthew Stevenson

Field Summary
 
Fields inherited from interface org.robokind.api.common.lifecycle.ManagedService
PROP_DEPENDENCY_CHANGED, PROP_SERVICE_CHANGED, PROP_SERVICE_TYPE
 
Constructor Summary
OSGiComponent(org.osgi.framework.BundleContext context, ServiceLifecycleProvider<T> lifecycle)
          Creates a new OSGiComponent from the given lifecycle provider.
OSGiComponent(org.osgi.framework.BundleContext context, ServiceLifecycleProvider<T> lifecycle, Properties registrationProps)
          Creates a new OSGiComponent from the given lifecycle provider.
OSGiComponent(org.osgi.framework.BundleContext context, ServiceLifecycleProvider<T> lifecycle, Properties registrationProps, boolean selfRegister)
          Creates a new OSGiComponent from the given lifecycle provider.
OSGiComponent(org.osgi.framework.BundleContext context, ServiceLifecycleProvider<T> lifecycle, Properties registrationProps, Properties uniqueProps, boolean selfRegister)
          Creates a new OSGiComponent from the given lifecycle provider.
 
Method Summary
 void dispose()
          Stops and unregisters the service, cleans up the service lifecycle and management, and stops and unregisters the ManagedService.
 int getAvailableDependencyCount()
          Returns the number of satisfied dependencies.
 List<DependencyDescriptor> getDependencies()
          Returns a list describing the service dependencies of this ManagedService.
 int getDependencyCount()
          Returns the number of dependencies for this ManagedService.
 boolean getDependencyStatus(String dependencyId)
          Returns true if the specified dependency is available.
 org.slf4j.Logger getLogger()
           
 boolean getRegistrationEnabled()
          Returns true if automatic service registration is enabled.
 Properties getRegistrationProperties()
          Returns the registration properties to use when registering the service.
 boolean getSelfRegistrationEnabled()
          Returns true if this OSGiComponent should register itself.
 String[] getServiceClassNames()
          Returns the class names of service being managed.
 boolean isAvailable()
          Returns true if the service is available and ready to use.
 boolean isRegistered()
          Returns true if the service has been added to the Service Registry.
 void register()
          Registers the service if it is available.
 void registerSelf()
          Add this OSGiComponent to the OSGi Service Registry.
 void setRegistrationEnabled(boolean enabled)
          If set true, the Service being managed will be automatically added to the Service Registry when available.
 void setSelfRegistrationEnabled(boolean enabled)
          If set true, this OSGiComponent will register itself when start() is called, or immediately if start has already been called.
 void start()
          Starts the OSGiComponent.
 void stop()
          Stops tracking dependency changes.
 void unregister()
          Unregisters the service if it is registered.
 void unregisterSelf()
          Removes this OSGiComponent from the OSGi Service Registry
 
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
 
Methods inherited from interface org.robokind.api.common.property.PropertyChangeSource
addPropertyChangeListener, addPropertyChangeListener, removePropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

OSGiComponent

public OSGiComponent(org.osgi.framework.BundleContext context,
                     ServiceLifecycleProvider<T> lifecycle)
Creates a new OSGiComponent from the given lifecycle provider.

Parameters:
context - BundleContext for accessing the OSGi Service Registry
lifecycle - lifecycle provider for the managed service

OSGiComponent

public OSGiComponent(org.osgi.framework.BundleContext context,
                     ServiceLifecycleProvider<T> lifecycle,
                     Properties registrationProps)
Creates a new OSGiComponent from the given lifecycle provider. Uses the given registration properties when registering the managed service to the OSGi Service Registry.

Parameters:
context - BundleContext for accessing the OSGi Service Registry
lifecycle - lifecycle provider for the managed service
registrationProps - optional properties to be used when registering the managed service to the OSGi Service Registry. These are combined with any properties from the ServiceLifecycleProvider

OSGiComponent

public OSGiComponent(org.osgi.framework.BundleContext context,
                     ServiceLifecycleProvider<T> lifecycle,
                     Properties registrationProps,
                     boolean selfRegister)
Creates a new OSGiComponent from the given lifecycle provider. Uses the given registration class name and properties when registering the managed service to the OSGi Service Registry.

Parameters:
context - BundleContext for accessing the OSGi Service Registry
lifecycle - lifecycle provider for the managed service
registrationProps - optional properties to be used when registering the managed service to the OSGi Service Registry. These are combined with any properties from the ServiceLifecycleProvider
selfRegister - determines if this OSGiComponent should register itself when started, by default this is true

OSGiComponent

public OSGiComponent(org.osgi.framework.BundleContext context,
                     ServiceLifecycleProvider<T> lifecycle,
                     Properties registrationProps,
                     Properties uniqueProps,
                     boolean selfRegister)
Creates a new OSGiComponent from the given lifecycle provider. Uses the given registration class name and properties when registering the managed service to the OSGi Service Registry.

Parameters:
context - BundleContext for accessing the OSGi Service Registry
lifecycle - lifecycle provider for the managed service
registrationProps - optional properties to be used when registering the managed service to the OSGi Service Registry. These are combined with any properties from the ServiceLifecycleProvider
registrationClassNames - class names to be used when registering the managed service to the OSGi Service Registry. By default, this value is taken from the ServiceLifecycleProvider's getServiceClass().
Method Detail

start

public void start()
Starts the OSGiComponent. Begins tracker dependencies and notifies the lifecycle provider of dependency changes. The OSGiComponent, by default, adds itself to the OSGi Service Registry. This can be disabled by calling setSelfRegistrationEnabled(false). The OSGiComponent can be unregistered by calling unregisterSelf(), and can be registered by calling registerSelf()

Specified by:
start in interface ManagedService<T>

stop

public void stop()
Stops tracking dependency changes. Does not modify the existing service or its OSGi registration state. Call unregister() to unregister the service being managed.

Specified by:
stop in interface ManagedService<T>

dispose

public void dispose()
Description copied from interface: ManagedService
Stops and unregisters the service, cleans up the service lifecycle and management, and stops and unregisters the ManagedService.

Specified by:
dispose in interface ManagedService<T>

setSelfRegistrationEnabled

public void setSelfRegistrationEnabled(boolean enabled)
If set true, this OSGiComponent will register itself when start() is called, or immediately if start has already been called. If set false and the component is already registered, it will be unregistered. By default this is set to true.

Parameters:
enabled - true to enable self-registration of the OSGiComponent

getSelfRegistrationEnabled

public boolean getSelfRegistrationEnabled()
Returns true if this OSGiComponent should register itself.

Returns:
true if this OSGiComponent should register itself

registerSelf

public void registerSelf()
Add this OSGiComponent to the OSGi Service Registry.


unregisterSelf

public void unregisterSelf()
Removes this OSGiComponent from the OSGi Service Registry


setRegistrationEnabled

public void setRegistrationEnabled(boolean enabled)
Description copied from interface: ManagedService
If set true, the Service being managed will be automatically added to the Service Registry when available. The default value is true.

Specified by:
setRegistrationEnabled in interface ManagedService<T>
Parameters:
enabled - if true the service will be automatically registered to the Service Registry when available.

getRegistrationEnabled

public boolean getRegistrationEnabled()
Description copied from interface: ManagedService
Returns true if automatic service registration is enabled.

Specified by:
getRegistrationEnabled in interface ManagedService<T>
Returns:
true if automatic service registration is enabled

unregister

public void unregister()
Description copied from interface: ManagedService
Unregisters the service if it is registered. Call setRegistrationEnabled(false) to prevent the service from being registered when dependencies change.

Specified by:
unregister in interface ManagedService<T>

register

public void register()
Description copied from interface: ManagedService
Registers the service if it is available.

Specified by:
register in interface ManagedService<T>

getDependencies

public List<DependencyDescriptor> getDependencies()
Description copied from interface: ManagedService
Returns a list describing the service dependencies of this ManagedService.

Specified by:
getDependencies in interface ManagedService<T>
Returns:
list describing the service dependencies of this ManagedService.

getDependencyStatus

public boolean getDependencyStatus(String dependencyId)
Description copied from interface: ManagedService
Returns true if the specified dependency is available.

Specified by:
getDependencyStatus in interface ManagedService<T>
Parameters:
dependencyId - name of the dependency to check
Returns:
true if the specified dependency is available

getRegistrationProperties

public Properties getRegistrationProperties()
Description copied from interface: ManagedService
Returns the registration properties to use when registering the service. These may change throughout the lifetime of the service.

Specified by:
getRegistrationProperties in interface ManagedService<T>
Returns:
registration properties to use when registering the service

isAvailable

public boolean isAvailable()
Description copied from interface: ManagedService
Returns true if the service is available and ready to use.

Specified by:
isAvailable in interface ManagedService<T>
Returns:
true if the service is available and ready to use

isRegistered

public boolean isRegistered()
Description copied from interface: ManagedService
Returns true if the service has been added to the Service Registry.

Specified by:
isRegistered in interface ManagedService<T>
Returns:
true if the service has been added to the Service Registry

getServiceClassNames

public String[] getServiceClassNames()
Description copied from interface: ManagedService
Returns the class names of service being managed.

Specified by:
getServiceClassNames in interface ManagedService<T>
Returns:
class names of service being managed

getDependencyCount

public int getDependencyCount()
Description copied from interface: ManagedService
Returns the number of dependencies for this ManagedService.

Specified by:
getDependencyCount in interface ManagedService<T>
Returns:
number of dependencies for this ManagedService

getAvailableDependencyCount

public int getAvailableDependencyCount()
Description copied from interface: ManagedService
Returns the number of satisfied dependencies.

Specified by:
getAvailableDependencyCount in interface ManagedService<T>
Returns:
number of satisfied dependencies

getLogger

public org.slf4j.Logger getLogger()


Copyright © 2011-2013. All Rights Reserved.