Apache

The controller lifecycle handler allows a component implementation to participate to the instance lifecycle. This handler allows you checking instances configuration (file existence for instance).

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 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. When the field get the 'true' value, the handler becomes valid.

An exemple

Imagine the following component :

public class LifecycleControllerTest {

    private boolean m_state;
    private String m_conf;

    public void setConf(String newConf) {
        System.out.println("setConf : " + newConf);
        if (newConf.equals("foo")) {
            m_state = true;
        } else {
            m_state = false;
        }
    }
}

with the following metadata :

<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. When the instance is created, the setConf method is called with the pushed value. If the given 'conf' property is "foo" the 'm_state' field (i.e. the controller) becomes true. Else, the 'm_state' receives the false value. It means that the lifecycle controller handler becomes invalid and as a consequence, the instance becomes invalid.


Overview
Getting Started
User Guide
Tools
Developer Guide
Misc & Contact