⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servicestate.java

📁 jainslee1.0 源代码
💻 JAVA
字号:
package javax.slee.management;import java.io.Serializable;import java.io.StreamCorruptedException;/** * This class defines an enumerated type that encapsulates the state of a Service. * <p> * A singleton instance of each enumerated value is guaranteed (via an implementation * of <code>readResolve()</code> - refer {@link java.io.Serializable java.io.Serializable}), * so that equality tests using <code>==</code> 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.) */public final class ServiceState implements Serializable {    /**     * An integer representation of the {@link #INACTIVE} state.     */    public static final int SERVICE_INACTIVE = 0 ;    /**     * An integer representation of the {@link #ACTIVE} state.     */    public static final int SERVICE_ACTIVE = 1;    /**     * An integer representation of the {@link #STOPPING} state.     */    public static final int SERVICE_STOPPING = 2;    /**     * The INACTIVE state indicates that the Service has been successfully     * installed.  All required files and parameters have been set up, so that the     * Service may be activated, but it is currently not running.  (This means that     * instances of the Service are not consuming memory or CPU resources.)     */    public static final ServiceState INACTIVE = new ServiceState(SERVICE_INACTIVE);    /**     * The ACTIVE state indicates that the Service has been activated.  In     * this state, instances of the Service are created by the SLEE's event routing     * subsystem in response to initial events, and the Service instances are invoked     * to respond to events.     */    public static final ServiceState ACTIVE = new ServiceState(SERVICE_ACTIVE);    /**     * The STOPPING state indicates that an active Service has been deactivated,     * but some instances of the Service are still running.  Once all Service instances     * have finished running, the Service state spontaneously returns to the     * INACTIVE state.     */    public static final ServiceState STOPPING = new ServiceState(SERVICE_STOPPING);    /**     * Get a <code>ServiceState</code> object from an integer value.     * @param state the state as an integer.     * @return a <code>ServiceState</code> object corresponding to <code>state</code>.     * @throws IllegalArgumentException if <code>state</code> is not a valid     *        state value.     */    public static ServiceState fromInt(int state) throws IllegalArgumentException {        switch (state) {            case SERVICE_INACTIVE: return INACTIVE;            case SERVICE_ACTIVE: return ACTIVE;            case SERVICE_STOPPING: return STOPPING;            default: throw new IllegalArgumentException("Invalid state: " + state);        }    }    /**     * Get an integer value representation for this <code>ServiceState</code> object.     * @return an integer value representation for this <code>ServiceState</code> object.     */    public int toInt() {        return state;    }    /**     * Determine if this ServiceState object represents the INACTIVE state of a Service.     * <p>     * This method is effectively equivalent to the conditional test:     * <code>(this == INACTIVE)</code>, ie. the code:     * <p>     * <code>&nbsp;&nbsp;&nbsp;&nbsp;if (state.isInactive()) ...</code>     * <p>     * is interchangeable with the code:     * <p>     * <code>&nbsp;&nbsp;&nbsp;if (state == ServiceState.INACTIVE) ...</code>     * <p>     * @return <code>true</code> if this object represents the INACTIVE state of a Service,     *       <code>false</code> otherwise.     */    public boolean isInactive() {        return state == SERVICE_INACTIVE;    }    /**     * Determine if this ServiceState object represents the ACTIVE state of a Service.     * <p>     * This method is effectively equivalent to the conditional test:     * <code>(this == ACTIVE)</code>, ie. the code:     * <p>     * <code>&nbsp;&nbsp;&nbsp;&nbsp;if (state.isActive()) ...</code>     * <p>     * is interchangeable with the code:     * <p>     * <code>&nbsp;&nbsp;&nbsp;if (state == ServiceState.ACTIVE) ...</code>     * <p>     * @return <code>true</code> if this object represents the ACTIVE state of a Service,     *       <code>false</code> otherwise.     */    public boolean isActive() {        return state == SERVICE_ACTIVE;    }    /**     * Determine if this ServiceState object represents the STOPPING state of a Service.     * <p>     * This method is effectively equivalent to the conditional test:     * <code>(this == STOPPING)</code>, ie. the code:     * <p>     * <code>&nbsp;&nbsp;&nbsp;&nbsp;if (state.isStopping()) ...</code>     * <p>     * is interchangeable with the code:     * <p>     * <code>&nbsp;&nbsp;&nbsp;if (state == ServiceState.STOPPING) ...</code>     * <p>     * @return <code>true</code> if this object represents the STOPPING state of a Service,     *       <code>false</code> otherwise.     */    public boolean isStopping() {        return state == SERVICE_STOPPING;    }    /**     * Compare this Service state for equality with another.     * @param obj the object to compare this with.     * @return <code>true</code> if <code>obj</code> is an instance of this class     *        representing the same Service state as this, <code>false</code> otherwise.     */    public boolean equals(Object obj) {        if (obj == this) return true;        return (obj instanceof ServiceState) && ((ServiceState)obj).state == state;    }    /**     * Get a hash code value for this Service state.     * @return a hash code value.     */    public int hashCode() {        return state;    }    /**     * Get the textual representation of this Service state object.     * @return the textual representation of this Service state object.     */    public String toString() {        switch (state) {            case SERVICE_INACTIVE: return "Service Inactive";            case SERVICE_ACTIVE: return "Service Active";            case SERVICE_STOPPING: return "Service Stopping";            default: return "Service in Unknown and Invalid State";        }    }    /**     * Private constructor to prevent unauthorised object creation.     */    private ServiceState(int state) {        this.state = state;    }    /**     * Resolve deserialisation references so that the singleton property of each     * enumerated object is preserved.     */    private Object readResolve() throws StreamCorruptedException {        if (state == SERVICE_INACTIVE) return INACTIVE;        if (state == SERVICE_ACTIVE) return ACTIVE;        if (state == SERVICE_STOPPING) return STOPPING;        throw new StreamCorruptedException("Invalid internal state found");    }    /**     * The internal state representation of the enumerated type.     */    private final int state;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -