|
Page Edited :
FELIX :
Lifecycle Callback Handler
Lifecycle Callback Handler has been edited by Clement Escoffier (Jul 04, 2007). Content:The lifecycle callback handler allows invoking methods (callbacks) on the instance when instance's state changed. For example, it allows invoking a start method when the instance becomes valid and a stop method when the instance becomes invalid. Moreover, this handler allows the creation of immediate component. This page presents how to use this handler. Instance LifecycleiPOJO instances have a very simple lifecycle. This lifecycle contains two states: INVALID and VALID. Once an instance is created, this instance can only be valid if all its plugged handlers are valid. For example, an instance requiring a service (and so using the dependency handler) cannot be valid if the required service is unavailable. Indeed, the dependency handler will be invalid. An instance starts and stops in the invalid state. Lifecycle callbackThis handler supports two kinds of callback. The INVALID=>VALID callback are invoked when the instance becomes valid (at starting or when an event allows the instance to become valid). The VALID=>INVALID callback are invoked when the instance becomes invalid (at stopping or when an event invalids the instance). An exampleLet's take an example. The following class requires a FooService and has two lifecycle callback start and stop. public class Foo { FooService fs; private void start() { // Starting method //... fs.foo(); //... } protected void stop() { // Stopping method if(fs!=null) { fs.foo(); } } } For this class, we define the following component type: <component className="...Foo"> <dependency field="fs"/> <callback transition="validate" method="start"/> <callback transition="invalidate" method="stop"/> </component> When an instance of this component type is created, the start method is called as soon as the Foo Service (service requirement) becomes available. If the Foo Service is no more available or when the instance is stopped, the stop method is called.
|
Unsubscribe or edit your notifications preferences
