Include Page | ||||
---|---|---|---|---|
|
...
Lifecycle Controller Handler
The lifecycle controller lifecycle handler allows a component implementation to participate to the instance lifecycle. This handler allows you checking instances configuration (file existence for instance).So, you can immediately decide to stop an instance if the configuration is incorrect (correct properties, accessible resources...). The licecyel controller impacts the instance lifecycle, if you want to impact only the registered service, have a look to the service controller (service providing).
Div | ||||||
---|---|---|---|---|---|---|
| ||||||
|
...
iPOJO
...
instance lifecycle & Lifecycle controller
Once started, iPOJO instances can be either valid or invalid. The decision comes from handlers. An instance is valid if every plugged handler are valid. As soos Basically it means that all required services are available. As soon as one handler becomes invalid, the instance becomes invalid.
The lifecycle controller just monitors a field inside the POJO class. When this field becomes 'false
', the handler becomes invalid, and so the instance becomes invalid. When the field get the 'true
' value, the handler becomes valid, and if all handlers are valid, the instance becomes valid.
An example
Imagine the following component :
Code Block |
---|
@Component public class LifecycleControllerTest { @Controller private boolean m_state; private String m_conf; @Property public void setConf(String newConf) { System.out.println("setConf : " + newConf); if (newConf.equals("fooa correct value")) { m_state = true; // update controller value. } else { m_state = false; // update control value } } } |
with the following metadata If you don't want to use annotations, the following snippet does the same job using XML:
Code Block | ||||
---|---|---|---|---|
| ||||
<component classname="org.apache.felix.ipojo.test.scenarios.component.LifecycleControllerTest" name="lcTest" immediate="true" architecture="true"> <controller field="m_state"/> <properties> <property name="conf" field="m_conf" method="setConf"/> </properties> </component> |
This component declares the m_state
field as a lifecycle controller (<controller/>
element)
The component requires the conf
property. iPOJO checks if this property is inside the pushed configuration, but cannot checks if the configuration is correct according to the component semantic. When the instance is created, the setConf
method is called with the pushed given value. If the given conf
property is "foovalid" the m_state
field (i.e. the controller) becomes is set to true
. Else, the m_state
receives the is set to false
value. It means that the lifecycle controller handler becomes invalid and as a consequence, the instance becomes invalid.
Include Page | ||||
---|---|---|---|---|
|