Hi peeps,
lots of code that assumes a 'hostile' environment keeps track of the
lifecycle and ensures it is correctly followed. Part of the defensive
coding paradigm I guess. Often not to accurately, though :D
I wrote a class org.apache.avalon.framework.State which codifies this
correct behaviour. The proposal is that it is included in framework
4.1.4. I've yet to test it (and write the testcase).
comments?
cheers,
- Leo
Example usage is something like:
/**
* Convenience base class. Typical use involves overriding initialize()
and dispose(),
* but make sure to call super on them.
*
* @author <a href="mail at leosimons dot com">Leo Simons</a>
* @version $Id$
*/
public abstract class AbstractService
implements LogEnabled, Configurable, Contextualizable,
Serviceable, Initializable,
Disposable
{
// ---------------------------------------------------------------
// Instance Properties
// ---------------------------------------------------------------
/**
* Provides access to the logger.
*/
protected Logger m_logger = null;
protected ServiceManager m_serviceManager = null;
/**
* Provides access to the serviceManager.
*/
protected Configuration m_configuration = null;
/**
* Provides access to the context.
*/
protected Context m_context = null;
/**
* Provides access to the current state.
*/
protected int m_state = State.STATIC;
// ---------------------------------------------------------------
// Constructors
// ---------------------------------------------------------------
/**
* default constructor.
*/
public void ContainerImpl()
{
m_state = State.change( m_state, State.CONSTRUCTED, this );
}
// ---------------------------------------------------------------
// Lifecycle Methods
// ---------------------------------------------------------------
/** @see LogEnabled@enableLogging */
public void enableLogging( Logger logger )
{
m_state = State.change( m_state, State.LOGENABLED, this );
m_logger = logger;
}
/** @see Contextualizable#contextualize */
public void contextualize( Context context )
throws ContextException
{
m_state = State.change( m_state, State.CONTEXTUALIZED, this );
m_context = context;
}
/** @see Configurable#configure */
public void configure( Configuration configuration )
throws ConfigurationException
{
m_state = State.change( m_state, State.CONFIGURED, this );
m_configuration = configuration;
}
/** @see Serviceable#service */
public void service( ServiceManager manager )
throws ServiceException
{
m_state = State.change( m_state, State.SERVICED, this );
m_serviceManager = manager;
}
/** @see Initializable#initialize */
public void initialize()
throws Exception
{
m_state = State.change( m_state, State.INITIALIZED, this );
}
/** @see Disposable#dispose */
public void dispose()
{
m_state = State.change( m_state, State.DISPOSED, this );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
- Re: [proposal] avalon-framework state checker Leo Simons
- Re: [proposal] avalon-framework state checker Berin Loritsch
- Re: [proposal] avalon-framework state checker Peter Donald
- Re: [proposal] avalon-framework state checker Leo Simons
