package org.jboss.jms.serverless;
import org.jboss.logging.Logger;
public class ConnectionState {
private static final Logger log = Logger.getLogger(ConnectionState.class);
public static final int DISCONNECTED = 0;
public static final int STOPPED = 1;
public static final int STARTED = 2;
public static final int CLOSED = 3;
private int state;
public ConnectionState() {
state = DISCONNECTED;
}
public synchronized boolean isDisconnected() {
return state == DISCONNECTED;
}
public synchronized boolean isStopped() {
return state == STOPPED;
}
public synchronized boolean isStarted() {
return state == STARTED;
}
public synchronized boolean isClosed() {
return state == CLOSED;
}
public synchronized void setStopped() {
state = STOPPED;
}
public synchronized void setStarted() {
state = STARTED;
}
public synchronized void setClosed() {
state = CLOSED;
}
public static String stateToString(ConnectionState cs) {
return
cs.state == DISCONNECTED ? "DISCONNECTED" :
cs.state == STOPPED ? "STOPPED" :
cs.state == STARTED ? "STARTED" :
cs.state == CLOSED ? "CLOSED" : "UNKNOWN";
}
}