geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r395784 - in /geronimo/branches/1.1/modules: kernel/src/java/org/apache/geronimo/gbean/ system/src/java/org/apache/geronimo/system/jmx/ system/src/java/org/apache/geronimo/system/main/
Date Fri, 21 Apr 2006 05:30:08 GMT
Author: dain
Date: Thu Apr 20 22:30:06 2006
New Revision: 395784

URL: http://svn.apache.org/viewcvs?rev=395784&view=rev
Log:
Removed use of ObjectName from StartupMonitors.
Consolidate wrapUp method in progress bar and long monitors into a util class.
Fixed shutdown bug in MBeanServerKernelBridge.

Added:
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/StartupMonitorUtil.java
Modified:
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/AbstractName.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanServerKernelBridge.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/LongStartupMonitor.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/ProgressBarStartupMonitor.java

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/AbstractName.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/AbstractName.java?rev=395784&r1=395783&r2=395784&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/AbstractName.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/AbstractName.java Thu Apr 20 22:30:06 2006
@@ -191,6 +191,10 @@
         return Collections.unmodifiableMap(name);
     }
 
+    public String getNameProperty(String key) {
+        return (String) name.get(key);
+    }
+
     public ObjectName getObjectName() {
         return objectName;
     }

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanServerKernelBridge.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanServerKernelBridge.java?rev=395784&r1=395783&r2=395784&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanServerKernelBridge.java (original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanServerKernelBridge.java Thu Apr 20 22:30:06 2006
@@ -82,8 +82,9 @@
             beans = new HashMap(registry);
             registry.clear();
         }
-        for (Iterator i = beans.keySet().iterator(); i.hasNext();) {
-            ObjectName objectName = (ObjectName) i.next();
+        for (Iterator i = beans.values().iterator(); i.hasNext();) {
+            MBeanGBeanBridge mbeanGBeanBridge = (MBeanGBeanBridge) i.next();
+            ObjectName objectName = mbeanGBeanBridge.getObjectName();
             try {
                 mbeanServer.unregisterMBean(objectName);
             } catch (Exception e) {

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/LongStartupMonitor.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/LongStartupMonitor.java?rev=395784&r1=395783&r2=395784&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/LongStartupMonitor.java (original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/LongStartupMonitor.java Thu Apr 20 22:30:06 2006
@@ -1,62 +1,73 @@
 package org.apache.geronimo.system.main;
 
 import java.io.PrintStream;
-import java.util.*;
-import java.net.InetSocketAddress;
-import javax.management.ObjectName;
-import javax.management.MalformedObjectNameException;
+
 import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.GBeanNotFoundException;
-import org.apache.geronimo.kernel.NoSuchAttributeException;
 import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.kernel.management.State;
-import org.apache.geronimo.gbean.GBeanInfo;
-import org.apache.geronimo.gbean.GAttributeInfo;
-import org.apache.geronimo.gbean.GBeanData;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
  * A startup monitor that shows the progress of loading and starting
  * configurations, outputing a new line for each configuration started
  * showing the time taken to start the configuration along with the
  * configId.
- *
+ * <p/>
  * This startup monitor produces more lines of output than the
  * ProgressBarStartupMonitor but its output is suitable for redirection
  * to a file or for when Geronimo is running under an IDE or other tool.
- *
+ * <p/>
  * A summary will also be produced containing a list of ports
  * Geronimo is listening on, the configIds of application modules
- * that were started and the URLs of Web applications that were started. 
+ * that were started and the URLs of Web applications that were started.
  *
  * @version $Revision: 1.0$
  */
 public class LongStartupMonitor implements StartupMonitor {
-    private final static Log log = LogFactory.getLog(LongStartupMonitor.class.getName());
-    /** Minimum width of the time (padded with leading spaces) in configuration start messages */
-    private final static int MIN_TIME_WIDTH=3;
-    /** PrintStream */
+    /**
+     * Minimum width of the time (padded with leading spaces) in configuration start messages
+     */
+    private final static int MIN_TIME_WIDTH = 3;
+
+    /**
+     * PrintStream
+     */
     private PrintStream out;
-    /** Number of configurations to start */
+
+    /**
+     * Number of configurations to start
+     */
     private int numConfigs;
-    /** Number of digits in number of configurations to start */
+
+    /**
+     * Number of digits in number of configurations to start
+     */
     private int numConfigsDigits;
-    /** Number of configuration currently being started */
+
+    /**
+     * Number of configuration currently being started
+     */
     private int configNum;
-    /** Time Geronimo was started */
+
+    /**
+     * Time Geronimo was started
+     */
     private long started;
-    /** Time the current configuration being processed was started */
+
+    /**
+     * Time the current configuration being processed was started
+     */
     private long configStarted;
-    /** The Kernel of the system being started */
+
+    /**
+     * The Kernel of the system being started
+     */
     private Kernel kernel;
 
-    public void systemStarting(long startTime) {
+    public synchronized void systemStarting(long startTime) {
         out = System.out;
         started = startTime;
     }
 
-    public void systemStarted(Kernel kernel) {
+    public synchronized void systemStarted(Kernel kernel) {
         this.kernel = kernel;
     }
 
@@ -75,22 +86,22 @@
     }
 
     public synchronized void configurationStarting(Artifact configuration) {
-        configStarted = System.currentTimeMillis();        
+        configStarted = System.currentTimeMillis();
     }
 
     public synchronized void configurationStarted(Artifact configuration) {
-        int time = Math.round((float)(System.currentTimeMillis() - configStarted)/1000f);
+        int time = Math.round((float) (System.currentTimeMillis() - configStarted) / 1000f);
         StringBuffer buf = new StringBuffer();
         buf.append(" started in ");
         // pad config index
         int configIndexDigits = Integer.toString(configNum).length();
-        for(; configIndexDigits < numConfigsDigits; configIndexDigits++) {
+        for (; configIndexDigits < numConfigsDigits; configIndexDigits++) {
             buf.append(' ');
         }
         // pad configuration startup time
         buf.append(configNum).append('/').append(numConfigs).append(' ');
         int timeDigits = Integer.toString(time).length();
-        for(; timeDigits < MIN_TIME_WIDTH; timeDigits++) {
+        for (; timeDigits < MIN_TIME_WIDTH; timeDigits++) {
             buf.append(' ');
         }
         buf.append(time).append("s ");
@@ -98,197 +109,15 @@
     }
 
     public synchronized void startupFinished() {
-        int time = Math.round((float)(System.currentTimeMillis() - started)/1000f);
-        
-        out.println("Startup completed in "+time+" seconds");
-        wrapUp();
-    }
-
-    // TODO - We should probably share the wrapUp() code in ProgressBarStartupMonitor
-    private void wrapUp() {
-        List apps = new ArrayList();  // type = String (message)
-        List webs = new ArrayList();  // type = WebAppInfo
-        List ports = new ArrayList(); // type = AddressHolder
-        Map containers = new HashMap();
-        Map failed = new HashMap();   // key = ObjectName, value = String (message)
-        String serverInfo = null;
-        try {
-            Set gbeans = kernel.listGBeans(ObjectName.getInstance("*:*"));
-            Map beanInfos = new HashMap(); // key = GBeanInfo, value = List (of attribute names)
-            for (Iterator it = gbeans.iterator(); it.hasNext();) {
-                ObjectName name = (ObjectName) it.next();
-                if(isApplicationModule(name)) {
-                    apps.add("    "+decodeModule(name.getKeyProperty("j2eeType"))+": "+name.getKeyProperty("name"));
-                }
-                if(isWebModule(name)) {
-                    String webAppName = name.getCanonicalName();
-                    String context = (String) kernel.getAttribute(name, "contextPath");
-                    String containerName = (String) kernel.getAttribute(name, "containerName");
-                    webs.add(new WebAppInfo(containerName, webAppName, context));
-                }
-
-                int stateValue = kernel.getGBeanState(name);
-                if (stateValue != State.RUNNING_INDEX) {
-                    GBeanData data = kernel.getGBeanData(name);
-                    State state = State.fromInt(stateValue);
-                    StringBuffer buf = new StringBuffer();
-                    buf.append("(").append(state.getName());
-                    // Since it's not unusual for a failure to be caused by a port binding failure
-                    //    we'll see if there's a likely looking port attribute in the config data
-                    //    for the GBean.  It's a long shot, but hey.
-                    if(data != null && data.getAttributes() != null) {
-                        Map map = data.getAttributes();
-                        for (Iterator it2 = map.keySet().iterator(); it2.hasNext();) {
-                            String att = (String) it2.next();
-                            if(att.equals("port") || att.indexOf("Port") > -1) {
-                                buf.append(",").append(att).append("=").append(map.get(att));
-                            }
-                        }
-                    }
-                    buf.append(")");
-                    failed.put(name, buf.toString());
-                    continue;
-                }
-
-                // Check if this is ServerInfo
-                GBeanInfo info = kernel.getGBeanInfo(name);
-                if(info.getClassName().equals("org.apache.geronimo.system.serverinfo.ServerInfo")) {
-                    serverInfo = (String) kernel.getAttribute(name, "version");
-                }
-
-                // Look for any SocketAddress properties
-                List list = (List) beanInfos.get(info);
-                if(list == null) {
-                    list = new ArrayList(3);
-                    beanInfos.put(info, list);
-                    Set atts = info.getAttributes();
-                    for (Iterator it2 = atts.iterator(); it2.hasNext();) {
-                        GAttributeInfo att = (GAttributeInfo) it2.next();
-                        if(att.getType().equals("java.net.InetSocketAddress")) {
-                            list.add(att);
-                        }
-                    }
-                }
-                for (int i = 0; i < list.size(); i++) {
-                    GAttributeInfo att = (GAttributeInfo) list.get(i);
-                    try {
-                        InetSocketAddress addr = (InetSocketAddress) kernel.getAttribute(name, att.getName());
-                        if(addr == null) {
-                            log.debug("No value for GBean "+name+" attribute "+att.getName());
-                            continue;
-                        } else if(addr.getAddress() == null || addr.getAddress().getHostAddress() == null) {
-                            log.debug("Null address or host for GBean "+name+" "+att.getName()+": "+addr.getAddress());
-                        }
-                        String attName = info.getName();
-                        if(list.size() > 1) {
-                            attName += " "+decamelize(att.getName());
-                        } else if(info.getAttribute("name") != null) {
-                            attName += " "+kernel.getAttribute(name, "name");
-                        }
-                        ports.add(new AddressHolder(attName, addr));
-                    } catch (IllegalStateException e) {
-                        // We weren't able to load a port for this service -- that's a bummer
-                    }
-                }
-            }
-            // Look up a URL for each WebContainer in the server (Manager -< Container -< Connector)
-            containers = WebAppUtil.mapContainersToURLs(kernel);
-        } catch (MalformedObjectNameException e) {
-            e.printStackTrace();
-        } catch (GBeanNotFoundException e) {
-            e.printStackTrace();
-        } catch (NoSuchAttributeException e) {
-            e.printStackTrace();
-        } catch (Exception e) { // required by Kernel.getAttribute
-            e.printStackTrace();
-        }
-
-        // Helpful output: list of ports we listen on
-        if(ports.size() > 0) {
-            Collections.sort(ports);
-            System.out.println("  Listening on Ports:");
-            int max = 0;
-            for (int i = 0; i < ports.size(); i++) {
-                AddressHolder holder = (AddressHolder) ports.get(i);
-                if(holder.getAddress().getAddress() != null && holder.getAddress().getAddress().getHostAddress() != null) {
-                    max = Math.max(max, holder.getAddress().getAddress().getHostAddress().length());
-                }
-            }
-            for (int i = 0; i < ports.size(); i++) {
-                AddressHolder holder = (AddressHolder) ports.get(i);
-                StringBuffer buf = new StringBuffer();
-                buf.append("   ");
-                if(holder.getAddress().getPort() < 10) {
-                    buf.append(' ');
-                }
-                if(holder.getAddress().getPort() < 100) {
-                    buf.append(' ');
-                }
-                if(holder.getAddress().getPort() < 1000) {
-                    buf.append(' ');
-                }
-                if(holder.getAddress().getPort() < 10000) {
-                    buf.append(' ');
-                }
-                buf.append(holder.getAddress().getPort()).append(' ');
-                String address = holder.getAddress().getAddress() == null || holder.getAddress().getAddress().getHostAddress() == null ? "" :
-                        holder.getAddress().getAddress().getHostAddress();
-                buf.append(address);
-                for(int j=address.length(); j<=max; j++) {
-                    buf.append(' ');
-                }
-                buf.append(holder.getName());
-                out.println(buf.toString());
-            }
-            out.println();
-        }
-        // Helpful output: list of applications started
-        if(apps.size() > 0) {
-            out.println("  Started Application Modules:");
-            for (int i = 0; i < apps.size(); i++) {
-                out.println((String)apps.get(i));
-            }
-            out.println();
-        }
-        // Helpful output: Web URLs
-        if(webs.size() > 0) {
-            Collections.sort(webs);
-            out.println("  Web Applications:");
-            for (int i = 0; i < webs.size(); i++) {
-                WebAppInfo app = (WebAppInfo) webs.get(i);
-                out.println("    "+containers.get(app.getContainerObjectName())+app.getContext());
-            }
-            out.println();
-        }
+        int time = Math.round((float) (System.currentTimeMillis() - started) / 1000f);
 
-        // Helpful output: list of GBeans that did not start
-        if(failed.size() > 0) {
-            out.println("  WARNING: Some GBeans were not started successfully:");
-            for (Iterator it = failed.keySet().iterator(); it.hasNext();) {
-                ObjectName name = (ObjectName) it.next();
-                String state = (String) failed.get(name);
-                if(name.getKeyProperty("name") != null) {
-                    log.debug("Unable to start "+name+" "+state);
-                    out.println("    "+name.getKeyProperty("name")+" "+state);
-                } else {
-                    out.println("    "+name+" "+state);
-                }
-            }
-            out.println();
-        }
-
-        StringBuffer msg = new StringBuffer();
-        msg.append("Geronimo Application Server started");
-        if(serverInfo != null) {
-            msg.append(" (version ").append(serverInfo).append(")");
-        }
-        out.println(msg.toString());
-        out.flush();
+        out.println("Startup completed in " + time + " seconds");
+        StartupMonitorUtil.wrapUp(out, kernel);
     }
 
     // TODO Review - Currently loadFailed is not called by Daemon
     public synchronized void loadFailed(String configuration, Exception problem) {
-        out.println("Failed to load configuration "+configuration);
+        out.println("Failed to load configuration " + configuration);
         out.println();
         problem.printStackTrace(out);
     }
@@ -301,143 +130,11 @@
 
     // TODO Review - Currently startFailed is not called by Daemon
     public synchronized void startFailed(String configuration, Exception problem) {
-        out.println("Failed to start configuration "+configuration);
+        out.println("Failed to start configuration " + configuration);
         // We print the stack track now (rather than defering the printing of it)
-        // since other problems that may occur during the start of a configuration 
-        // (e.g. an individual GBean not being able to start) produce 
+        // since other problems that may occur during the start of a configuration
+        // (e.g. an individual GBean not being able to start) produce
         // errors in the log (and therefore standard output) immediately.
         problem.printStackTrace(out);
-    }
-
-    private static boolean isApplicationModule(ObjectName on) {
-        String type = on.getKeyProperty("j2eeType");
-        String app = on.getKeyProperty("J2EEApplication");
-        String name = on.getKeyProperty("name");
-        if(type != null && (app == null || app.equals("null"))) {
-            return (type.equals("WebModule") || type.equals("J2EEApplication") || type.equals("EJBModule") || type.equals("AppClientModule") || type.equals("ResourceAdapterModule")) && !name.startsWith("org/apache/geronimo/System");
-        }
-        return false;
-    }
-
-    private static boolean isWebModule(ObjectName on) {
-        String type = on.getKeyProperty("j2eeType");
-        return type != null && type.equals("WebModule");
-    }
-
-    private static String decodeModule(String value) {
-        if(value.equals("WebModule")) {
-            return "WAR";
-        } else if(value.equals("J2EEApplication")) {
-            return "EAR";
-        } else if(value.equals("EJBModule")) {
-            return "JAR";
-        } else if(value.equals("AppClientModule")) {
-            return "CAR";
-        } else if(value.equals("ResourceAdapterModule")) {
-            return "RAR";
-        } else {
-            return "UNK";
-        }
-    }
-
-    private static String decamelize(String s) {
-        if(s == null || s.equals("")) {
-            return s;
-        }
-        StringBuffer buf = new StringBuffer();
-        buf.append(Character.toUpperCase(s.charAt(0)));
-        for(int i=1; i<s.length(); i++) {
-            if(Character.isUpperCase(s.charAt(i))) {
-                if(s.length() > i+1 && Character.isLowerCase(s.charAt(i+1))) {
-                    buf.append(" ");
-                }
-            }
-            buf.append(s.charAt(i));
-        }
-        return buf.toString();
-    }
-
-    private static class AddressHolder implements Comparable {
-        private String name;
-        private InetSocketAddress address;
-
-        public AddressHolder(String name, InetSocketAddress address) {
-            this.name = name;
-            this.address = address;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public void setName(String name) {
-            this.name = name;
-        }
-
-        public InetSocketAddress getAddress() {
-            return address;
-        }
-
-        public void setAddress(InetSocketAddress address) {
-            this.address = address;
-        }
-
-        public int compareTo(Object o) {
-            AddressHolder other = (AddressHolder) o;
-            int value = address.getPort() - other.address.getPort();
-            return value == 0 ? address.getAddress().toString().compareTo(other.address.getAddress().toString()) : value;
-        }
-    }
-
-    private static class WebAppInfo implements Comparable {
-        private String containerObjectName;
-        private String webAppObjectName;
-        private String context;
-
-        public WebAppInfo(String containerObjectName, String webAppObjectName, String context) {
-            this.containerObjectName = containerObjectName;
-            this.webAppObjectName = webAppObjectName;
-            this.context = context;
-        }
-
-        public String getContainerObjectName() {
-            return containerObjectName;
-        }
-
-        public String getWebAppObjectName() {
-            return webAppObjectName;
-        }
-
-        public String getContext() {
-            return context;
-        }
-
-        public boolean equals(Object o) {
-            if (this == o) return true;
-            if (!(o instanceof WebAppInfo)) return false;
-
-            final WebAppInfo webAppInfo = (WebAppInfo) o;
-
-            if (!containerObjectName.equals(webAppInfo.containerObjectName)) return false;
-            if (!context.equals(webAppInfo.context)) return false;
-            if (!webAppObjectName.equals(webAppInfo.webAppObjectName)) return false;
-
-            return true;
-        }
-
-        public int hashCode() {
-            int result;
-            result = containerObjectName.hashCode();
-            result = 29 * result + webAppObjectName.hashCode();
-            result = 29 * result + context.hashCode();
-            return result;
-        }
-
-        public int compareTo(Object o) {
-            WebAppInfo other = (WebAppInfo) o;
-            int test = containerObjectName.compareTo(other.containerObjectName);
-            if(test != 0) return test;
-            return context.compareTo(other.context);
-        }
     }
 }

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/ProgressBarStartupMonitor.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/ProgressBarStartupMonitor.java?rev=395784&r1=395783&r2=395784&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/ProgressBarStartupMonitor.java (original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/ProgressBarStartupMonitor.java Thu Apr 20 22:30:06 2006
@@ -1,41 +1,31 @@
 package org.apache.geronimo.system.main;
 
 import java.io.PrintStream;
-import java.util.*;
-import java.net.InetSocketAddress;
-import javax.management.ObjectName;
-import javax.management.MalformedObjectNameException;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.GBeanNotFoundException;
-import org.apache.geronimo.kernel.NoSuchAttributeException;
 import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.kernel.management.State;
-import org.apache.geronimo.gbean.GBeanInfo;
-import org.apache.geronimo.gbean.GAttributeInfo;
-import org.apache.geronimo.gbean.GBeanData;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
  * A startup monitor that shows the progress of loading and starting
  * configurations using a text based progress bar and the use of line
- * feeds to update the progress display, therefore minimizing the 
+ * feeds to update the progress display, therefore minimizing the
  * number of lines output to the terminal.
- *
+ * <p/>
  * A summary will also be produced containing a list of ports
  * Geronimo is listening on, the configIds of application modules
- * that were started and the URLs of Web applications that were started. 
+ * that were started and the URLs of Web applications that were started.
  *
  * @version $Revision: 1.0$
  */
 public class ProgressBarStartupMonitor implements StartupMonitor {
-    private final static Log log = LogFactory.getLog(ProgressBarStartupMonitor.class.getName());
-    private final static char STATUS_NOT_READY=' ';
-    private final static char STATUS_LOADING='-';
-    private final static char STATUS_LOADED='>';
-    private final static char STATUS_STARTED='*';
-    private final static char STATUS_FAILED='x';
-    private final static int MAX_WIDTH=70;
+    private final static char STATUS_NOT_READY = ' ';
+    private final static char STATUS_LOADING = '-';
+    private final static char STATUS_LOADED = '>';
+    private final static char STATUS_STARTED = '*';
+    private final static char STATUS_FAILED = 'x';
+    private final static int MAX_WIDTH = 70;
     private PrintStream out;
     private String currentOperation;
     private Artifact[] configurations;
@@ -48,12 +38,12 @@
     private List exceptions = new ArrayList();
     private UpdateThread thread;
 
-    public void systemStarting(long startTime) {
+    public synchronized void systemStarting(long startTime) {
         out = System.out;
         started = startTime;
     }
 
-    public void systemStarted(Kernel kernel) {
+    public synchronized void systemStarted(Kernel kernel) {
         out.println("Starting Geronimo Application Server");
         this.kernel = kernel;
         currentOperation = "Loading";
@@ -66,44 +56,44 @@
             configStatus[i] = STATUS_NOT_READY;
         }
         operationLimit = MAX_WIDTH
-            - 5 // two brackets, start and stop tokens, space afterward
-            - configurations.length // configuration tokens
-            - 4 // 2 digits of percent plus % plus space afterward
-            - 5;// 3 digits of time plus s plus space afterward
+                - 5 // two brackets, start and stop tokens, space afterward
+                - configurations.length // configuration tokens
+                - 4 // 2 digits of percent plus % plus space afterward
+                - 5;// 3 digits of time plus s plus space afterward
         repaint();
         thread = new UpdateThread();
         thread.start();
     }
 
-    public void calculatePercent() {
-        if(finished) {
+    public synchronized void calculatePercent() {
+        if (finished) {
             this.percent = 100;
             return;
         }
         int percent = 0;
-        if(kernel != null) percent += 5;
-        int total = configStatus.length*2;
+        if (kernel != null) percent += 5;
+        int total = configStatus.length * 2;
         int progress = 0;
         for (int i = 0; i < configStatus.length; i++) {
             char c = configStatus[i];
-            switch(c) {
+            switch (c) {
                 case STATUS_LOADED:
-                    progress +=1;
+                    progress += 1;
                     break;
                 case STATUS_STARTED:
                 case STATUS_FAILED:
-                    progress +=2;
+                    progress += 2;
                     break;
             }
         }
-        percent += Math.round(90f*(float)progress/(float)total);
+        percent += Math.round(90f * (float) progress / (float) total);
         this.percent = percent;
     }
 
     public synchronized void configurationLoading(Artifact configuration) {
-        currentOperation = " Loading "+configuration;
+        currentOperation = " Loading " + configuration;
         for (int i = 0; i < configurations.length; i++) {
-            if(configurations[i].equals(configuration)) {
+            if (configurations[i].equals(configuration)) {
                 configStatus[i] = STATUS_LOADING;
             }
         }
@@ -112,7 +102,7 @@
 
     public synchronized void configurationLoaded(Artifact configuration) {
         for (int i = 0; i < configurations.length; i++) {
-            if(configurations[i].equals(configuration)) {
+            if (configurations[i].equals(configuration)) {
                 configStatus[i] = STATUS_LOADED;
             }
         }
@@ -121,12 +111,12 @@
     }
 
     public synchronized void configurationStarting(Artifact configuration) {
-        currentOperation = "Starting "+configuration;
+        currentOperation = "Starting " + configuration;
     }
 
     public synchronized void configurationStarted(Artifact configuration) {
         for (int i = 0; i < configurations.length; i++) {
-            if(configurations[i].equals(configuration)) {
+            if (configurations[i].equals(configuration)) {
                 configStatus[i] = STATUS_STARTED;
             }
         }
@@ -142,199 +132,13 @@
         thread.interrupt();
     }
 
-    private void wrapUp() {
-        repaint();
-        out.println();
-
-        List apps = new ArrayList();  // type = String (message)
-        List webs = new ArrayList();  // type = WebAppInfo
-        List ports = new ArrayList(); // type = AddressHolder
-        Map containers = new HashMap();
-        Map failed = new HashMap();   // key = ObjectName, value = String (message)
-        String serverInfo = null;
-        try {
-            Set gbeans = kernel.listGBeans(ObjectName.getInstance("*:*"));
-            Map beanInfos = new HashMap(); // key = GBeanInfo, value = List (of attribute names)
-            for (Iterator it = gbeans.iterator(); it.hasNext();) {
-                ObjectName name = (ObjectName) it.next();
-                if(isApplicationModule(name)) {
-                    apps.add("    "+decodeModule(name.getKeyProperty("j2eeType"))+": "+name.getKeyProperty("name"));
-                }
-                if(isWebModule(name)) {
-                    String webAppName = name.getCanonicalName();
-                    String context = (String) kernel.getAttribute(name, "contextPath");
-                    String containerName = (String) kernel.getAttribute(name, "containerName");
-                    webs.add(new WebAppInfo(containerName, webAppName, context));
-                }
-
-                int stateValue = kernel.getGBeanState(name);
-                if (stateValue != State.RUNNING_INDEX) {
-                    GBeanData data = kernel.getGBeanData(name);
-                    State state = State.fromInt(stateValue);
-                    StringBuffer buf = new StringBuffer();
-                    buf.append("(").append(state.getName());
-                    // Since it's not unusual for a failure to be caused by a port binding failure
-                    //    we'll see if there's a likely looking port attribute in the config data
-                    //    for the GBean.  It's a long shot, but hey.
-                    if(data != null && data.getAttributes() != null) {
-                        Map map = data.getAttributes();
-                        for (Iterator it2 = map.keySet().iterator(); it2.hasNext();) {
-                            String att = (String) it2.next();
-                            if(att.equals("port") || att.indexOf("Port") > -1) {
-                                buf.append(",").append(att).append("=").append(map.get(att));
-                            }
-                        }
-                    }
-                    buf.append(")");
-                    failed.put(name, buf.toString());
-                    continue;
-                }
-
-                // Check if this is ServerInfo
-                GBeanInfo info = kernel.getGBeanInfo(name);
-                if(info.getClassName().equals("org.apache.geronimo.system.serverinfo.ServerInfo")) {
-                    serverInfo = (String) kernel.getAttribute(name, "version");
-                }
-
-                // Look for any SocketAddress properties
-                List list = (List) beanInfos.get(info);
-                if(list == null) {
-                    list = new ArrayList(3);
-                    beanInfos.put(info, list);
-                    Set atts = info.getAttributes();
-                    for (Iterator it2 = atts.iterator(); it2.hasNext();) {
-                        GAttributeInfo att = (GAttributeInfo) it2.next();
-                        if(att.getType().equals("java.net.InetSocketAddress")) {
-                            list.add(att);
-                        }
-                    }
-                }
-                for (int i = 0; i < list.size(); i++) {
-                    GAttributeInfo att = (GAttributeInfo) list.get(i);
-                    try {
-                        InetSocketAddress addr = (InetSocketAddress) kernel.getAttribute(name, att.getName());
-                        if(addr == null) {
-                            log.debug("No value for GBean "+name+" attribute "+att.getName());
-                            continue;
-                        } else if(addr.getAddress() == null || addr.getAddress().getHostAddress() == null) {
-                            log.debug("Null address or host for GBean "+name+" "+att.getName()+": "+addr.getAddress());
-                        }
-                        String attName = info.getName();
-                        if(list.size() > 1) {
-                            attName += " "+decamelize(att.getName());
-                        } else if(info.getAttribute("name") != null) {
-                            attName += " "+kernel.getAttribute(name, "name");
-                        }
-                        ports.add(new AddressHolder(attName, addr));
-                    } catch (IllegalStateException e) {
-                        // We weren't able to load a port for this service -- that's a bummer
-                    }
-                }
-            }
-            // Look up a URL for each WebContainer in the server (Manager -< Container -< Connector)
-            containers = WebAppUtil.mapContainersToURLs(kernel);
-        } catch (MalformedObjectNameException e) {
-            e.printStackTrace();
-        } catch (GBeanNotFoundException e) {
-            e.printStackTrace();
-        } catch (NoSuchAttributeException e) {
-            e.printStackTrace();
-        } catch (Exception e) { // required by Kernel.getAttribute
-            e.printStackTrace();
-        }
-
-        Collections.sort(apps);
-
-        // Helpful output: list of ports we listen on
-        if(ports.size() > 0) {
-            Collections.sort(ports);
-            System.out.println("  Listening on Ports:");
-            int max = 0;
-            for (int i = 0; i < ports.size(); i++) {
-                AddressHolder holder = (AddressHolder) ports.get(i);
-                if(holder.getAddress().getAddress() != null && holder.getAddress().getAddress().getHostAddress() != null) {
-                    max = Math.max(max, holder.getAddress().getAddress().getHostAddress().length());
-                }
-            }
-            for (int i = 0; i < ports.size(); i++) {
-                AddressHolder holder = (AddressHolder) ports.get(i);
-                StringBuffer buf = new StringBuffer();
-                buf.append("   ");
-                if(holder.getAddress().getPort() < 10) {
-                    buf.append(' ');
-                }
-                if(holder.getAddress().getPort() < 100) {
-                    buf.append(' ');
-                }
-                if(holder.getAddress().getPort() < 1000) {
-                    buf.append(' ');
-                }
-                if(holder.getAddress().getPort() < 10000) {
-                    buf.append(' ');
-                }
-                buf.append(holder.getAddress().getPort()).append(' ');
-                String address = holder.getAddress().getAddress() == null || holder.getAddress().getAddress().getHostAddress() == null ? "" :
-                        holder.getAddress().getAddress().getHostAddress();
-                buf.append(address);
-                for(int j=address.length(); j<=max; j++) {
-                    buf.append(' ');
-                }
-                buf.append(holder.getName());
-                out.println(buf.toString());
-            }
-            out.println();
-        }
-        // Helpful output: list of applications started
-        if(apps.size() > 0) {
-            out.println("  Started Application Modules:");
-            for (int i = 0; i < apps.size(); i++) {
-                out.println((String)apps.get(i));
-            }
-            out.println();
-        }
-        // Helpful output: Web URLs
-        if(webs.size() > 0) {
-            Collections.sort(webs);
-            out.println("  Web Applications:");
-            for (int i = 0; i < webs.size(); i++) {
-                WebAppInfo app = (WebAppInfo) webs.get(i);
-                out.println("    "+containers.get(app.getContainerObjectName())+app.getContext());
-            }
-            out.println();
-        }
-
-        // Helpful output: list of GBeans that did not start
-        if(failed.size() > 0) {
-            out.println("  WARNING: Some GBeans were not started successfully:");
-            for (Iterator it = failed.keySet().iterator(); it.hasNext();) {
-                ObjectName name = (ObjectName) it.next();
-                String state = (String) failed.get(name);
-                if(name.getKeyProperty("name") != null) {
-                    log.debug("Unable to start "+name+" "+state);
-                    out.println("    "+name.getKeyProperty("name")+" "+state);
-                } else {
-                    out.println("    "+name+" "+state);
-                }
-            }
-            out.println();
-        }
-
-        StringBuffer msg = new StringBuffer();
-        msg.append("Geronimo Application Server started");
-        if(serverInfo != null) {
-            msg.append(" (version ").append(serverInfo).append(")");
-        }
-        out.println(msg.toString());
-        out.flush();
-    }
-
     public synchronized void loadFailed(String configuration, Exception problem) {
         for (int i = 0; i < configurations.length; i++) {
-            if(configurations[i].equals(configuration)) {
+            if (configurations[i].equals(configuration)) {
                 configStatus[i] = STATUS_FAILED;
             }
         }
-        if(problem != null) exceptions.add(problem);
+        if (problem != null) exceptions.add(problem);
     }
 
     public synchronized void serverStartFailed(Exception problem) {
@@ -346,11 +150,11 @@
 
     public synchronized void startFailed(String configuration, Exception problem) {
         for (int i = 0; i < configurations.length; i++) {
-            if(configurations[i].equals(configuration)) {
+            if (configurations[i].equals(configuration)) {
                 configStatus[i] = STATUS_FAILED;
             }
         }
-        if(problem != null) exceptions.add(problem);
+        if (problem != null) exceptions.add(problem);
     }
 
     private synchronized void repaint() {
@@ -362,28 +166,28 @@
         }
         buf.append(finished ? STATUS_STARTED : STATUS_NOT_READY);
         buf.append("] ");
-        if(percent < 10) {
+        if (percent < 10) {
             buf.append(' ');
         }
         buf.append(percent).append("% ");
-        int time = Math.round((float)(System.currentTimeMillis() - started)/1000f);
-        if(time < 10) {
+        int time = Math.round((float) (System.currentTimeMillis() - started) / 1000f);
+        if (time < 10) {
             buf.append(' ');
         }
-        if(time < 100) {
+        if (time < 100) {
             buf.append(' ');
         }
         buf.append(time).append("s ");
-        if(currentOperation.length() > operationLimit) {
+        if (currentOperation.length() > operationLimit) {
             int space = currentOperation.indexOf(' ', 5);
-            buf.append(currentOperation.substring(0, space+1));
+            buf.append(currentOperation.substring(0, space + 1));
             // "Foo BarBarBar" limit 9 = "Foo ...ar" = 13 - 9 + 3 + 1 + 3
             // buf.append("...").append(currentOperation.substring(currentOperation.length()-operationLimit+space+4));
             // "FooBar BarBarBar" limit 12 = "FooBar Ba..." = (7, 12-3)
-            buf.append(currentOperation.substring(space+1, operationLimit - 3)).append("...");
+            buf.append(currentOperation.substring(space + 1, operationLimit - 3)).append("...");
         } else {
             buf.append(currentOperation);
-            for(int i=currentOperation.length(); i<operationLimit; i++) {
+            for (int i = currentOperation.length(); i < operationLimit; i++) {
                 buf.append(' ');
             }
         }
@@ -391,86 +195,6 @@
         out.flush();
     }
 
-    private static boolean isApplicationModule(ObjectName on) {
-        String type = on.getKeyProperty("j2eeType");
-        String app = on.getKeyProperty("J2EEApplication");
-        String name = on.getKeyProperty("name");
-        if(type != null && (app == null || app.equals("null"))) {
-            return (type.equals("WebModule") || type.equals("J2EEApplication") || type.equals("EJBModule") || type.equals("AppClientModule") || type.equals("ResourceAdapterModule")) && !name.startsWith("org/apache/geronimo/System");
-        }
-        return false;
-    }
-
-    private static boolean isWebModule(ObjectName on) {
-        String type = on.getKeyProperty("j2eeType");
-        return type != null && type.equals("WebModule");
-    }
-
-    private static String decodeModule(String value) {
-        if(value.equals("WebModule")) {
-            return "WAR";
-        } else if(value.equals("J2EEApplication")) {
-            return "EAR";
-        } else if(value.equals("EJBModule")) {
-            return "JAR";
-        } else if(value.equals("AppClientModule")) {
-            return "CAR";
-        } else if(value.equals("ResourceAdapterModule")) {
-            return "RAR";
-        } else {
-            return "UNK";
-        }
-    }
-
-    private static String decamelize(String s) {
-        if(s == null || s.equals("")) {
-            return s;
-        }
-        StringBuffer buf = new StringBuffer();
-        buf.append(Character.toUpperCase(s.charAt(0)));
-        for(int i=1; i<s.length(); i++) {
-            if(Character.isUpperCase(s.charAt(i))) {
-                if(s.length() > i+1 && Character.isLowerCase(s.charAt(i+1))) {
-                    buf.append(" ");
-                }
-            }
-            buf.append(s.charAt(i));
-        }
-        return buf.toString();
-    }
-
-    private static class AddressHolder implements Comparable {
-        private String name;
-        private InetSocketAddress address;
-
-        public AddressHolder(String name, InetSocketAddress address) {
-            this.name = name;
-            this.address = address;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public void setName(String name) {
-            this.name = name;
-        }
-
-        public InetSocketAddress getAddress() {
-            return address;
-        }
-
-        public void setAddress(InetSocketAddress address) {
-            this.address = address;
-        }
-
-        public int compareTo(Object o) {
-            AddressHolder other = (AddressHolder) o;
-            int value = address.getPort() - other.address.getPort();
-            return value == 0 ? address.getAddress().toString().compareTo(other.address.getAddress().toString()) : value;
-        }
-    }
-
     private class UpdateThread extends Thread {
         private volatile boolean done = false;
 
@@ -480,7 +204,7 @@
         }
 
         public void run() {
-            while(!done) {
+            while (!done) {
                 try {
                     Thread.sleep(500);
                 } catch (InterruptedException e) {
@@ -488,59 +212,10 @@
                 }
                 repaint();
             }
-            wrapUp();
-        }
-    }
-
-    private static class WebAppInfo implements Comparable {
-        private String containerObjectName;
-        private String webAppObjectName;
-        private String context;
-
-        public WebAppInfo(String containerObjectName, String webAppObjectName, String context) {
-            this.containerObjectName = containerObjectName;
-            this.webAppObjectName = webAppObjectName;
-            this.context = context;
-        }
-
-        public String getContainerObjectName() {
-            return containerObjectName;
-        }
-
-        public String getWebAppObjectName() {
-            return webAppObjectName;
-        }
 
-        public String getContext() {
-            return context;
-        }
-
-        public boolean equals(Object o) {
-            if (this == o) return true;
-            if (!(o instanceof WebAppInfo)) return false;
-
-            final WebAppInfo webAppInfo = (WebAppInfo) o;
-
-            if (!containerObjectName.equals(webAppInfo.containerObjectName)) return false;
-            if (!context.equals(webAppInfo.context)) return false;
-            if (!webAppObjectName.equals(webAppInfo.webAppObjectName)) return false;
-
-            return true;
-        }
-
-        public int hashCode() {
-            int result;
-            result = containerObjectName.hashCode();
-            result = 29 * result + webAppObjectName.hashCode();
-            result = 29 * result + context.hashCode();
-            return result;
-        }
-
-        public int compareTo(Object o) {
-            WebAppInfo other = (WebAppInfo) o;
-            int test = containerObjectName.compareTo(other.containerObjectName);
-            if(test != 0) return test;
-            return context.compareTo(other.context);
+            repaint();
+            out.println();
+            StartupMonitorUtil.wrapUp(ProgressBarStartupMonitor.this.out, ProgressBarStartupMonitor.this.kernel);
         }
     }
 }

Added: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/StartupMonitorUtil.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/StartupMonitorUtil.java?rev=395784&view=auto
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/StartupMonitorUtil.java (added)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/StartupMonitorUtil.java Thu Apr 20 22:30:06 2006
@@ -0,0 +1,351 @@
+/**
+ *
+ * Copyright 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.apache.geronimo.system.main;
+
+import java.io.PrintStream;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.gbean.GAttributeInfo;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.management.State;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StartupMonitorUtil {
+    private final static Log log = LogFactory.getLog(StartupMonitor.class.getName());
+
+    public static synchronized void wrapUp(PrintStream out, Kernel kernel) {
+        List apps = new ArrayList();  // type = String (message)
+        List webs = new ArrayList();  // type = WebAppInfo
+        List ports = new ArrayList(); // type = AddressHolder
+        Map containers = new HashMap();
+        Map failed = new HashMap();   // key = AbstractName, value = String (message)
+        String serverInfo = null;
+        try {
+            Set gbeans = kernel.listGBeans((AbstractNameQuery) null);
+            Map beanInfos = new HashMap(); // key = GBeanInfo, value = List (of attribute names)
+            for (Iterator it = gbeans.iterator(); it.hasNext();) {
+                AbstractName name = (AbstractName) it.next();
+                if (isApplicationModule(name)) {
+                    apps.add("    " + decodeModule(name.getNameProperty("j2eeType")) + ": " + name.getNameProperty("name"));
+                }
+                if (isWebModule(name)) {
+                    String context = (String) kernel.getAttribute(name, "contextPath");
+                    String containerName = (String) kernel.getAttribute(name, "containerName");
+                    webs.add(new WebAppInfo(containerName, name, context));
+                }
+
+                int stateValue = kernel.getGBeanState(name);
+                if (stateValue != State.RUNNING_INDEX) {
+                    GBeanData data = kernel.getGBeanData(name);
+                    State state = State.fromInt(stateValue);
+                    StringBuffer buf = new StringBuffer();
+                    buf.append("(").append(state.getName());
+                    // Since it's not unusual for a failure to be caused by a port binding failure
+                    //    we'll see if there's a likely looking port attribute in the config data
+                    //    for the GBean.  It's a long shot, but hey.
+                    if (data != null && data.getAttributes() != null) {
+                        Map map = data.getAttributes();
+                        for (Iterator it2 = map.keySet().iterator(); it2.hasNext();) {
+                            String att = (String) it2.next();
+                            if (att.equals("port") || att.indexOf("Port") > -1) {
+                                buf.append(",").append(att).append("=").append(map.get(att));
+                            }
+                        }
+                    }
+                    buf.append(")");
+                    failed.put(name, buf.toString());
+                    continue;
+                }
+
+                // Check if this is ServerInfo
+                GBeanInfo info = kernel.getGBeanInfo(name);
+                if (info.getClassName().equals("org.apache.geronimo.system.serverinfo.ServerInfo")) {
+                    serverInfo = (String) kernel.getAttribute(name, "version");
+                }
+
+                // Look for any SocketAddress properties
+                List list = (List) beanInfos.get(info);
+                if (list == null) {
+                    list = new ArrayList(3);
+                    beanInfos.put(info, list);
+                    Set atts = info.getAttributes();
+                    for (Iterator it2 = atts.iterator(); it2.hasNext();) {
+                        GAttributeInfo att = (GAttributeInfo) it2.next();
+                        if (att.getType().equals("java.net.InetSocketAddress")) {
+                            list.add(att);
+                        }
+                    }
+                }
+                for (int i = 0; i < list.size(); i++) {
+                    GAttributeInfo att = (GAttributeInfo) list.get(i);
+                    try {
+                        InetSocketAddress addr = (InetSocketAddress) kernel.getAttribute(name, att.getName());
+                        if (addr == null) {
+                            log.debug("No value for GBean " + name + " attribute " + att.getName());
+                            continue;
+                        } else if (addr.getAddress() == null || addr.getAddress().getHostAddress() == null) {
+                            log.debug("Null address or host for GBean " + name + " " + att.getName() + ": " + addr.getAddress());
+                        }
+                        String attName = info.getName();
+                        if (list.size() > 1) {
+                            attName += " " + decamelize(att.getName());
+                        } else if (info.getAttribute("name") != null) {
+                            attName += " " + kernel.getAttribute(name, "name");
+                        }
+                        ports.add(new AddressHolder(attName, addr));
+                    } catch (IllegalStateException e) {
+                        // We weren't able to load a port for this service -- that's a bummer
+                    }
+                }
+            }
+            // Look up a URL for each WebContainer in the server (Manager -< Container -< Connector)
+            containers = WebAppUtil.mapContainersToURLs(kernel);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        Collections.sort(apps);
+
+        // Helpful output: list of ports we listen on
+        if (ports.size() > 0) {
+            Collections.sort(ports);
+            System.out.println("  Listening on Ports:");
+            int max = 0;
+            for (int i = 0; i < ports.size(); i++) {
+                AddressHolder holder = (AddressHolder) ports.get(i);
+                if (holder.getAddress().getAddress() != null && holder.getAddress().getAddress().getHostAddress() != null)
+                {
+                    max = Math.max(max, holder.getAddress().getAddress().getHostAddress().length());
+                }
+            }
+            for (int i = 0; i < ports.size(); i++) {
+                AddressHolder holder = (AddressHolder) ports.get(i);
+                StringBuffer buf = new StringBuffer();
+                buf.append("   ");
+                if (holder.getAddress().getPort() < 10) {
+                    buf.append(' ');
+                }
+                if (holder.getAddress().getPort() < 100) {
+                    buf.append(' ');
+                }
+                if (holder.getAddress().getPort() < 1000) {
+                    buf.append(' ');
+                }
+                if (holder.getAddress().getPort() < 10000) {
+                    buf.append(' ');
+                }
+                buf.append(holder.getAddress().getPort()).append(' ');
+                String address = holder.getAddress().getAddress() == null || holder.getAddress().getAddress().getHostAddress() == null ? "" :
+                        holder.getAddress().getAddress().getHostAddress();
+                buf.append(address);
+                for (int j = address.length(); j <= max; j++) {
+                    buf.append(' ');
+                }
+                buf.append(holder.getName());
+                out.println(buf.toString());
+            }
+            out.println();
+        }
+        // Helpful output: list of applications started
+        if (apps.size() > 0) {
+            out.println("  Started Application Modules:");
+            for (int i = 0; i < apps.size(); i++) {
+                out.println((String) apps.get(i));
+            }
+            out.println();
+        }
+        // Helpful output: Web URLs
+        if (webs.size() > 0) {
+            Collections.sort(webs);
+            out.println("  Web Applications:");
+            for (int i = 0; i < webs.size(); i++) {
+                WebAppInfo app = (WebAppInfo) webs.get(i);
+                out.println("    " + containers.get(app.getContainerObjectName()) + app.getContext());
+            }
+            out.println();
+        }
+
+        // Helpful output: list of GBeans that did not start
+        if (failed.size() > 0) {
+            out.println("  WARNING: Some GBeans were not started successfully:");
+            for (Iterator it = failed.keySet().iterator(); it.hasNext();) {
+                AbstractName name = (AbstractName) it.next();
+                String state = (String) failed.get(name);
+                if (name.getNameProperty("name") != null) {
+                    log.debug("Unable to start " + name + " " + state);
+                    out.println("    " + name.getNameProperty("name") + " " + state);
+                } else {
+                    out.println("    " + name + " " + state);
+                }
+            }
+            out.println();
+        }
+
+        StringBuffer msg = new StringBuffer();
+        msg.append("Geronimo Application Server started");
+        if (serverInfo != null) {
+            msg.append(" (version ").append(serverInfo).append(")");
+        }
+        out.println(msg.toString());
+        out.flush();
+    }
+
+    private static boolean isApplicationModule(AbstractName abstractName) {
+        String type = abstractName.getNameProperty("j2eeType");
+        String app = abstractName.getNameProperty("J2EEApplication");
+        String name = abstractName.getNameProperty("name");
+        if (type != null && (app == null || app.equals("null"))) {
+            return (type.equals("WebModule") || type.equals("J2EEApplication") || type.equals("EJBModule") || type.equals("AppClientModule") || type.equals("ResourceAdapterModule")) && !name.startsWith("org/apache/geronimo/System");
+        }
+        return false;
+    }
+
+    private static boolean isWebModule(AbstractName abstractName) {
+        String type = abstractName.getNameProperty("j2eeType");
+        return type != null && type.equals("WebModule");
+    }
+
+    private static String decodeModule(String value) {
+        if (value.equals("WebModule")) {
+            return "WAR";
+        } else if (value.equals("J2EEApplication")) {
+            return "EAR";
+        } else if (value.equals("EJBModule")) {
+            return "JAR";
+        } else if (value.equals("AppClientModule")) {
+            return "CAR";
+        } else if (value.equals("ResourceAdapterModule")) {
+            return "RAR";
+        } else {
+            return "UNK";
+        }
+    }
+
+    private static String decamelize(String s) {
+        if (s == null || s.equals("")) {
+            return s;
+        }
+        StringBuffer buf = new StringBuffer();
+        buf.append(Character.toUpperCase(s.charAt(0)));
+        for (int i = 1; i < s.length(); i++) {
+            if (Character.isUpperCase(s.charAt(i))) {
+                if (s.length() > i + 1 && Character.isLowerCase(s.charAt(i + 1))) {
+                    buf.append(" ");
+                }
+            }
+            buf.append(s.charAt(i));
+        }
+        return buf.toString();
+    }
+
+    private static class AddressHolder implements Comparable {
+        private String name;
+        private InetSocketAddress address;
+
+        public AddressHolder(String name, InetSocketAddress address) {
+            this.name = name;
+            this.address = address;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public InetSocketAddress getAddress() {
+            return address;
+        }
+
+        public void setAddress(InetSocketAddress address) {
+            this.address = address;
+        }
+
+        public int compareTo(Object o) {
+            AddressHolder other = (AddressHolder) o;
+            int value = address.getPort() - other.address.getPort();
+            return value == 0 ? address.getAddress().toString().compareTo(other.address.getAddress().toString()) : value;
+        }
+    }
+
+    private static class WebAppInfo implements Comparable {
+        private String containerObjectName;
+        private AbstractName webAppAbstractName;
+        private String context;
+
+        public WebAppInfo(String containerObjectName, AbstractName webAppAbstractName, String context) {
+            this.containerObjectName = containerObjectName;
+            this.webAppAbstractName = webAppAbstractName;
+            this.context = context;
+        }
+
+        public String getContainerObjectName() {
+            return containerObjectName;
+        }
+
+        public AbstractName getWebAppAbstractName() {
+            return webAppAbstractName;
+        }
+
+        public String getContext() {
+            return context;
+        }
+
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (!(o instanceof WebAppInfo)) return false;
+
+            final WebAppInfo webAppInfo = (WebAppInfo) o;
+
+            if (!containerObjectName.equals(webAppInfo.containerObjectName)) return false;
+            if (!context.equals(webAppInfo.context)) return false;
+            return webAppAbstractName.equals(webAppInfo.webAppAbstractName);
+        }
+
+        public int hashCode() {
+            int result;
+            result = containerObjectName.hashCode();
+            result = 29 * result + webAppAbstractName.hashCode();
+            result = 29 * result + context.hashCode();
+            return result;
+        }
+
+        public int compareTo(Object o) {
+            WebAppInfo other = (WebAppInfo) o;
+            int test = containerObjectName.compareTo(other.containerObjectName);
+            if (test != 0) return test;
+            return context.compareTo(other.context);
+        }
+    }
+}



Mime
View raw message