Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
xml
xml
<component className="...Foo">
       <dependency field="fs"/>
       <callback initialtransition="INVALID" final="VALIDvalidate" method="start"/>
       <callback initialtransition="VALIDinvalidate" final="INVALID" method="stop"/>
</component>

When an instance of this component type is created, the start method is called as soon as the Foo Service (service dependencyrequirement) becomes available. If the Foo Service is no more available or when the instance is stopped, the stop method is called.

The invoked methods have no argument, but could be private, protected or public. Moreover, the INVALID=>VALID (validate) method can use service dependency dependencies (the instance becomes valid means that all required services are available); however, in the stop method (invalidate) it is possible that one of these dependency can be null. Indeed, the departure of a service can be the cause of the instance invalidation.

...

One usage of lifecycle callback is when the instance needs to create threads. Indeed, the thread can be created in the INVALID=>VALID validate callback, and stopped in the VALID=>INVALID invalidate method. The next class shows an example of a class creating a thread.

...

Code Block
xml
xml
<component className="... HelloRequesterImpl">
		<dependency field="HelloService"/>
		<callback initialtransition="INVALIDvaldiate" final="VALID" method="starting"/>
		<callback initialtransition="VALIDinvaldiate" final="INVALID" method="stopping"/>
</component>

...

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 callbackthe Validate callback. However, it stills a difference between the immediate and the validate callback. The constructor is call only once time. The validate callback is re-called each time the instance becomes valid.

However as there is no destructor in Java, the VALID=>INVALID invalidate callback is necessary if some actions are needed when stopping.

Advanced features

Static callbacks

You can call a static method as a callback. By default, the callback is not static. To call a static method, you need to add the isStatic attribute in the callback metadata :

...

Callback on several objects

If you instance has created several objects (called the implementation class constructor several times), the callback is called on each object in the creation order.