Author: azeez
Date: Tue Jan  1 23:51:38 2008
New Revision: 11732

Log:

Show different server statuses via JMX



Added:
   trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerStatus.java
Modified:
   
trunk/wsas/java/modules/admin/src/org/wso2/wsas/admin/service/ServerAdmin.java
   
trunk/wsas/java/modules/admin/src/org/wso2/wsas/admin/service/ServerAdminMBean.java
   trunk/wsas/java/modules/core/src/org/wso2/wsas/MainServlet.java
   trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerConstants.java
   trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerManager.java

Modified: 
trunk/wsas/java/modules/admin/src/org/wso2/wsas/admin/service/ServerAdmin.java
==============================================================================
--- 
trunk/wsas/java/modules/admin/src/org/wso2/wsas/admin/service/ServerAdmin.java  
    (original)
+++ 
trunk/wsas/java/modules/admin/src/org/wso2/wsas/admin/service/ServerAdmin.java  
    Tue Jan  1 23:51:38 2008
@@ -18,7 +18,6 @@
 
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.MessageContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.wso2.utils.AbstractAdmin;
@@ -72,6 +71,10 @@
         }
     }
 
+    public String getServerVersion() {
+        return ServerConfiguration.getInstance().getFirstProperty("Version");
+    }
+
     public ServerStatus getStatus() throws AxisFault {
         ServerStatus serverStatus = new ServerStatus();
         serverStatus.update(getAxisConfig());
@@ -159,6 +162,12 @@
     }
 
     public void startMaintenance() throws Exception {
+        try {
+            org.wso2.wsas.ServerStatus.setServerInMaintenance();
+        } catch (AxisFault e) {
+            String msg = "Cannot set server to maintenance mode";
+            log.error(msg, e);
+        }
         HashMap inTransports = getAxisConfig().getTransportsIn();
         new ServerManagement(inTransports).startMaintenance();
     }
@@ -166,9 +175,25 @@
     public void endMaintenance() throws Exception {
         HashMap inTransports = getAxisConfig().getTransportsIn();
         new ServerManagement(inTransports).endMaintenance();
+        try {
+            org.wso2.wsas.ServerStatus.setServerRunning();
+        } catch (AxisFault e) {
+            String msg = "Cannot set server to running mode";
+            log.error(msg, e);
+        }
     }
 
     public boolean isAlive() {
         return true;
     }
+
+    public String getServerStatus() throws Exception {
+        try {
+            return org.wso2.wsas.ServerStatus.getCurrentStatus();
+        } catch (AxisFault e) {
+            String msg = "Could not get current server status";
+            log.error(msg);
+            throw new Exception(msg, e);
+        }
+    }
 }

Modified: 
trunk/wsas/java/modules/admin/src/org/wso2/wsas/admin/service/ServerAdminMBean.java
==============================================================================
--- 
trunk/wsas/java/modules/admin/src/org/wso2/wsas/admin/service/ServerAdminMBean.java
 (original)
+++ 
trunk/wsas/java/modules/admin/src/org/wso2/wsas/admin/service/ServerAdminMBean.java
 Tue Jan  1 23:51:38 2008
@@ -82,6 +82,12 @@
      */
     String getServerDataAsString() throws Exception;
 
+    /**
+     * Get the version of this WSAS instance
+     *
+     * @return The version of this WSAS instance
+     */
+    String getServerVersion();
 
     /**
      * Method to check whether this WSAS instance is alive
@@ -89,4 +95,17 @@
      * @return True always
      */
     boolean isAlive();
+
+    /**
+     * Get the current status of this WSAS instance
+     *
+     * @return The current server status. <br/>
+     *         Possible values are, <br/>
+     *         [EMAIL PROTECTED] org.wso2.wsas.ServerStatus#RUNNING}, <br/>
+     *         [EMAIL PROTECTED] 
org.wso2.wsas.ServerStatus#SHUTTING_DOWN},<br/>
+     *         [EMAIL PROTECTED] org.wso2.wsas.ServerStatus#RESTARTING},<br/>
+     *         [EMAIL PROTECTED] org.wso2.wsas.ServerStatus#IN_MAINTENANCE} 
<br/>
+     * @see org.wso2.wsas.ServerStatus
+     */
+    String getServerStatus() throws Exception;
 }

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 Jan 
 1 23:51:38 2008
@@ -198,7 +198,7 @@
         serverInfo.process();
         ServerManager.getInstance().setHttpPort(serverInfo.getHttpPort());
         ServerManager.getInstance().setHttpsPort(serverInfo.getHttpsPort());
-        
+
         
WsasUtils.setServletContextProperties(servletConfig.getServletContext(),
                                               (Map) configCtx
                                                       
.getProperty(ServerConstants.GENERATED_PAGES),
@@ -317,6 +317,12 @@
         try {
             init(this.servletConfig);
             reinitializeServlets(this.servletConfig.getServletContext());
+            try {
+                ServerStatus.setServerRunning();
+            } catch (AxisFault e) {
+                String msg = "Cannot set server to running mode";
+                log.error(msg, e);
+            }
         } catch (ServletException e) {
             String msg = "Cannot start server";
             log.fatal(msg, e);
@@ -328,6 +334,12 @@
     }
 
     public void restart() {
+        try {
+            ServerStatus.setServerRestarting();
+        } catch (AxisFault e) {
+            String msg = "Cannot set server to restarting mode";
+            log.error(msg, e);
+        }
         SystemRestarter st = new SystemRestarter(false,
                                                  this,
                                                  this,
@@ -338,6 +350,12 @@
     }
 
     public void restartGracefully() {
+        try {
+            ServerStatus.setServerRestarting();
+        } catch (AxisFault e) {
+            String msg = "Cannot set server to restarting mode";
+            log.error(msg, e);
+        }
         SystemRestarter st = new SystemRestarter(true,
                                                  this,
                                                  this,
@@ -347,12 +365,24 @@
         new Thread(st).start();
     }
 
-    public void shutdown() throws ServerException {
+    public void shutdown() {
+        try {
+            ServerStatus.setServerShuttingDown();
+        } catch (AxisFault e) {
+            String msg = "Cannot set server to shutdown mode";
+            log.error(msg, e);
+        }
         Runtime.getRuntime().removeShutdownHook(shutdownHook);
         System.exit(0);
     }
 
-    public void shutdownGracefully() throws ServerException {
+    public void shutdownGracefully() {
+        try {
+            ServerStatus.setServerShuttingDown();
+        } catch (AxisFault e) {
+            String msg = "Cannot set server to shutdown mode";
+            log.error(msg, e);
+        }
         System.exit(0);
     }
 

Modified: trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerConstants.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerConstants.java 
(original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerConstants.java Tue Jan 
 1 23:51:38 2008
@@ -42,6 +42,7 @@
     public static final String SERVICE_PATH = "services";
 
     public static final String SERVICE_TYPE = "serviceType";
+
     //=============================================
     //          Service Types
     //=============================================

Modified: trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerManager.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerManager.java   
(original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerManager.java   Tue Jan 
 1 23:51:38 2008
@@ -126,6 +126,12 @@
 
             runIntializers();
 
+            try {
+                ServerStatus.setServerRunning();
+            } catch (AxisFault e) {
+                String msg = "Cannot set server to running mode";
+                log.error(msg, e);
+            }
         } catch (Exception e) {
             String msg = "Cannot start WSO2 WSAS";
             log.fatal(msg, e);
@@ -196,7 +202,7 @@
             if (configContext != null) {
                 configContext.terminate();
             }
-        } catch (Exception e) { 
+        } catch (Exception e) {
             log.error("Exception occurred while shutting down listeners", e);
         }
     }

Added: trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerStatus.java
==============================================================================
--- (empty file)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerStatus.java    Tue Jan 
 1 23:51:38 2008
@@ -0,0 +1,120 @@
+/*                                                                             
+ * Copyright 2004,2005 The Apache Software Foundation.                         
+ *                                                                             
+ * Licensed under the Apache License, Version 2.0 (the "License");             
+ * you may not use this file except in compliance with the License.            
+ * You may obtain a copy of the License at                                     
+ *                                                                             
+ *      http://www.apache.org/licenses/LICENSE-2.0                             
+ *                                                                             
+ * Unless required by applicable law or agreed to in writing, software         
+ * distributed under the License is distributed on an "AS IS" BASIS,           
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    
+ * See the License for the specific language governing permissions and         
+ * limitations under the License.                                              
+ */
+package org.wso2.wsas;
+
+import org.wso2.utils.ServerConfigurator;
+import org.wso2.utils.WSO2ConfigurationContextFactory;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.AxisFault;
+
+/**
+ * The status in which this WSAS instance can currently be in
+ */
+public final class ServerStatus {
+    /**
+     * Server is running
+     */
+    private static final String STATUS_RUNNING = "RUNNING";
+
+    /**
+     * Server has switched to maintenace mode
+     */
+    private static final String STATUS_IN_MAINTENANCE = "IN_MAINTENANCE";
+
+    /**
+     * Server is restarting
+     */
+    private static final String STATUS_RESTARTING = "RESTARTING";
+
+    /**
+     * Server is shutting down
+     */
+    private static final String STATUS_SHUTTING_DOWN = "SHUTTING_DOWN";
+
+    /**
+     * The current status of this WSAS instance
+     */
+    private static final String CURRENT_SERVER_STATUS = 
"current.server.status";
+
+    private ServerStatus() {
+    }
+
+    /**
+     * Get the current server status
+     *
+     * @return The current server status
+     * @throws AxisFault If an error occurs while getting the 
ConfigurationContext
+     */
+    public static String getCurrentStatus() throws AxisFault {
+        ConfigurationContext configCtx =
+                WSO2ConfigurationContextFactory.
+                        
getConfigurationContext(ServerConfigurator.getInstance());
+        String currentStatus = (String) 
configCtx.getProperty(CURRENT_SERVER_STATUS);
+        if (currentStatus == null) {
+            configCtx.setProperty(CURRENT_SERVER_STATUS, STATUS_RUNNING);
+            return STATUS_RUNNING;
+        }
+        return currentStatus;
+    }
+
+    /**
+     * Set server to running mode
+     *
+     * @throws AxisFault If an error occurs while getting the 
ConfigurationContext
+     */
+    public static void setServerRunning() throws AxisFault {
+        ConfigurationContext configCtx =
+                WSO2ConfigurationContextFactory.
+                        
getConfigurationContext(ServerConfigurator.getInstance());
+        configCtx.setProperty(CURRENT_SERVER_STATUS, STATUS_RUNNING);
+    }
+
+    /**
+     * Set server to shutting-down mode
+     *
+     * @throws AxisFault If an error occurs while getting the 
ConfigurationContext
+     */
+    public static void setServerShuttingDown() throws AxisFault {
+        ConfigurationContext configCtx =
+                WSO2ConfigurationContextFactory.
+                        
getConfigurationContext(ServerConfigurator.getInstance());
+        configCtx.setProperty(CURRENT_SERVER_STATUS, STATUS_SHUTTING_DOWN);
+    }
+
+    /**
+     * Set server to restarting-down mode
+     *
+     * @throws AxisFault If an error occurs while getting the 
ConfigurationContext
+     */
+    public static void setServerRestarting() throws AxisFault {
+        ConfigurationContext configCtx =
+                WSO2ConfigurationContextFactory.
+                        
getConfigurationContext(ServerConfigurator.getInstance());
+        configCtx.setProperty(CURRENT_SERVER_STATUS, STATUS_RESTARTING);
+    }
+
+    /**
+     * Set server to maintenace mode
+     *
+     * @throws AxisFault If an error occurs while getting the 
ConfigurationContext
+     */
+    public static void setServerInMaintenance() throws AxisFault {
+        ConfigurationContext configCtx =
+                WSO2ConfigurationContextFactory.
+                        
getConfigurationContext(ServerConfigurator.getInstance());
+        configCtx.setProperty(CURRENT_SERVER_STATUS, STATUS_IN_MAINTENANCE);
+    }
+}

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

Reply via email to