Author: channa
Date: Wed Jan  2 21:47:14 2008
New Revision: 11780

Log:

Added ability to accept home directories of monitored servers as string 
arguments in monitor invocation. Helps resolve JIRA related to disabled 'Start' 
menu option.

Modified:
   
trunk/commons/monitor/modules/client/src/main/java/org/wso2/monitor/InstanceMonitor.java
   
trunk/commons/monitor/modules/client/src/main/java/org/wso2/monitor/ServiceMonitor.java

Modified: 
trunk/commons/monitor/modules/client/src/main/java/org/wso2/monitor/InstanceMonitor.java
==============================================================================
--- 
trunk/commons/monitor/modules/client/src/main/java/org/wso2/monitor/InstanceMonitor.java
    (original)
+++ 
trunk/commons/monitor/modules/client/src/main/java/org/wso2/monitor/InstanceMonitor.java
    Wed Jan  2 21:47:14 2008
@@ -46,6 +46,7 @@
     private MessageDisplay display;
     private int connectionRetries;
     private int retryCount;
+    private String serverHome;
 
     /**
      * Constructor, instantiates JMX Client and menu and initializes the 
polling process
@@ -53,8 +54,10 @@
      *
      * @param display        Instance of the message display implementation 
object.
      * @param instanceNumber Instance number of the server being monitored.
+     * @param serverHome Home directory of monitored server.
      */
-    public InstanceMonitor(MessageDisplay display, int instanceNumber) {
+    public InstanceMonitor(MessageDisplay display, int instanceNumber, String 
serverHome) {
+        this.serverHome = serverHome;
         this.display = display;
         this.instanceNumber = instanceNumber;
         serviceName = getProperty(".name");
@@ -268,8 +271,7 @@
      */
     private boolean isServiceLocal() {
         boolean found;
-        String wrapperPath = getProperty(".bin");
-        File wrapperBinary = new File(wrapperPath);
+        File wrapperBinary = new File(getWrapperPath());
         log.debug("Checking for wrapper binary at:" + 
wrapperBinary.getAbsolutePath());
         found = wrapperBinary.exists();
         log.debug("Binary found =" + found);
@@ -277,6 +279,24 @@
     }
 
     /**
+     * Provides the path to the monitored service, relative or absolute based 
on whether the server
+     * home directory has been provided.
+     * 
+     * @return String path.
+     */
+    private String getWrapperPath() {
+        String wrapperPath = getProperty(".bin");
+
+        // If monitored server's home directory is known, use that instead of 
relative path.
+        if (serverHome != null && wrapperPath.startsWith("..")) {
+            log.debug("Initially serverHome:" + serverHome + " and path:" + 
wrapperPath);
+            wrapperPath = serverHome.concat(wrapperPath.substring(2));
+        }
+
+        return wrapperPath;
+    }
+
+    /**
      * Start an instance of the server to be monitored.
      */
     private void startServer() {
@@ -286,7 +306,7 @@
         try {
             Runtime runtime = Runtime.getRuntime();
             String[] command = new String[3];
-            command[0] = getProperty(".bin");
+            command[0] = getWrapperPath();
 
             // Setup the start argument based on operating system, defaulting 
to the command line.
             String osName = System.getProperty("os.name");

Modified: 
trunk/commons/monitor/modules/client/src/main/java/org/wso2/monitor/ServiceMonitor.java
==============================================================================
--- 
trunk/commons/monitor/modules/client/src/main/java/org/wso2/monitor/ServiceMonitor.java
     (original)
+++ 
trunk/commons/monitor/modules/client/src/main/java/org/wso2/monitor/ServiceMonitor.java
     Wed Jan  2 21:47:14 2008
@@ -37,6 +37,7 @@
     JPopupMenu monitorMenu;
     JMenuItem quitMenuItem;
     HashMap monitoredInstances;
+    String[] serverHomes;
 
     /**
      * Constructor, calls base class constructor.
@@ -91,11 +92,22 @@
     public static void main(String[] args) {
         ServiceMonitor serviceMonitor = new ServiceMonitor();
 
-        // Start is default, stop if specified.
-        if (args.length == 0 || 
args[0].equalsIgnoreCase(MonitorConstants.COMMAND_START)) {
+        // If no arguments have been provided, assume start.
+        if (args.length == 0) {
             serviceMonitor.init();
-        } else if (args[0].equalsIgnoreCase(MonitorConstants.COMMAND_STOP)) {
-            serviceMonitor.shutDown();
+        } else {
+            // If arguments have been provided, first is either start or stop.
+            if (args[0].equalsIgnoreCase(MonitorConstants.COMMAND_STOP)) {
+                serviceMonitor.shutDown();
+            } else {
+                // Anything after that would be the home directories of 
monitored servers.
+                if (args.length > 1) {
+                    String[] serverLocations = new String[args.length - 1];
+                    System.arraycopy(args, 1, serverLocations, 0, 
serverLocations.length);
+                    serviceMonitor.setServerHomes(serverLocations);
+                }
+                serviceMonitor.init();
+            }
         }
     }
 
@@ -122,12 +134,21 @@
      */
     private void buildMenu() {
         int instanceNumber = 0;
+        String instanceHome = null;
 
         // Add a menu for each configured server instance.
         String instanceName = monitorProperties.getProperty("monitor.service." 
+ instanceNumber +
                 ".name");
         while (instanceName != null) {
-            InstanceMonitor instanceMonitor = new InstanceMonitor(this, 
instanceNumber);
+            // If server home directories have been specified at startup, use 
them.
+            if (serverHomes != null && serverHomes.length > instanceNumber) {
+                log.debug("Home for instance " + instanceNumber + " is " + 
serverHomes[
+                        instanceNumber]);
+                instanceHome = serverHomes[instanceNumber];
+            }
+
+            InstanceMonitor instanceMonitor = new InstanceMonitor(this, 
instanceNumber,
+                                                                  
instanceHome);
             monitoredInstances.put(instanceName, instanceMonitor);
             monitorMenu.add(instanceMonitor.getInstanceMenu());
             instanceNumber++;
@@ -206,4 +227,12 @@
             System.exit(0);
         }
     }
+
+    /**
+     * Assign server home directory array.
+     * @param serverHomes String array of server home directories.
+     */
+    public void setServerHomes(String[] serverHomes) {
+        this.serverHomes = serverHomes;
+    }
 }
\ No newline at end of file

_______________________________________________
Commons-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/commons-dev

Reply via email to