org.apache.felix.servicebinder
Class InstanceManager

java.lang.Object
  extended by org.apache.felix.servicebinder.InstanceManager
All Implemented Interfaces:
Instance, InstanceReference

public class InstanceManager
extends Object
implements InstanceReference, Instance

A InstanceManager is created for every component instance. * * When the InstanceManager is instantiated, a collection of DependencyManagers is * created. Each dependency manager corresponds to a required service * * A InstanceManager follows a sequence of clearly defined steps. * * 1.- Creation : the binder instance is created, its state becomes CREATED. This step is further divided * in the following substeps: * - The binder instance checks if all of the dependencies are valid, if this * is false, it returns. * - If the dependendencies are valid, its state becomes executing. The object from * the instance class is created (if this object receives a ServiceBinderContext as * a parameter in its constructor, the context is passed to it. * - The validate() method is called on the dependency managers, this will cause * calls on the binding methods to occur * - The binder instance adds itself to the list of binder instances in the activator * - The binder instance registers the services implemented by the instance object. * * 2.- Disposal : * * @author Felix Project Team


Nested Class Summary
static class InstanceManager.StateChangeMulticaster
           
 
Nested classes/interfaces inherited from interface org.apache.felix.servicebinder.InstanceReference
InstanceReference.ValueHolder
 
Field Summary
 
Fields inherited from interface org.apache.felix.servicebinder.InstanceReference
INSTANCE_BUNDLE, INSTANCE_DEPENDENCIES, INSTANCE_METADATA, INSTANCE_STATE
 
Fields inherited from interface org.apache.felix.servicebinder.architecture.Instance
INSTANCE_CREATED, INSTANCE_DESTROYED, INSTANCE_INVALID, INSTANCE_VALID
 
Method Summary
 void addInstanceReferenceListener(InstanceReferenceListener l)
          Adds an instance reference listener to listen for changes to the availability of the underlying object associated with this instance reference.
protected  void fireInstanceReferenceInvalidating()
          Fires an event when the instance reference is invalidating
protected  void fireInstanceReferenceValidated()
          Fires an event when the instance reference has been validated
 Object get(String name)
          Get a property associated with this instance.
 long getBundleId()
          Get the state
 Instance[] getChildInstances()
          Get a list of child instances in case this is a factory
 Dependency[] getDependencies()
          Get an array of dependencies for this instance.
 InstanceMetadata getInstanceMetadata()
          Returns the InstanceMetadata
 Object getObject()
          Get the object that is implementing this descriptor
 int getState()
          Get the state
 void put(String name, Object obj)
          Associate a property with this instance.
 void removeInstanceReferenceListener(InstanceReferenceListener l)
          Removes an instance reference listener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstanceMetadata

public InstanceMetadata getInstanceMetadata()
Returns the InstanceMetadata

Specified by:
getInstanceMetadata in interface Instance
Returns:
the isntance metadata

getObject

public Object getObject()
Get the object that is implementing this descriptor

Specified by:
getObject in interface InstanceReference
Returns:
the object that implements

getState

public int getState()
Get the state

Specified by:
getState in interface Instance
Returns:
an integer representing the state of the instance

getBundleId

public long getBundleId()
Get the state

Specified by:
getBundleId in interface Instance
Returns:
an integer with the bundle id

get

public Object get(String name)
Get a property associated with this instance. For classes implementing this method, special care must be taken for values implementing InstanceReference.ValueHolder. In such cases, the value itself should not be returned, but the value of InstanceReference.ValueHolder.get() should be returned instead. This may be used to defer creating value objects in cases where creating the value object is expensive.

Specified by:
get in interface InstanceReference
Parameters:
name - the name of the property to retrieve.
Returns:
the value of the associated property or null.

put

public void put(String name,
                Object obj)
Associate a property with this instance. For classes implementing this method, special care must be taken for values implementing InstanceReference.ValueHolder. In such cases, the value itself should not be returned, but the value of InstanceReference.ValueHolder.get() should be returned instead. This may be used to defer creating value objects in cases where creating the value object is expensive.

Specified by:
put in interface InstanceReference
Parameters:
name - the name of the property to add.
obj - the value of the property.

addInstanceReferenceListener

public void addInstanceReferenceListener(InstanceReferenceListener l)
Adds an instance reference listener to listen for changes to the availability of the underlying object associated with this instance reference.

Specified by:
addInstanceReferenceListener in interface InstanceReference
Parameters:
l - the listener to add.

removeInstanceReferenceListener

public void removeInstanceReferenceListener(InstanceReferenceListener l)
Removes an instance reference listener.

Specified by:
removeInstanceReferenceListener in interface InstanceReference
Parameters:
l - the listener to remove.

fireInstanceReferenceValidated

protected void fireInstanceReferenceValidated()
Fires an event when the instance reference has been validated


fireInstanceReferenceInvalidating

protected void fireInstanceReferenceInvalidating()
Fires an event when the instance reference is invalidating


getDependencies

public Dependency[] getDependencies()
Get an array of dependencies for this instance. This method is declared in the Instance interface

Specified by:
getDependencies in interface Instance
Returns:
an array of Dependencies

getChildInstances

public Instance[] getChildInstances()
Get a list of child instances in case this is a factory

Specified by:
getChildInstances in interface Instance
Returns:
an array of Instances


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.