KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > serverless > ConnectionState


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.jms.serverless;
8
9 import org.jboss.logging.Logger;
10
11 /**
12  * An object that holds the current state of a connection. The state could be one, and only one of
13  * DISCONNECTED, STOPPED, STARTED, CLOSED. The instance's lock is used during the operations that
14  * change the connection state.
15  *
16  * @author Ovidiu Feodorov <ovidiu@jboss.org>
17  * @version $Revision: 1.1 $ $Date: 2004/04/15 22:54:19 $
18  *
19  **/

20 public class ConnectionState {
21
22     private static final Logger log = Logger.getLogger(ConnectionState.class);
23
24     public static final int DISCONNECTED = 0;
25     public static final int STOPPED = 1;
26     public static final int STARTED = 2;
27     public static final int CLOSED = 3;
28
29     private int state;
30
31     public ConnectionState() {
32         state = DISCONNECTED;
33     }
34
35     public synchronized boolean isDisconnected() {
36         return state == DISCONNECTED;
37     }
38
39     public synchronized boolean isStopped() {
40         return state == STOPPED;
41     }
42
43     public synchronized boolean isStarted() {
44         return state == STARTED;
45     }
46
47     public synchronized boolean isClosed() {
48         return state == CLOSED;
49     }
50
51     // No state consistency check is performed at this level. State changing methods should do
52
// that and throw apropriate exceptions.
53

54     public synchronized void setStopped() {
55         state = STOPPED;
56     }
57
58     public synchronized void setStarted() {
59         state = STARTED;
60     }
61
62     public synchronized void setClosed() {
63         state = CLOSED;
64     }
65
66     public static String JavaDoc stateToString(ConnectionState cs) {
67         return
68             cs.state == DISCONNECTED ? "DISCONNECTED" :
69             cs.state == STOPPED ? "STOPPED" :
70             cs.state == STARTED ? "STARTED" :
71             cs.state == CLOSED ? "CLOSED" : "UNKNOWN";
72     }
73    
74
75 }
76
Popular Tags