...
An instance starts and stops in the invalid state.
<IMAGE>
Lifecycle callback
This 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).
<IMAGE>
An example
Let's take an example. The following class requires a FooService and has two lifecycle callback start and stop.
Code Block |
---|
public class Foo { FooService fs; private void start() { // Starting method //... fs.foo(); //... } protected void stop() { // Stopping method if(fs!=null) { fs.foo(); } } } |
...
An instance of an immediate component type is instantiated as soon it becomes valid. It means that, when the instance becomes valid, the constructor of the implementation class is called. This can replace the INVALID=>VALID callback.
<IMAGE>
However as there is no destructor in Java, the VALID=>INVALID callback is necessary if some actions are needed when stopping.
...