[Mulgara-svn] r2053 - trunk/src/jar/server/java/org/mulgara/server

pag at mulgara.org pag at mulgara.org
Wed Sep 28 13:40:13 UTC 2011


Author: pag
Date: 2011-09-28 13:40:13 +0000 (Wed, 28 Sep 2011)
New Revision: 2053

Modified:
   trunk/src/jar/server/java/org/mulgara/server/EmbeddedMulgaraServer.java
Log:
Minor cleanups. configureSystemProperties is now final. ShutdownService now uses the correct socket, so it is correctly closed. Logger final. Temporary directory falls back to system temp dir if the default cannot be created. Shutdown port is now reported correctly if falling back to default

Modified: trunk/src/jar/server/java/org/mulgara/server/EmbeddedMulgaraServer.java
===================================================================
--- trunk/src/jar/server/java/org/mulgara/server/EmbeddedMulgaraServer.java	2011-09-28 13:40:01 UTC (rev 2052)
+++ trunk/src/jar/server/java/org/mulgara/server/EmbeddedMulgaraServer.java	2011-09-28 13:40:13 UTC (rev 2053)
@@ -93,7 +93,7 @@
   public final static String SHUTDOWN_MSG = "shutdownmulgara";
 
   /** The logging category to log to. */
-  protected static Logger log = Logger.getLogger(EmbeddedMulgaraServer.class.getName());
+  protected static final Logger log = Logger.getLogger(EmbeddedMulgaraServer.class.getName());
 
   /** The embedded configuration file path */
   protected static String CONFIG_PATH = "conf/mulgara-x-config.xml";
@@ -335,7 +335,7 @@
         if (log.isInfoEnabled()) log.info("Override default shutdown hook port to " + port);
       } catch (NumberFormatException ex) {
         log.error("Unable to convert supplied port " + portString + " to int " +
-            " for shutdown hook. Defaulting to port :" + portString, ex);
+            " for shutdown hook. Defaulting to port :" + port, ex);
       }
     }
 
@@ -637,7 +637,7 @@
       printUsage();
       startServer = false;
     } catch (Exception e) {
-      log.warn("Could not start embedded Mulgara server", e );
+      log.warn("Could not start embedded Mulgara server", e);
       startServer = false;
     }
 
@@ -678,8 +678,11 @@
     if (log.isDebugEnabled()) log.debug("Set config to be: " + mulgaraConfig);
 
     // set the directory that all temporary files will be created in.
-    tempDir.mkdirs();
-    TempDir.setTempDir(tempDir);
+    if (!tempDir.mkdirs()) {
+      tempDir = TempDir.getTempDir();
+    } else {
+      TempDir.setTempDir(tempDir);
+    }
 
     // remove any temporary files 
     cleanUpTemporaryFiles();
@@ -719,7 +722,7 @@
    * Sets up any system properties needed by system components like JNDI and security.
    * @throws IOException if any files embedded within the JAR file cannot be found
    */
-  protected void configureSystemProperties() throws IOException {
+  protected final void configureSystemProperties() throws IOException {
     boolean startedLocalRMIRegistry = false;
 
     // attempt to start a rmiregistry
@@ -733,6 +736,7 @@
       } catch (java.rmi.server.ExportException ex) {
         log.info("Existing RMI registry found on port " + ServerInfo.getRMIPort());
       } catch (Exception ex) {
+
         log.error("Failed to start or detect RMI Registry", ex);
       }
     }
@@ -904,7 +908,7 @@
 
       // bind to the specified socket on the local host
       try {
-        ServerSocket shutdownSocket = new ServerSocket(port, 0, InetAddress.getByName("localhost"));
+        shutdownSocket = new ServerSocket(port, 0, InetAddress.getByName("localhost"));
 
         // wait until a request to stop the server
         while (!stop) {
@@ -915,13 +919,16 @@
           BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
 
           // check if the require request is correct
-          String message = org.mulgara.util.io.IOUtil.readLine(input, EmbeddedMulgaraServer.SHUTDOWN_MSG.length() + 2);
+          String message = null;
+          try {
+            message = org.mulgara.util.io.IOUtil.readLine(input, EmbeddedMulgaraServer.SHUTDOWN_MSG.length() + 2);
+          } finally {
+            socket.close();
+          }
 
           if ((message != null) && message.equals(EmbeddedMulgaraServer.SHUTDOWN_MSG)) {
-            socket.close();
             stop = true;
           } else {
-            socket.close();
             if (message != null) log.error("Incorrect request to shutdown mulgara");
           }
         }



More information about the Mulgara-svn mailing list