javax.slee.management.ResourceAdaptorEntityState Maven / Gradle / Ivy
package javax.slee.management;
import java.io.Serializable;
import java.io.StreamCorruptedException;
/**
* This class defines an enumerated type that encapsulates the state of a Resource Adaptor Entity.
*
* A singleton instance of each enumerated value is guaranteed (via an implementation
* of readResolve()
- refer {@link java.io.Serializable java.io.Serializable}),
* so that equality tests using ==
are always evaluated correctly. (This
* equality test is only guaranteed if this class is loaded in the application's boot class
* path, rather than dynamically loaded at runtime.)
* @since SLEE 1.1
*/
public final class ResourceAdaptorEntityState implements Serializable {
/**
* An integer representation of the {@link #INACTIVE} state.
*/
public static final int ENTITY_INACTIVE = 0;
/**
* An integer representation of the {@link #ACTIVE} state.
*/
public static final int ENTITY_ACTIVE = 1;
/**
* An integer representation of the {@link #STOPPING} state.
*/
public static final int ENTITY_STOPPING = 2;
/**
* A string representation of the {@link #INACTIVE} state.
*/
public static final String INACTIVE_STRING = "Inactive";
/**
* A string representation of the {@link #ACTIVE} state.
*/
public static final String ACTIVE_STRING = "Active";
/**
* A string representation of the {@link #STOPPING} state.
*/
public static final String STOPPING_STRING = "Stopping";
/**
* The INACTIVE state indicates that the resource adaptor entity has been successfully
* created and configured. All required files and parameters have been set up, so that
* the resource adaptor entity may be connected to the underlying resource, but it is
* not currently producing events.
*/
public static final ResourceAdaptorEntityState INACTIVE = new ResourceAdaptorEntityState(ENTITY_INACTIVE);
/**
* The ACTIVE state indicates that the resource adaptor entity has been activated and
* it is able to deliver events from the underlying resource to the SLEE.
*/
public static final ResourceAdaptorEntityState ACTIVE = new ResourceAdaptorEntityState(ENTITY_ACTIVE);
/**
* The STOPPING state indicates that an active resource adaptor entity has been
* deactivated but some activities created by the resource adaptor entity still exist.
* Once all activities have completed, the resource adaptor entity state spontaneously
* returns to the INACTIVE state.
*/
public static final ResourceAdaptorEntityState STOPPING = new ResourceAdaptorEntityState(ENTITY_STOPPING);
/**
* Get a ResourceAdaptorEntityState
object from an integer value.
* @param state the state as an integer.
* @return a ResourceAdaptorEntityState
object corresponding to state
.
* @throws IllegalArgumentException if state
is not a valid resource
* adaptor entity state value.
*/
public static ResourceAdaptorEntityState fromInt(int state) throws IllegalArgumentException {
switch (state) {
case ENTITY_INACTIVE: return INACTIVE;
case ENTITY_ACTIVE: return ACTIVE;
case ENTITY_STOPPING: return STOPPING;
default: throw new IllegalArgumentException("Invalid state: " + state);
}
}
/**
* Get a ResourceAdaptorEntityState
object from a string value.
* @param state the state as a string, for example as returned by the {@link #toString()}
* method (case insensitive).
* @return a ResourceAdaptorEntityState
object corresponding to state
.
* @throws NullPointerException if state
is null
.
* @throws IllegalArgumentException if state
is not a valid resource
* adaptor entity state string.
*/
public static ResourceAdaptorEntityState fromString(String state) throws NullPointerException, IllegalArgumentException {
if (state == null) throw new NullPointerException("state is null");
if (state.equalsIgnoreCase(INACTIVE_STRING)) return INACTIVE;
if (state.equalsIgnoreCase(ACTIVE_STRING)) return ACTIVE;
if (state.equalsIgnoreCase(STOPPING_STRING)) return STOPPING;
throw new IllegalArgumentException("Invalid state: " + state);
}
/**
* Get an integer value representation for this ResourceAdaptorEntityState
object.
* @return an integer value representation for this ResourceAdaptorEntityState
object.
*/
public int toInt() {
return state;
}
/**
* Determine if this ResourceAdaptorEntityState object represents the INACTIVE state of
* a resource adaptor entity.
*
* This method is effectively equivalent to the conditional test:
* (this == INACTIVE)
, ie. the code:
*
* if (state.isInactive()) ...
*
* is interchangeable with the code:
*
* if (state == ResourceAdaptorEntityState.INACTIVE) ...
*
* @return true
if this object represents the INACTIVE state of a resource
* adaptor entity, false
otherwise.
*/
public boolean isInactive() {
return state == ENTITY_INACTIVE;
}
/**
* Determine if this ResourceAdaptorEntityState object represents the ACTIVE state of
* a resource adaptor entity.
*
* This method is effectively equivalent to the conditional test:
* (this == ACTIVE)
, ie. the code:
*
* if (state.isActive()) ...
*
* is interchangeable with the code:
*
* if (state == ResourceAdaptorEntityState.ACTIVE) ...
*
* @return true
if this object represents the ACTIVE state of a resource
* adaptor entity, false
otherwise.
*/
public boolean isActive() {
return state == ENTITY_ACTIVE;
}
/**
* Determine if this ResourceAdaptorEntityState object represents the STOPPING state of
* a resource adaptor entity.
*
* This method is effectively equivalent to the conditional test:
* (this == STOPPING)
, ie. the code:
*
* if (state.isStopping()) ...
*
* is interchangeable with the code:
*
* if (state == ResourceAdaptorEntityState.STOPPING) ...
*
* @return true
if this object represents the STOPPING state of a
* resource adaptor entity, false
otherwise.
*/
public boolean isStopping() {
return state == ENTITY_STOPPING;
}
/**
* Compare this resource adaptor state for equality with another.
* @param obj the object to compare this with.
* @return true
if obj
is an instance of this class
* representing the same resource adaptor state as this, false
* otherwise.
*/
public boolean equals(Object obj) {
if (obj == this) return true;
return (obj instanceof ResourceAdaptorEntityState)
&& ((ResourceAdaptorEntityState)obj).state == state;
}
/**
* Get a hash code value for this resource adaptor state.
* @return a hash code value.
*/
public int hashCode() {
return state;
}
/**
* Get the textual representation of the ResourceAdaptorEntityState object.
* @return the textual representation of the ResourceAdaptorEntityState object.
*/
public String toString() {
switch (state) {
case ENTITY_INACTIVE: return INACTIVE_STRING;
case ENTITY_ACTIVE: return ACTIVE_STRING;
case ENTITY_STOPPING: return STOPPING_STRING;
default: return "ResourceAdaptorEntityState in Unknown and Invalid State";
}
}
/**
* Private constructor to prevent unauthorized object creation.
*/
private ResourceAdaptorEntityState(int state) {
this.state = state;
}
/**
* Resolve deserialisation references so that the singleton property of each
* enumerated object is preserved.
*/
private Object readResolve() throws StreamCorruptedException {
try {
return fromInt(state);
}
catch (IllegalArgumentException iae) {
throw new StreamCorruptedException("Invalid internal state found");
}
}
/**
* The internal state representation of the enumerated type.
*/
private final int state;
}