KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > supervisor > api > BladeState


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2004 France Telecom R&D
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * CLIF $Name: $
20 *
21 * Contact: clif@objectweb.org
22 */

23
24
25 package org.objectweb.clif.supervisor.api;
26
27
28 import java.io.Serializable JavaDoc;
29 import java.util.Collection JavaDoc;
30
31
32 /**
33  * Representation of a blade state
34  * @author Bruno Dillenseger
35  */

36 public class BladeState implements Serializable JavaDoc
37 {
38     static private int instanceCount = 0;
39     static private BladeState[] instances = new BladeState[14];
40     static public final BladeState UNDEPLOYED = new BladeState("undeployed");
41     static public final BladeState DEPLOYING = new BladeState("deploying");
42     static public final BladeState DEPLOYED = new BladeState("deployed");
43     static public final BladeState INITIALIZING = new BladeState("initializing");
44     static public final BladeState INITIALIZED = new BladeState("initialized");
45     static public final BladeState STARTING = new BladeState("starting");
46     static public final BladeState RUNNING = new BladeState("running");
47     static public final BladeState SUSPENDING = new BladeState("suspending");
48     static public final BladeState SUSPENDED = new BladeState("suspended");
49     static public final BladeState RESUMING = new BladeState("resuming");
50     static public final BladeState COMPLETED = new BladeState("completed");
51     static public final BladeState STOPPING = new BladeState("stopping");
52     static public final BladeState STOPPED = new BladeState("stopped");
53     static public final BladeState ABORTED = new BladeState("aborted");
54
55
56     static public BladeState get(int code)
57     {
58         return instances[code];
59     }
60
61
62     static public BladeState getGlobalState(Collection JavaDoc states)
63     {
64         BladeState result = null;
65         // transitional states
66
if (states.contains(BladeState.DEPLOYING))
67         {
68             result = BladeState.DEPLOYING;
69         }
70         else if (states.contains(BladeState.INITIALIZING))
71         {
72             result = BladeState.INITIALIZING;
73         }
74         else if (states.contains(BladeState.STARTING))
75         {
76             result = BladeState.STARTING;
77         }
78         else if (states.contains(BladeState.SUSPENDING))
79         {
80             result = BladeState.SUSPENDING;
81         }
82         else if (states.contains(BladeState.RESUMING))
83         {
84             result = BladeState.RESUMING;
85         }
86         else if (states.contains(BladeState.STOPPING))
87         {
88             result = BladeState.STOPPING;
89         }
90         // stationary states
91
else if (states.contains(BladeState.UNDEPLOYED))
92         {
93             result = BladeState.UNDEPLOYED;
94         }
95         else if (states.contains(BladeState.DEPLOYED))
96         {
97             result = BladeState.DEPLOYED;
98         }
99         else if (states.contains(BladeState.INITIALIZED))
100         {
101             result = BladeState.INITIALIZED;
102         }
103         else if (states.contains(BladeState.RUNNING))
104         {
105             result = BladeState.RUNNING;
106         }
107         else if (states.contains(SUSPENDED))
108         {
109             result = BladeState.SUSPENDED;
110         }
111         else
112         {
113             result = BladeState.STOPPED;
114         }
115         return result;
116     }
117
118
119     int code;
120     transient String JavaDoc label;
121
122
123     protected BladeState(String JavaDoc label)
124     {
125         code = instanceCount;
126         this.label = label;
127         instances[instanceCount++] = this;
128     }
129
130
131     public String JavaDoc toString()
132     {
133         return label;
134     }
135
136
137     public int getCode()
138     {
139         return code;
140     }
141
142
143     public boolean equals(Object JavaDoc obj)
144     {
145         return code == ((BladeState)obj).code;
146     }
147
148
149     private Object JavaDoc readResolve()
150     {
151         return instances[code];
152     }
153 }
154
Popular Tags