net.sf.mmm.util.component.base
Class InitializationState

java.lang.Object
  extended by net.sf.mmm.util.component.base.InitializationState

public class InitializationState
extends Object

This class represents the state of an initialization.
It therefore offers the method requireNotInitilized() that can be called before initialization e.g. from injection-setters so nothing can be re-injected after initialization. Additionally there is requireInitilized() that can be called after initialization e.g. from functional methods of the component to ensure that the component has been initialized.

Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
PostConstruct

Field Summary
private  AtomicInteger state
          This field holds the atomic state of this object.
private static int STATE_INITIALIZED
          The state if initialization has completed.
private static int STATE_INITIALIZING
          The state during initialization.
private static int STATE_UNINITIALIZED
          The initial state.
 
Constructor Summary
InitializationState()
          The constructor.
 
Method Summary
 boolean isInitialized()
          This method gets the status of the initialization .
 void requireInitilized()
          This method checks that this state has already been initialized.
 void requireNotInitilized()
          This method checks that this state has NOT yet been initialized.
 void setInitialized()
          This method sets the state to initialized.
 boolean setInitializing()
          This method sets the state to initializing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_UNINITIALIZED

private static final int STATE_UNINITIALIZED
The initial state.

See Also:
Constant Field Values

STATE_INITIALIZING

private static final int STATE_INITIALIZING
The state during initialization.

See Also:
Constant Field Values

STATE_INITIALIZED

private static final int STATE_INITIALIZED
The state if initialization has completed.

See Also:
Constant Field Values

state

private AtomicInteger state
This field holds the atomic state of this object.

Constructor Detail

InitializationState

public InitializationState()
The constructor.

Method Detail

setInitializing

public boolean setInitializing()
This method sets the state to initializing. This should be done to start the initialization in a thread-safe and atomic way. After the initialization has completed, the method setInitialized() should be invoked.

Returns:
true if the state was NOT initialized and is now initialized, false if the state is already initialized.

setInitialized

public void setInitialized()
This method sets the state to initialized.
ATTENTION:
You need to call setInitializing() before you invoke this method!


isInitialized

public boolean isInitialized()
This method gets the status of the initialization .

Returns:
true if this component has been initialized, false otherwise.

requireInitilized

public void requireInitilized()
                       throws NotInitializedException
This method checks that this state has already been initialized.

Throws:
NotInitializedException - if this state has NOT been initialized yet.

requireNotInitilized

public void requireNotInitilized()
                          throws AlreadyInitializedException
This method checks that this state has NOT yet been initialized.

Throws:
AlreadyInitializedException - if this state has already been initialized.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.