[Mulgara-svn] r1111 - in trunk/src/jar: server/java/org/mulgara/server server-rmi/java/org/mulgara/server/rmi
pag at mulgara.org
pag at mulgara.org
Mon Jul 28 22:56:12 UTC 2008
Author: pag
Date: 2008-07-28 15:56:11 -0700 (Mon, 28 Jul 2008)
New Revision: 1111
Modified:
trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RmiServer.java
trunk/src/jar/server/java/org/mulgara/server/AbstractServer.java
trunk/src/jar/server/java/org/mulgara/server/ServerMBean.java
Log:
Changed server state to an enumeration
Modified: trunk/src/jar/server/java/org/mulgara/server/AbstractServer.java
===================================================================
--- trunk/src/jar/server/java/org/mulgara/server/AbstractServer.java 2008-07-28 22:51:23 UTC (rev 1110)
+++ trunk/src/jar/server/java/org/mulgara/server/AbstractServer.java 2008-07-28 22:56:11 UTC (rev 1111)
@@ -85,7 +85,7 @@
protected String hostname = null;
/** State. */
- private int state = UNINITIALIZED;
+ private ServerState state = ServerState.UNINITIALIZED;
/** The server object. */
private SessionFactory sessionFactory;
@@ -110,7 +110,7 @@
*/
public void setPortNumber(int newPortNumber) {
// Prevent the port from being changed while the server is up
- if (this.getState() == STARTED) {
+ if (getState() == ServerState.STARTED) {
throw new IllegalStateException("Can't change server port without first stopping the server");
}
portNumber = newPortNumber;
@@ -129,11 +129,11 @@
/**
* Sets the hostname of the server.
* @param newHostname the hostname of the server, if <code>null</code> <code>localhost</code> will be used
- * @throws IllegalStateException if the service is started or if the underlying session factory already has a fixed hostname
+ * @throws IllegalStateException if the service is STARTED or if the underlying session factory already has a fixed hostname
*/
public void setHostname(String newHostname) {
// Prevent the hostname from being changed while the server is up
- if (this.getState() == STARTED) {
+ if (this.getState() == ServerState.STARTED) {
throw new IllegalStateException("Can't change hostname without first stopping the server");
}
@@ -180,7 +180,7 @@
* Read the server state.
* @return The current server state.
*/
- public int getState() {
+ public ServerState getState() {
return state;
}
@@ -278,7 +278,7 @@
.newInstance(new Object[] {getURI(), dir, sessionConfig});
}
- state = STOPPED;
+ state = ServerState.STOPPED;
// Log successful creation
if (logger.isInfoEnabled()) logger.info("Created server");
@@ -295,17 +295,12 @@
logger.info("Starting");
// Validate state
- switch (state) {
+ if (state == ServerState.UNINITIALIZED) throw new IllegalStateException("Not initialized");
- case UNINITIALIZED:
- throw new IllegalStateException("Not initialized");
+ if (state == ServerState.STARTED) throw new IllegalStateException("Already STARTED");
- case STARTED:
- throw new IllegalStateException("Already started");
- }
+ assert state == ServerState.STOPPED;
- assert state == STOPPED;
-
// Invariant tests for the STOPPED state
if (sessionFactory == null) throw new AssertionError("Null \"sessionFactory\" parameter");
@@ -334,7 +329,7 @@
// }
// }
- state = STARTED;
+ state = ServerState.STARTED;
logger.info("Started");
}
@@ -349,14 +344,14 @@
logger.info("Shutting down");
// Validate state
- if (state != STARTED) throw new IllegalStateException("Server is not started");
+ if (state != ServerState.STARTED) throw new IllegalStateException("Server is not STARTED");
// if (jmdns != null) {
// logger.info("Unregistering from ZeroConf server");
// jmdns.unregisterAllServices();
// }
stopService();
- state = STOPPED;
+ state = ServerState.STOPPED;
logger.info("Shut down");
}
@@ -376,7 +371,7 @@
// jmdns.unregisterAllServices();
// }
sessionFactory = null;
- state = UNINITIALIZED;
+ state = ServerState.UNINITIALIZED;
logger.info("Destroyed");
}
@@ -385,12 +380,12 @@
* from other properties and call this method whenever those properties are
* modified.
* @param uri the desired server URI, or <code>null</code>
- * @throws IllegalStateException if the service is started or if the
+ * @throws IllegalStateException if the service is STARTED or if the
* underlying session factory already has a fixed URI
*/
protected void setURI(URI uri) {
// Prevent the URI from being changed while the server is up
- if (state == STARTED) throw new IllegalStateException("Can't change URI without first stopping the server");
+ if (state == ServerState.STARTED) throw new IllegalStateException("Can't change URI without first stopping the server");
this.uri = uri;
}
Modified: trunk/src/jar/server/java/org/mulgara/server/ServerMBean.java
===================================================================
--- trunk/src/jar/server/java/org/mulgara/server/ServerMBean.java 2008-07-28 22:51:23 UTC (rev 1110)
+++ trunk/src/jar/server/java/org/mulgara/server/ServerMBean.java 2008-07-28 22:56:11 UTC (rev 1111)
@@ -60,32 +60,34 @@
// MBean states
//
- /**
- * Value of the <var>state</var> MBean property indicating that the server has
- * not been created. This is the initial state when the MBean is created, and
- * is also the result of calling the {@link #destroy} action from the {@link
- * #STOPPED} state. The {@link #init} action can be used to transition from
- * this state to the {@link #STOPPED} state.
- */
- public final int UNINITIALIZED = 1;
+ public enum ServerState {
+ /**
+ * Value of the <var>state</var> MBean property indicating that the server has
+ * not been created. This is the initial state when the MBean is created, and
+ * is also the result of calling the {@link #destroy} action from the {@link
+ * #STOPPED} state. The {@link #init} action can be used to transition from
+ * this state to the {@link #STOPPED} state.
+ */
+ UNINITIALIZED,
- /**
- * Value of the <var>state</var> MBean property indicating that the server has
- * been created, but is not accepting client requests from the network. This
- * state is entered from the {@link #UNINITIALIZED} state via the {@link
- * #init} action. The {@link #start} action can be used to transition from
- * this state to the {@link #STARTED} state.
- */
- public final int STOPPED = 2;
+ /**
+ * Value of the <var>state</var> MBean property indicating that the server has
+ * been created, but is not accepting client requests from the network. This
+ * state is entered from the {@link #UNINITIALIZED} state via the {@link
+ * #init} action. The {@link #start} action can be used to transition from
+ * this state to the {@link #STARTED} state.
+ */
+ STOPPED,
- /**
- * Value of the <var>state</var> MBean property indicating that the server is
- * accepting client requests from the network. This state is entered from the
- * {@link #STOPPED} state via the {@link #start} action. The {@link #stop}
- * action can be used to transition from this state to the {@link #STOPPED}
- * state.
- */
- public final int STARTED = 3;
+ /**
+ * Value of the <var>state</var> MBean property indicating that the server is
+ * accepting client requests from the network. This state is entered from the
+ * {@link #STOPPED} state via the {@link #start} action. The {@link #stop}
+ * action can be used to transition from this state to the {@link #STOPPED}
+ * state.
+ */
+ STARTED
+ };
//
// MBean actions
@@ -131,7 +133,7 @@
* @return The current server state, always one of the values {@link
* #UNINITIALIZED}, {@link #STOPPED} or {@link #STARTED}
*/
- public int getState();
+ public ServerState getState();
/**
* Read the database persistence directory.
Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RmiServer.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RmiServer.java 2008-07-28 22:51:23 UTC (rev 1110)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RmiServer.java 2008-07-28 22:56:11 UTC (rev 1111)
@@ -98,7 +98,7 @@
*/
public void setName(String name) {
// Prevent the name from being changed while the server is up
- if (this.getState() == STARTED) {
+ if (this.getState() == ServerState.STARTED) {
throw new IllegalStateException("Can't change name without first stopping the server");
}
@@ -115,7 +115,7 @@
*/
public void setHostname(String hostname) {
// Prevent the hostname from being changed while the server is up
- if (this.getState() == STARTED) {
+ if (this.getState() == ServerState.STARTED) {
throw new IllegalStateException("Can't change hostname without first stopping the server");
}
More information about the Mulgara-svn
mailing list