Kang Desheng wrote:
Components which implement the Startable interface are componentsI am a newbie to Avalon and just read bunch of source code of Avalon. I am really confused by the lifecycle interfaces. I don't know how to distinguish Startable and Initializable/Disposable. I did some research about the existing code of Avalon projects such as Phoenix, cocoon, excalibur, tweety and found that the stop method of Startable interface is seldom used, even ContainerUtil.shutdown method binds stop and dispose together.
which need to be started and stopped. An example would be a component
which has a daemon thread running in the background for the life of the
component. The thread would be created and started in the start method,
then stopped in the stop method. Start is not called until after the logger
has been set, the component has been configured and initialized. Stop
must be called while the component is still valid, so it must happen before
dispose is called.
Disposable provides the dispose method. This is usually where resources
allocated by the component during its life are freed up. An example would
be a component which looked up an instance of another component in its
initialize method. That instance may be needed within the stop method and
so it is released in the dispose method.
Containers hold a contract to always call the various lifecycle methods in
the correct order. With the Interfaces: LogEnabled, Configureable,
Initializable, Startable, Disposable. The following life cycle methods will
always be called in the following order:
enableLogging (LogEnabled)
configure (Configurable)
initialize (Initializable)
start (Startable)
stop (Startable)
dispose (Disposable)
Once the dispose method of a component has been called. All references
to it should be considered invalid and the component should be GCed.
If you look at the component as a object that you are controlling yourself, then
everything could be done in a simple start and stop method. But avalon
components are designed to fit into a framework where they can be dropped
into a container and expected to work as is. Doing things in the standard
places makes this possible.
Could anybody tell me when to use Startable interface?Containers are all designed to only call lifecycle methods for components which
If the application just has one main thread, do we
still need to use Startable?
implement specific lifecycle interfaces. So it is perfectly legal to have one
component which implements all the above interfaces, while a second component
implements only the Initializable interface for example. So the answer to your
question is no, you do not have to implement Startable. :-)
Hope this helps clear things up a bit.
Cheers,
Leif
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>