org.apache.felix.scr.impl
Class DelayedComponentManager

java.lang.Object
  extended by org.apache.felix.scr.impl.DelayedComponentManager
All Implemented Interfaces:
Component, ComponentManager, org.osgi.framework.ServiceFactory, org.osgi.service.component.ComponentInstance

public class DelayedComponentManager
extends java.lang.Object
implements org.osgi.framework.ServiceFactory

The DelayedComponentManager TODO

Version:
$Rev$, $Date: 2007-11-23 14:02:49 +0100 (Fri, 23 Nov 2007) $
Author:
fmeschbe

Field Summary
 
Fields inherited from interface org.apache.felix.scr.Component
STATE_ACTIVATING, STATE_ACTIVE, STATE_DEACTIVATING, STATE_DESTROYED, STATE_DISABLED, STATE_ENABLED, STATE_FACTORY, STATE_REGISTERED, STATE_UNSATISFIED
 
Constructor Summary
DelayedComponentManager(org.apache.felix.scr.impl.BundleComponentActivator activator, ComponentMetadata metadata, long componentId)
           
 
Method Summary
 void activate()
          Activates this component if satisfied.
protected  java.util.Dictionary copyTo(java.util.Dictionary target, java.util.Dictionary source)
          Copies the properties from the source Dictionary into the target Dictionary.
protected  boolean createComponent()
          Method is called by activate() in STATE_ACTIVATING or by getService(Bundle, ServiceRegistration) in STATE_REGISTERED.
protected  java.lang.Object createImplementationObject(org.osgi.service.component.ComponentContext componentContext)
           
 void deactivate()
          Deactivates the component.
protected  void deleteComponent()
          Method is called by deactivate() in STATE_DEACTIVATING
 void disable()
          Disables this component and - if active - first deactivates it.
 void dispose()
          Before doing real disposal, we also have to unregister the managed service which was registered when the instance was created.
protected  void disposeImplementationObject(java.lang.Object implementationObject, org.osgi.service.component.ComponentContext componentContext)
           
 void enable()
          Enables this component and - if satisfied - also activates it.
 org.osgi.framework.Bundle getBundle()
          Returns the Bundle declaring this component.
 java.lang.String getClassName()
          Returns the class name of the Component implementation.
 ComponentMetadata getComponentMetadata()
          Get the component information
 java.lang.String getFactory()
          Returns the component factory name or null if this component is not defined as a component factory.
 long getId()
          Returns the component ID of this component.
 java.lang.Object getInstance()
          Get the object that is implementing this descriptor
 java.lang.String getName()
          Returns the name of the component, which is also used as the service PID.
 java.util.Dictionary getProperties()
          Returns the (private copy) of the Component properties to be used for the ComponentContext as well as eventual service registration.
 Reference[] getReferences()
          Returns an array of Reference instances representing the service references (or dependencies) of this Component.
protected  java.lang.Object getService()
          Returns the service object to be registered if the service element is specified.
 java.lang.Object getService(org.osgi.framework.Bundle arg0, org.osgi.framework.ServiceRegistration arg1)
           
 java.lang.String[] getServices()
          Returns an array of service names provided by this Component or null if the Component is not registered as a service.
 int getState()
          Returns the current state of the Component, which is one of the STATE_* constants defined in this interface.
 boolean isDefaultEnabled()
          Returns whether the Component is declared to be enabled initially.
 boolean isImmediate()
          Returns whether the Component is an Immediate or a Delayed Component.
 boolean isServiceFactory()
          Returns true if this component is a service factory.
 void reactivate()
          Cycles this component by deactivating it and - if still satisfied - activating it again.
 void reconfigure()
          Reconfigures this component by deactivating and activating it.
 void reconfigure(java.util.Dictionary configuration)
          Called by the Configuration Admin Service to update the component with Configuration properties.
protected  org.osgi.framework.ServiceRegistration registerComponentService()
           
protected  void setFactoryProperties(java.util.Dictionary dictionary)
           
protected  void setState(int newState)
          sets the state of the manager
protected  boolean setStateConditional(int requiredStates, int newState)
          If the state is currently one of the requiredStates, the state is set to newState and true is returned.
 java.lang.String stateToString(int state)
           
 void ungetService(org.osgi.framework.Bundle arg0, org.osgi.framework.ServiceRegistration arg1, java.lang.Object arg2)
           
protected  void unregisterComponentService()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelayedComponentManager

public DelayedComponentManager(org.apache.felix.scr.impl.BundleComponentActivator activator,
                               ComponentMetadata metadata,
                               long componentId)
Parameters:
activator -
metadata -
componentId -
Method Detail

createComponent

protected boolean createComponent()
Method is called by activate() in STATE_ACTIVATING or by getService(Bundle, ServiceRegistration) in STATE_REGISTERED.

Returns:
true if creation of the component succeeded. If false is returned, the cause should have been logged.

deleteComponent

protected void deleteComponent()
Method is called by deactivate() in STATE_DEACTIVATING


getService

protected java.lang.Object getService()
Returns the service object to be registered if the service element is specified.

Extensions of this class may overwrite this method to return a ServiceFactory to register in the case of a delayed or a service factory component.


getService

public java.lang.Object getService(org.osgi.framework.Bundle arg0,
                                   org.osgi.framework.ServiceRegistration arg1)
Specified by:
getService in interface org.osgi.framework.ServiceFactory

ungetService

public void ungetService(org.osgi.framework.Bundle arg0,
                         org.osgi.framework.ServiceRegistration arg1,
                         java.lang.Object arg2)
Specified by:
ungetService in interface org.osgi.framework.ServiceFactory

dispose

public void dispose()
Before doing real disposal, we also have to unregister the managed service which was registered when the instance was created.

Specified by:
dispose in interface ComponentManager
Specified by:
dispose in interface org.osgi.service.component.ComponentInstance

getInstance

public java.lang.Object getInstance()
Get the object that is implementing this descriptor

Specified by:
getInstance in interface org.osgi.service.component.ComponentInstance
Returns:
the object that implements the services

createImplementationObject

protected java.lang.Object createImplementationObject(org.osgi.service.component.ComponentContext componentContext)

disposeImplementationObject

protected void disposeImplementationObject(java.lang.Object implementationObject,
                                           org.osgi.service.component.ComponentContext componentContext)

setFactoryProperties

protected void setFactoryProperties(java.util.Dictionary dictionary)

getProperties

public java.util.Dictionary getProperties()
Returns the (private copy) of the Component properties to be used for the ComponentContext as well as eventual service registration.

Method implements the Component Properties provisioning as described in 112.6, Component Properties.

Specified by:
getProperties in interface Component
Returns:
a private Hashtable of component properties

reconfigure

public void reconfigure(java.util.Dictionary configuration)
Called by the Configuration Admin Service to update the component with Configuration properties.

Parameters:
configuration - The configuration properties for the component from the Configuration Admin Service or null if there is no configuration or if the configuration has just been deleted.

enable

public final void enable()
Enables this component and - if satisfied - also activates it. If enabling the component fails for any reason, the component ends up disabled.

This method ignores the enabled flag of the component metadata and just enables as requested.

This method schedules the enablement for asynchronous execution.

Specified by:
enable in interface Component
Specified by:
enable in interface ComponentManager

activate

public final void activate()
Activates this component if satisfied. If any of the dependencies is not met, the component is not activated and remains unsatisifed.

This method schedules the activation for asynchronous execution.


reconfigure

public final void reconfigure()
Reconfigures this component by deactivating and activating it. During activation the new configuration data is retrieved from the Configuration Admin Service.

Specified by:
reconfigure in interface ComponentManager

reactivate

public final void reactivate()
Cycles this component by deactivating it and - if still satisfied - activating it again.

This method immediately deactivates the component to prevent action with old configuration/references and schedules the reactivation for asynchronous execution.


deactivate

public final void deactivate()
Deactivates the component.

This method unlike other state change methods immediately takes action and deactivates the component. The reason for this is, that this method is called when a required service is not available any more and hence the component cannot work.


disable

public final void disable()
Disables this component and - if active - first deactivates it. The component may be reenabled by calling the enable() method.

This method schedules the disablement for asynchronous execution.

Specified by:
disable in interface Component
Specified by:
disable in interface ComponentManager

getId

public long getId()
Description copied from interface: Component
Returns the component ID of this component. This ID is managed by the SCR.

Specified by:
getId in interface Component

getName

public java.lang.String getName()
Description copied from interface: Component
Returns the name of the component, which is also used as the service PID. This method provides access to the name attribute of the component element.

Specified by:
getName in interface Component

getBundle

public org.osgi.framework.Bundle getBundle()
Description copied from interface: Component
Returns the Bundle declaring this component.

Specified by:
getBundle in interface Component

getClassName

public java.lang.String getClassName()
Description copied from interface: Component
Returns the class name of the Component implementation. This method provides access to the class attribute of the implementation element.

Specified by:
getClassName in interface Component

getFactory

public java.lang.String getFactory()
Description copied from interface: Component
Returns the component factory name or null if this component is not defined as a component factory. This method provides access to the factory attribute of the component element.

Specified by:
getFactory in interface Component

getReferences

public Reference[] getReferences()
Description copied from interface: Component
Returns an array of Reference instances representing the service references (or dependencies) of this Component. If the Component has no references, null is returned.

Specified by:
getReferences in interface Component

isImmediate

public boolean isImmediate()
Description copied from interface: Component
Returns whether the Component is an Immediate or a Delayed Component. This method provides access to the immediate attribute of the component element.

Specified by:
isImmediate in interface Component

isDefaultEnabled

public boolean isDefaultEnabled()
Description copied from interface: Component
Returns whether the Component is declared to be enabled initially. This method provides access to the enabled attribute of the component element.

Specified by:
isDefaultEnabled in interface Component

isServiceFactory

public boolean isServiceFactory()
Description copied from interface: Component
Returns true if this component is a service factory. This method returns the value of the serviceFactory attribute of the service element. If the component has no service element, this method returns false.

Specified by:
isServiceFactory in interface Component

getServices

public java.lang.String[] getServices()
Description copied from interface: Component
Returns an array of service names provided by this Component or null if the Component is not registered as a service. This method provides access to the interface attributes of the provide elements.

Specified by:
getServices in interface Component

registerComponentService

protected org.osgi.framework.ServiceRegistration registerComponentService()

unregisterComponentService

protected void unregisterComponentService()

copyTo

protected java.util.Dictionary copyTo(java.util.Dictionary target,
                                      java.util.Dictionary source)
Copies the properties from the source Dictionary into the target Dictionary.

Parameters:
target - The Dictionary into which to copy the properties. If null a new Hashtable is created.
source - The Dictionary providing the properties to copy. If null or empty, nothing is copied.
Returns:
The target is returned, which may be empty if source is null or empty and target was null.

getComponentMetadata

public ComponentMetadata getComponentMetadata()
Description copied from interface: ComponentManager
Get the component information

Specified by:
getComponentMetadata in interface ComponentManager
Returns:
a ComponentMetadata object

getState

public int getState()
Description copied from interface: Component
Returns the current state of the Component, which is one of the STATE_* constants defined in this interface.

Specified by:
getState in interface Component

setState

protected void setState(int newState)
sets the state of the manager


setStateConditional

protected boolean setStateConditional(int requiredStates,
                                      int newState)
If the state is currently one of the requiredStates, the state is set to newState and true is returned. Otherwise the state is not changed and false is returned.

This method atomically checks the current state and sets the new state.

Parameters:
requiredStates - The set of states required for the state change to happen.
newState - The new state to go into.
Returns:
true if the state was one of the required states and the new state has now been entered.

stateToString

public java.lang.String stateToString(int state)