public abstract class Manageable extends Object
In environments where Manageable
instances are constructed
dynamically, they are typically expected to have a public no-argument
constructor.
Initially the state of a manageable object is UNUSABLE
. In this
state, the object should be considered unusable. To change to the
USABLE
state, the bootstrap(Map)
and
init(Map)
methods should be called first, as described
below.
The bootstrap(Map)
method can only be called if the
state of this object is UNUSABLE
. If it finishes successfully, the
state then changes to BOOTSTRAPPED
.
After that the init(Map)
method should be called to
initialize or re-initialize this object. This method can only be called
successfully if the current state is either BOOTSTRAPPED
or even
USABLE
.
The deinit()
method is called when this object is no
longer needed. That changes the state back to UNUSABLE
. After
that, bootstrap(Map)
could be called again, though.
Modifier and Type | Class and Description |
---|---|
static class |
Manageable.State
State of a
Manageable object. |
Modifier and Type | Field and Description |
---|---|
static Manageable.State |
BOOTSTRAPPED
The BOOTSTRAPPED state.
|
static Manageable.State |
BOOTSTRAPPING
The BOOTSTRAPPING state.
|
static Manageable.State |
DEINITIALIZING
The DEINITIALIZING state.
|
static Manageable.State |
INITIALIZING
The INITIALIZING state.
|
static Manageable.State |
UNUSABLE
The UNUSABLE state.
|
static Manageable.State |
USABLE
The USABLE state.
|
Modifier | Constructor and Description |
---|---|
protected |
Manageable()
Constructs a new
Manageable . |
Modifier and Type | Method and Description |
---|---|
protected void |
assertUsable()
Asserts that this object is currently usable.
|
void |
bootstrap(Map<String,String> properties)
Performs the bootstrap procedure (wrapper method).
|
protected void |
bootstrapImpl(Map<String,String> properties)
Performs the bootstrap procedure (actual implementation).
|
void |
deinit()
Deinitializes this instance (wrapper method).
|
protected void |
deinitImpl()
Deinitializes this instance (actual implementation).
|
Manageable.State |
getState()
Gets the current state of this object.
|
void |
init(Map<String,String> properties)
Performs the initialization procedure (wrapper method).
|
protected void |
initImpl(Map<String,String> properties)
Performs the initialization procedure (actual implementation).
|
boolean |
isBootstrapped()
Determines if this object is currently bootstrapped.
|
boolean |
isUsable()
Determines if this object is currently usable.
|
public static final Manageable.State UNUSABLE
public static final Manageable.State BOOTSTRAPPING
public static final Manageable.State BOOTSTRAPPED
public static final Manageable.State INITIALIZING
public static final Manageable.State USABLE
public static final Manageable.State DEINITIALIZING
public final Manageable.State getState()
null
.public final void bootstrap(Map<String,String> properties) throws IllegalStateException, MissingRequiredPropertyException, InvalidPropertyValueException, BootstrapException
If the state of this object is valid (it must be UNUSABLE
)
and the argument is not null
, then
bootstrapImpl(Map)
will be called. If that method
succeeds, then this object will be left in the BOOTSTRAPPED
state.
If bootstrapImpl(Map)
throws any exception (even
Error
s), it is wrapped in an BootstrapException
and then
the latter is thrown instead.
properties
- the bootstrap properties, can be null
.IllegalStateException
- if the current state is not UNUSABLE
.MissingRequiredPropertyException
- if a required property is not given.InvalidPropertyValueException
- if the value of a certain property is invalid.BootstrapException
- if the bootstrapping failed for any other reason.protected void bootstrapImpl(Map<String,String> properties) throws MissingRequiredPropertyException, InvalidPropertyValueException, BootstrapException
bootstrap(Map)
, the state and
the argument will have been checked and the state will have been set to
BOOTSTRAPPING
.
The implementation of this method in class Manageable
is
empty.
properties
- the bootstrap properties, not null
.MissingRequiredPropertyException
- if a required property is not given.InvalidPropertyValueException
- if the value of a certain property is invalid.BootstrapException
- if the bootstrapping failed for any other reason.public final void init(Map<String,String> properties) throws IllegalStateException, MissingRequiredPropertyException, InvalidPropertyValueException, InitializationException
If the state of this object is valid (it must be either
BOOTSTRAPPED
or USABLE
) and the argument is not
null
, then initImpl(Map)
will be
called. If that method succeeds, then this object will be left in the
USABLE
state. If an exception is thrown, then this object will
be left in the BOOTSTRAPPED
state instead.
If initImpl(Map)
throws any exception (even
Error
s), it is wrapped in an InitializationException
and
then the latter is thrown instead.
properties
- the initialization properties, can be null
.IllegalStateException
- if the current state is not BOOTSTRAPPED
or USABLE
.MissingRequiredPropertyException
- if a required property is not given.InvalidPropertyValueException
- if the value of a certain property is invalid.InitializationException
- if the initialization failed for any other reason.protected void initImpl(Map<String,String> properties) throws MissingRequiredPropertyException, InvalidPropertyValueException, InitializationException
init(Map)
, the state and the
argument will have been checked and the state will have been set to
INITIALIZING
.
The implementation of this method in class Manageable
is
empty.
properties
- the initialization properties, not null
.MissingRequiredPropertyException
- if a required property is not given.InvalidPropertyValueException
- if the value of a certain property is invalid.InitializationException
- if the initialization failed, for any other reason.public final void deinit() throws IllegalStateException, DeinitializationException
deinitImpl()
to actually perform the deinitialization.
The current state of this object must be either BOOTSTRAPPED
or USABLE
.
When this method returns, the state has been set to
UNUSABLE
, even if deinitImpl()
threw an exception.
If deinitImpl()
throws any exception, it is wrapped in a
DeinitializationException
and
then the latter is thrown instead.
IllegalStateException
- if the state is not BOOTSTRAPPED
nor USABLE
.DeinitializationException
- if the deinitialization caused an exception in
deinitImpl()
.protected void deinitImpl() throws Throwable
deinit()
each time the latter is called and it
finds that the state is correct. The state will have been set to
DEINITIALIZING
.Throwable
- if the deinitialization caused an exception.public final boolean isBootstrapped()
true
if this object is bootstrapped,
false
if it is not.public final boolean isUsable()
true
if this object is usable,
false
if it is not.protected final void assertUsable() throws IllegalStateException
IllegalStateException
is thrown.IllegalStateException
- if this object is not in the USABLE
state.See http://www.xins.org/.