KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > system > ServiceMBeanState


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.system;
23
24 import java.util.Arrays JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Set JavaDoc;
27
28 import org.jboss.util.state.State;
29 import org.jboss.util.state.StateMachine;
30 import org.jboss.util.state.Transition;
31
32 /**
33  * A final class that encapsulates the constants necessary
34  * for creating StateMachines that follow the ServiceMBean
35  * lifecycle model.
36  *
37  * @author <a HREF="dimitris@jboss.org">Dimitris Andreadis</a>
38  * @version $Revision: 57108 $
39 **/

40 public final class ServiceMBeanState
41 {
42    // ServiceMBean States
43
public static final State STATE_UNREGISTERED = new State("Unregistered"); // Initial State
44
public static final State STATE_REGISTERED = new State("Registered");
45    public static final State STATE_CREATED = new State("Created");
46    public static final State STATE_STARTING = new State("Starting");
47    public static final State STATE_STARTED = new State("Started");
48    public static final State STATE_STOPPING = new State("Stopping");
49    public static final State STATE_STOPPED = new State("Stopped");
50    public static final State STATE_DESTROYED = new State("Destroyed");
51    public static final State STATE_FAILED = new State("Failed");
52    
53    // ServiceMBean State Transitions
54
public static final Transition TRANS_REGISTER = new Transition("register", STATE_REGISTERED);
55    public static final Transition TRANS_CREATE = new Transition("create", STATE_CREATED);
56    public static final Transition TRANS_START_BEGIN = new Transition("startBegin", STATE_STARTING);
57    public static final Transition TRANS_START_END = new Transition("startEnd", STATE_STARTED);
58    public static final Transition TRANS_STOP_BEGIN = new Transition("stopBegin", STATE_STOPPING);
59    public static final Transition TRANS_STOP_END = new Transition("stopEnd", STATE_STOPPED);
60    public static final Transition TRANS_DESTROY = new Transition("destroy", STATE_DESTROYED);
61    public static final Transition TRANS_UNREGISTER = new Transition("unregister", STATE_UNREGISTERED);
62    public static final Transition TRANS_FAIL = new Transition("fail", STATE_FAILED);
63
64    /** The possible set of States a ServiceMBean can be in */
65    public static final Set JavaDoc STATES = new HashSet JavaDoc(
66       Arrays.asList(new State[] {
67          STATE_UNREGISTERED,
68          STATE_REGISTERED,
69          STATE_CREATED,
70          STATE_STARTING,
71          STATE_STARTED,
72          STATE_STOPPING,
73          STATE_STOPPED,
74          STATE_DESTROYED,
75          STATE_FAILED
76       }));
77    
78    // Associate States with valid Transitions, or else, define explicitly
79
// the ServiceMBean lifecycle that drives the StateMachine
80
static
81    {
82       STATE_UNREGISTERED
83          .addTransition(TRANS_REGISTER)
84          .addTransition(TRANS_FAIL);
85       
86       STATE_REGISTERED
87          .addTransition(TRANS_CREATE)
88          .addTransition(TRANS_UNREGISTER)
89          .addTransition(TRANS_FAIL);
90       
91       STATE_CREATED
92          .addTransition(TRANS_START_BEGIN)
93          .addTransition(TRANS_DESTROY)
94          .addTransition(TRANS_FAIL);
95       
96       STATE_STARTING
97          .addTransition(TRANS_START_END)
98          .addTransition(TRANS_FAIL);
99       
100       STATE_STARTED
101          .addTransition(TRANS_STOP_BEGIN)
102          .addTransition(TRANS_FAIL);
103       
104       STATE_STOPPING
105          .addTransition(TRANS_STOP_END)
106          .addTransition(TRANS_FAIL);
107       
108       STATE_STOPPED
109          .addTransition(TRANS_START_BEGIN)
110          .addTransition(TRANS_DESTROY)
111          .addTransition(TRANS_FAIL);
112       
113       STATE_DESTROYED
114          .addTransition(TRANS_CREATE)
115          .addTransition(TRANS_UNREGISTER)
116          .addTransition(TRANS_FAIL);
117       
118       // STATE_FAILED - no transitions
119
}
120    
121    /**
122     * Create a new StateMachine that follows the ServiceMBean
123     * lifecycle, initialized to the STATE_UNREGISTERED state.
124     *
125     * @param description A string description for this state machine, or null
126     * @return the StateMachine
127     */

128    public static StateMachine createStateMachine(String JavaDoc description)
129    {
130       return new StateMachine(STATES, STATE_UNREGISTERED, description);
131    }
132    
133    /**
134     * Dissallow instances of this class
135     */

136    private ServiceMBeanState()
137    {
138       // empty
139
}
140
141 }
142
Popular Tags