Author: sandakith
Date: Tue Dec  4 20:53:49 2007
New Revision: 10505

Log:

Fix for WSAS-631



Modified:
   trunk/wsas/java/modules/core/src/org/wso2/wsas/Main.java
   trunk/wsas/java/modules/core/src/org/wso2/wsas/MainServlet.java
   trunk/wsas/java/modules/core/src/org/wso2/wsas/util/ServerController.java
   trunk/wsas/java/modules/core/src/org/wso2/wsas/util/WsasUtils.java

Modified: trunk/wsas/java/modules/core/src/org/wso2/wsas/Main.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/Main.java    (original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/Main.java    Tue Dec  4 
20:53:49 2007
@@ -155,7 +155,7 @@
         } else if (cmd.toUpperCase().endsWith(COMMAND_RESTART)) {
             try {
                 ServerController serverController = new ServerController();
-                serverController.setPort(getCommandListenerPort());
+                serverController.setPort(WsasUtils.getCommandListenerPort());
                 serverController.restartServer();
             } catch (Exception e) {
                 String msg = "Cannot restart " + serverName;
@@ -164,7 +164,7 @@
         } else if (cmd.toUpperCase().endsWith(COMMAND_STOP)) {
             try {
                 ServerController serverController = new ServerController();
-                serverController.setPort(getCommandListenerPort());
+                serverController.setPort(WsasUtils.getCommandListenerPort());
                 serverController.shutDownServer();
             } catch (Exception e) {
                 String msg = "Cannot stop " + serverName;
@@ -184,15 +184,6 @@
         }
     }
 
-    private static int getCommandListenerPort() {
-        String port = serverConfig.getFirstProperty("Ports.CommandListener");
-        if(port == null){
-            port = serverConfig.getFirstProperty("CommandListener.Port");
-        }
-        int serverPort =Integer.parseInt(port);
-        return serverPort;
-    }
-
     private static void printUsages() {
         String serverName = serverConfig.getFirstProperty("Name");
         System.out.println("Usage: " + System.getProperty("server.script") + " 
[command]");

Modified: trunk/wsas/java/modules/core/src/org/wso2/wsas/MainServlet.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/MainServlet.java     
(original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/MainServlet.java     Tue Dec 
 4 20:53:49 2007
@@ -28,8 +28,8 @@
 import org.wso2.adminui.AdminUIServletFilter;
 import org.wso2.utils.FileManipulator;
 import org.wso2.utils.ServerConfiguration;
-import org.wso2.utils.ServerException;
 import org.wso2.utils.ServerConfigurationException;
+import org.wso2.utils.ServerException;
 import org.wso2.utils.transport.ProxyCache;
 import org.wso2.wsas.serverinfo.ServerInfo;
 import org.wso2.wsas.transport.ServerPropertyKeys;
@@ -273,7 +273,6 @@
             return;
         }
 
-        final MainServlet main = this;
         shutdownHook = new Thread() {
             public void run() {
                 log.info("Shutting down " + serverName + "...");
@@ -447,12 +446,10 @@
             return;
         }
         serverController = new ServerController(this);
-        String cmdListenerPortStr =
-                
serverConfig.getFirstProperty(ServerConfiguration.COMMAND_LISTENER_PORT);
-        if (cmdListenerPortStr == null) {
+        int cmdListenerPort = WsasUtils.getCommandListenerPort();
+        if(cmdListenerPort == -1){
             return;
         }
-        int cmdListenerPort = Integer.parseInt(cmdListenerPortStr);
         serverController.setPort(cmdListenerPort);
         Thread thread = new Thread(serverController);
         thread.start();

Modified: 
trunk/wsas/java/modules/core/src/org/wso2/wsas/util/ServerController.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/util/ServerController.java   
(original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/util/ServerController.java   
Tue Dec  4 20:53:49 2007
@@ -59,7 +59,7 @@
             serverSocket =
                     new ServerSocket(port, 1, 
InetAddress.getByName(LOCAL_HOST_IP));
         } catch (IOException e) {
-            log.error("Cannot listen on port " + port + ". It is in use.");
+            log.error("Cannot listen on port " + port + ". May be it is in 
use.", e);
             System.exit(1);
         }
         while (true) {
@@ -76,29 +76,21 @@
                 String command = stringBuffer.toString();
                 log.debug("Received Command ==> " + command);
                 if (command.equals(SHUTDOWN_COMMAND)) {
-                    if (controllable.getShutdownHook() != null) {
-                        
Runtime.getRuntime().removeShutdownHook(controllable.getShutdownHook());
-                    }
                     try {
-                        log.info("Shuting down WSO2 WSAS");
-                        controllable.shutdownGracefully();
-                        log.info("Shutdown complete");
-                        log.info("Halting JVM");
-                    } catch (Exception e) {
-                        log.error("Exception while shutting down server");
-                    } finally {
                         // close the socket and exit from the jvm
                         inputStream.close();
                         socket.close();
                         serverSocket.close();
-                        System.exit(0);
+                        controllable.shutdownGracefully();
+                    } catch (Exception e) {
+                        log.error("Exception while shutting down server", e);
                     }
                 } else if (command.equals(RESTART_COMMAND)) {
                     try {
-                        log.info("Restarting WSO2 WSAS");
+                        log.info("Restarting WSO2 WSAS...");
                         controllable.restart();
                     } catch (ServerException e) {
-                        log.error("Exception while restarting the server");
+                        log.error("Exception while restarting the server", e);
                     } finally {
                         // close the socket and exit from the jvm
                         inputStream.close();
@@ -109,9 +101,9 @@
                     log.error("Invalid command : " + command);
                 }
             } catch (IOException e) {
-                e.printStackTrace();
+                
                 // if we cannot start the server then we cannot run the server
-                log.error("Cannot listen on port " + port + ". It is in use.");
+                log.error("Cannot listen on port " + port + ". May be it is in 
use.", e);
                 System.exit(1);
             }
         }

Modified: trunk/wsas/java/modules/core/src/org/wso2/wsas/util/WsasUtils.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/util/WsasUtils.java  
(original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/util/WsasUtils.java  Tue Dec 
 4 20:53:49 2007
@@ -84,7 +84,6 @@
      * Check whther the specified Strin corresponds to a URL
      *
      * @param location The String to be checked
-     *
      * @return true - if <code>location</code> is a URL, false - otherwise
      */
     public static boolean isURL(String location) {
@@ -101,7 +100,6 @@
      * serviceGroup
      *
      * @param serviceGroup The service group whose last updated time we need 
to get
-     *
      * @return The last updated time of the service artifact corresponding to 
AxisServiceGroup
      *         serviceGroup. Will return null if a Axis2 URL repository is in 
use.
      */
@@ -128,4 +126,23 @@
         }
         return lastUpdated;
     }
+
+    /**
+     * Get the port of the command listener. A server socket is opened on this 
port to listen
+     * to incoming commands
+     *
+     * @return The command listener port
+     */
+    public static int getCommandListenerPort() {
+        int serverPort = -1;
+        ServerConfiguration serverConfig = ServerConfiguration.getInstance();
+        String port = serverConfig.getFirstProperty("Ports.CommandListener");
+        if (port == null) {
+            port = serverConfig.getFirstProperty("CommandListener.Port");
+        }
+        if (port != null) {
+            serverPort = Integer.parseInt(port);
+        }
+        return serverPort;
+    }
 }

_______________________________________________
Wsas-java-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/wsas-java-dev

Reply via email to