|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.felix.ipojo.InstanceManager
public class InstanceManager
This class defines the container of primitive instances. It manages content initialization and handlers cooperation.
Field Summary | |
---|---|
protected String |
m_className
The name of the component type implementation class. |
protected HandlerManager[] |
m_handlers
The handler object list. |
protected List |
m_listeners
The instance state listener list. |
protected String |
m_name
The name of the component instance. |
protected int |
m_state
The current instance state ( ComponentInstance.STOPPED at the beginning). |
Fields inherited from interface org.apache.felix.ipojo.ComponentInstance |
---|
DISPOSED, INVALID, STOPPED, VALID |
Constructor Summary | |
---|---|
InstanceManager(ComponentFactory factory,
BundleContext context,
HandlerManager[] handlers)
Creates a new Component Manager. |
Method Summary | |
---|---|
void |
addInstanceStateListener(InstanceStateListener listener)
Registers an instance state listener. |
void |
configure(Element metadata,
Dictionary configuration)
Configures the instance manager. |
Object |
createPojoObject()
Creates an instance of the content. |
void |
deletePojoObject(Object pojo)
Deletes a POJO object. |
void |
dispose()
Disposes the instance. |
String |
getClassName()
Gets the implementation class of the component type. |
Class |
getClazz()
Gets the manipulated class. |
BundleContext |
getContext()
Gets the bundle context used by this component instance. |
ComponentFactory |
getFactory()
Gets the factory which has created the current instance. |
Object |
getFieldValue(String fieldName)
Gives access to a field value of the first created pojo. |
Object |
getFieldValue(String fieldName,
Object pojo)
Gives access to a field value to the given created pojo. |
BundleContext |
getGlobalContext()
Gets the global bundle context. |
Handler |
getHandler(String name)
Returns a specified handler. |
InstanceDescription |
getInstanceDescription()
Gets the description of the current instance. |
String |
getInstanceName()
Gets the instance name. |
ServiceContext |
getLocalServiceContext()
Gets the local service context. |
Object |
getPojoObject()
Gets the first object created by the instance. |
Object[] |
getPojoObjects()
Gets the object array created by the instance. |
Set |
getRegistredFields()
Gets the list of registered fields (containing field names). |
Handler[] |
getRegistredHandlers()
Gets the list of handlers plugged (i.e. |
Set |
getRegistredMethods()
Gets the list of registered methods (containing method ids). |
int |
getState()
Gets the actual state of the instance. |
boolean |
isStarted()
Checks if the instance is started. |
void |
onEntry(Object pojo,
String methodId,
Object[] args)
Dispatches entry method events on registered method interceptors. |
void |
onError(Object pojo,
String methodId,
Throwable error)
Dispatches error method events on registered method interceptors. |
void |
onExit(Object pojo,
String methodId,
Object result)
Dispatches exit method events on registered method interceptors. |
Object |
onGet(Object pojo,
String fieldName)
This method is called by the manipulated class each time that a GETFIELD instruction is executed. |
void |
onSet(Object pojo,
String fieldName,
Object objectValue)
This method is called by the manipulated class each time that a PUTFILED instruction is executed. |
void |
reconfigure(Dictionary configuration)
Reconfigures the current instance. |
void |
register(FieldMetadata field,
FieldInterceptor interceptor)
Registers a field interceptor. |
void |
register(MethodMetadata method,
MethodInterceptor interceptor)
Registers a method interceptor. |
void |
register(PrimitiveHandler handler,
FieldMetadata[] fields,
MethodMetadata[] methods)
Deprecated. use register(FieldMetadata, FieldInterceptor)
and InstanceManager#register(FieldMetadata, MethodInterceptor) instead. |
void |
removeInstanceStateListener(InstanceStateListener listener)
Unregisters an instance state listener. |
void |
setState(int state)
Sets the state of the component instance. |
void |
start()
Starts the instance manager. |
void |
stateChanged(ComponentInstance instance,
int newState)
State Change listener callback. |
void |
stop()
Stops the instance manager. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected String m_name
protected String m_className
protected final HandlerManager[] m_handlers
protected int m_state
ComponentInstance.STOPPED
at the beginning).
Possible value are
ComponentInstance.INVALID
ComponentInstance.VALID
ComponentInstance.DISPOSED
ComponentInstance.STOPPED
protected List m_listeners
InstanceStateListener
Constructor Detail |
---|
public InstanceManager(ComponentFactory factory, BundleContext context, HandlerManager[] handlers)
factory
- the factory managing the instance managercontext
- the bundle context to give to the instancehandlers
- handler object arrayMethod Detail |
---|
public void configure(Element metadata, Dictionary configuration) throws ConfigurationException
metadata
- the component type metadataconfiguration
- the configuration of the instance
ConfigurationException
- if the metadata are not correctpublic InstanceDescription getInstanceDescription()
getInstanceDescription
in interface ComponentInstance
ComponentInstance.getInstanceDescription()
public Handler[] getRegistredHandlers()
public Handler getHandler(String name)
name
- the class name of the handler to find or its qualified name (namespace:name)
public Object getFieldValue(String fieldName)
fieldName
- the field name.
null
is returned if the value is managed and not already set.public Object getFieldValue(String fieldName, Object pojo)
null
, tries only on managed fields.
fieldName
- the field name.pojo
- the pojo on which computing field value.
null
is returned if the value is managed and not already set.public void start()
start
in interface ComponentInstance
public void stop()
ComponentInstance.STOPPED
,
disables attached handlers, and notifies listeners (InstanceStateListener
)
of the instance stopping process.
stop
in interface ComponentInstance
public void dispose()
ComponentInstance.STOPPED
InstanceStateListener
of the destruction
dispose
in interface ComponentInstance
ComponentInstance.dispose()
public void setState(int state)
Handler.stateChanged(int)
method on the attached handlers.
This method has a reentrant mechanism. If in the flow of the first call the method is called another times,
the second call is stored and executed after the first one finished.
state
- the new statepublic int getState()
ComponentInstance.INVALID
ComponentInstance.VALID
ComponentInstance.DISPOSED
ComponentInstance.STOPPED
getState
in interface ComponentInstance
ComponentInstance.getState()
public boolean isStarted()
ComponentInstance.VALID
or ComponentInstance.INVALID
.
isStarted
in interface ComponentInstance
true
if the instance is started.ComponentInstance.isStarted()
public void addInstanceStateListener(InstanceStateListener listener)
addInstanceStateListener
in interface ComponentInstance
listener
- the listener to register.ComponentInstance.addInstanceStateListener(org.apache.felix.ipojo.InstanceStateListener)
public void removeInstanceStateListener(InstanceStateListener listener)
removeInstanceStateListener
in interface ComponentInstance
listener
- the listener to unregister.ComponentInstance.removeInstanceStateListener(org.apache.felix.ipojo.InstanceStateListener)
public ComponentFactory getFactory()
getFactory
in interface ComponentInstance
ComponentInstance.getFactory()
public Object[] getPojoObjects()
public Object createPojoObject()
createObject()
method, and adds
the created object to the m_pojoObjects
list. Then,
it calls the PrimitiveHandler.onCreation(Object)
methods on attached
handlers.
null
if an error occurs during the
creation.public void deletePojoObject(Object pojo)
pojo
- the pojo to remove from the list of created pojos.public Object getPojoObject()
createObject()
method, and adds
the created object to the m_pojoObjects
list. Then,
it calls the PrimitiveHandler.onCreation(Object)
methods on attached
handlers.
TODO this method has a potential race condition if two threads require a pojo
object at the same time. Only one object will be created, but the second thread
can receive the created object before the PrimitiveHandler.onCreation(Object)
calls.
public Class getClazz()
public void register(PrimitiveHandler handler, FieldMetadata[] fields, MethodMetadata[] methods)
register(FieldMetadata, FieldInterceptor)
and InstanceManager#register(FieldMetadata, MethodInterceptor)
instead.
handler
- the handler to registerfields
- the field metadata listmethods
- the method metadata listpublic void register(FieldMetadata field, FieldInterceptor interceptor)
field
- the field to monitorinterceptor
- the field interceptor objectpublic void register(MethodMetadata method, MethodInterceptor interceptor)
method
- the field to monitorinterceptor
- the field interceptor objectpublic Object onGet(Object pojo, String fieldName)
PrimitiveHandler.onGet(Object, String, Object)
method. If the field value changes, this method call the PrimitiveHandler.onSet(Object, String, Object)
method on each field interceptor monitoring the field in order to advertize the new value.
pojo
- the pojo object on which the field was getfieldName
- the field name on which the GETFIELD instruction is called
public void onEntry(Object pojo, String methodId, Object[] args)
PrimitiveHandler.onEntry(Object, Method, Object[])
methods on method interceptors monitoring the method.
pojo
- the pojo object on which method is invoked.methodId
- the method id used to compute the Method
object.args
- the argument arraypublic void onExit(Object pojo, String methodId, Object result)
Exception
if the method thrown an
exception. If the given object is null
, either the method returns void
,
or the method has returned null
This method calls the PrimitiveHandler#onExit(Object, Method, Object[])
and the
PrimitiveHandler.onFinally(Object, Method)
methods on method interceptors monitoring the method.
pojo
- the pojo object on which method was invoked.methodId
- the method id used to compute the Method
object.result
- the returned object.public void onError(Object pojo, String methodId, Throwable error)
null
This method calls the PrimitiveHandler#onExit(Object, Method, Object[])
and the
PrimitiveHandler.onFinally(Object, Method)
methods on method interceptors monitoring
the method.
pojo
- the pojo object on which the method was invokedmethodId
- the method id used to compute the Method
object.error
- the Throwable object.public void onSet(Object pojo, String fieldName, Object objectValue)
PrimitiveHandler.onSet(Object, String, Object)
method on each field
interceptors monitoring this field.
This method can be invoked with a null
pojo argument when the changes comes from another
handler.
pojo
- the pojo object on which the field was setfieldName
- the field name on which the PUTFIELD instruction is calledobjectValue
- the new value of the fieldpublic BundleContext getContext()
getContext
in interface ComponentInstance
ComponentInstance.getContext()
public BundleContext getGlobalContext()
public ServiceContext getLocalServiceContext()
null
null
if the
instance doesn't live in a composite.public String getInstanceName()
getInstanceName
in interface ComponentInstance
ComponentInstance.getInstanceName()
public void reconfigure(Dictionary configuration)
Handler.reconfigure(Dictionary)
methods on each attached handler, and then recompute the instance
state. Note that the reconfiguration process does not deactivate the
instance.
reconfigure
in interface ComponentInstance
configuration
- the new configuration to pushComponentInstance.reconfigure(java.util.Dictionary)
public String getClassName()
public void stateChanged(ComponentInstance instance, int newState)
setState(int)
method.
stateChanged
in interface InstanceStateListener
instance
- the handler becoming valid or invalidnewState
- the new state of the handlerInstanceStateListener.stateChanged(org.apache.felix.ipojo.ComponentInstance, int)
public Set getRegistredFields()
public Set getRegistredMethods()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |