servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r605240 - in /servicemix/smx4/runtime/trunk: ./ assembly/src/main/distribution/text/etc/ gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/ gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/ gs...
Date Tue, 18 Dec 2007 15:48:32 GMT
Author: gnodet
Date: Tue Dec 18 07:48:31 2007
New Revision: 605240

URL: http://svn.apache.org/viewvc?rev=605240&view=rev
Log:
Add info command and remove System.out from Main

Added:
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/InfoCommand.java
Modified:
    servicemix/smx4/runtime/trunk/assembly/src/main/distribution/text/etc/config.properties
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml
    servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml
    servicemix/smx4/runtime/trunk/main/src/main/java/org/apache/servicemix/runtime/main/Main.java
    servicemix/smx4/runtime/trunk/pom.xml

Modified: servicemix/smx4/runtime/trunk/assembly/src/main/distribution/text/etc/config.properties
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/assembly/src/main/distribution/text/etc/config.properties?rev=605240&r1=605239&r2=605240&view=diff
==============================================================================
--- servicemix/smx4/runtime/trunk/assembly/src/main/distribution/text/etc/config.properties
(original)
+++ servicemix/smx4/runtime/trunk/assembly/src/main/distribution/text/etc/config.properties
Tue Dec 18 07:48:31 2007
@@ -25,6 +25,7 @@
  org.osgi.service.startlevel; version=1.0.0, \
  org.osgi.service.url; version=1.0.0, \
  org.apache.servicemix.runtime.main.spi, \
+ com.sun.management, \
  ${jre-${java.specification.version}}
 #org.osgi.framework.bootdelegation=sun.*,com.sun.*
 

Added: servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/InfoCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/InfoCommand.java?rev=605240&view=auto
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/InfoCommand.java
(added)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtins/InfoCommand.java
Tue Dec 18 07:48:31 2007
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.gshell.commands.builtins;
+
+import java.lang.management.ClassLoadingMXBean;
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.OperatingSystemMXBean;
+import java.lang.management.RuntimeMXBean;
+import java.lang.management.ThreadMXBean;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.geronimo.gshell.ansi.Code;
+import org.apache.geronimo.gshell.ansi.Renderer;
+import org.apache.geronimo.gshell.branding.Branding;
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.apache.geronimo.gshell.command.annotation.Requirement;
+import org.apache.geronimo.gshell.support.OsgiCommandSupport;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Display environmental informations
+ */
+@CommandComponent(id="gshell-builtins:info", description="Show system informations")
+public class InfoCommand
+    extends OsgiCommandSupport
+{
+
+    @Requirement
+    private Branding branding;
+
+    private Renderer renderer = new Renderer();
+    private NumberFormat fmtI = new DecimalFormat("###,###");
+    private NumberFormat fmtD = new DecimalFormat("###,##0.000");
+
+    public InfoCommand(Branding branding) {
+        this.branding = branding;
+    }
+
+    @Override
+    protected OsgiCommandSupport createCommand() throws Exception {
+        return new InfoCommand(branding);
+    }
+
+    @Override
+    protected Object doExecute() throws Exception {
+        int maxNameLen;
+        String name;
+        Map<String, String> props = new HashMap<String, String>();
+
+        RuntimeMXBean         runtime = ManagementFactory.getRuntimeMXBean();
+        OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
+        ThreadMXBean          threads = ManagementFactory.getThreadMXBean();
+        MemoryMXBean          mem = ManagementFactory.getMemoryMXBean();
+        ClassLoadingMXBean    cl = ManagementFactory.getClassLoadingMXBean();
+
+        //
+        // print ServiceMix informations
+        //
+        maxNameLen = 25;
+        io.out.println("ServiceMix");
+        printValue("ServiceMix home", maxNameLen, System.getProperty("servicemix.home"));
+        printValue("ServiceMix base", maxNameLen, System.getProperty("servicemix.base"));
+        printValue("ServiceMix version", maxNameLen, branding.getVersion());
+        io.out.println();
+
+        io.out.println("JVM");
+        printValue("Java Virtual Machine", maxNameLen, runtime.getVmName() + " version "
+ runtime.getVmVersion());
+        printValue("Vendor", maxNameLen, runtime.getVmVendor());
+        printValue("Uptime", maxNameLen, printDuration(runtime.getUptime()));
+        try {
+            com.sun.management.OperatingSystemMXBean sunOs = (com.sun.management.OperatingSystemMXBean)
os;
+            printValue("Process CPU time", maxNameLen, printDuration(sunOs.getProcessCpuTime()
/ 1000000));
+            printValue("Total compile time", maxNameLen, printDuration(ManagementFactory.getCompilationMXBean().getTotalCompilationTime()));
+        } catch (Throwable t) {}
+
+        io.out.println("Threads");
+        printValue("Live threads", maxNameLen, Integer.toString(threads.getThreadCount()));
+        printValue("Daemon threads", maxNameLen, Integer.toString(threads.getDaemonThreadCount()));
+        printValue("Peak", maxNameLen, Integer.toString(threads.getPeakThreadCount()));
+        printValue("Total started", maxNameLen, Long.toString(threads.getTotalStartedThreadCount()));
+
+        io.out.println("Memory");
+        printValue("Current heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getUsed()));
+        printValue("Maximum heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getMax()));
+        printValue("Committed heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getCommitted()));
+        printValue("Pending objects", maxNameLen, Integer.toString(mem.getObjectPendingFinalizationCount()));
+        for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans())
{
+            String val = "Name = '" + gc.getName() + "', Collections = " + gc.getCollectionCount()
+ ", Time = " + printDuration(gc.getCollectionTime());
+            printValue("Garbage collector", maxNameLen, val);
+        }
+
+        io.out.println("Classes");
+        printValue("Current classes loaded", maxNameLen, printLong(cl.getLoadedClassCount()));
+        printValue("Total classes loaded", maxNameLen, printLong(cl.getTotalLoadedClassCount()));
+        printValue("Total classes unloaded", maxNameLen, printLong(cl.getUnloadedClassCount()));
+
+        io.out.println("Operating system");
+        printValue("Name", maxNameLen, os.getName() + " version " + os.getVersion());
+        printValue("Architecture", maxNameLen, os.getArch());
+        printValue("Processrors", maxNameLen, Integer.toString(os.getAvailableProcessors()));
+        try {
+            com.sun.management.OperatingSystemMXBean sunOs = (com.sun.management.OperatingSystemMXBean)
os;
+            printValue("Total physical memory", maxNameLen, printSizeInKb(sunOs.getTotalPhysicalMemorySize()));
+            printValue("Free physical memory", maxNameLen, printSizeInKb(sunOs.getFreePhysicalMemorySize()));
+            printValue("Committed virtual memory", maxNameLen, printSizeInKb(sunOs.getCommittedVirtualMemorySize()));
+            printValue("Total swap space", maxNameLen, printSizeInKb(sunOs.getTotalSwapSpaceSize()));
+            printValue("Free swap space", maxNameLen, printSizeInKb(sunOs.getFreeSwapSpaceSize()));
+        } catch (Throwable t) {}
+
+        return null;
+    }
+
+    private String printLong(long i) {
+        return fmtI.format(i);
+    }
+
+    private String printSizeInKb(double size) {
+        return fmtI.format((long) (size / 1024)) + " kbytes";
+    }
+
+    private String printDuration(double uptime) {
+        uptime /= 1000;
+        if (uptime < 60) {
+            return fmtD.format(uptime) + " seconds";
+        }
+        uptime /= 60;
+        if (uptime < 60) {
+            long minutes = (long) uptime;
+            String s = fmtI.format(minutes) + (minutes > 1 ? " minutes" : " minute");
+            return s;
+        }
+        uptime /= 60;
+        if (uptime < 24) {
+            long hours = (long) uptime;
+            long minutes = (long) ((uptime - hours) * 60);
+            String s = fmtI.format(hours) + (hours > 1 ? " hours" : " hour");
+            if (minutes != 0) {
+                s += " " + fmtI.format(minutes) + (minutes > 1 ? " minutes" : "minute");
+            }
+            return s;
+        }
+        uptime /= 24;
+        long days = (long) uptime;
+        long hours = (long) ((uptime - days) * 60);
+        String s = fmtI.format(days) + (days > 1 ? " days" : " day");
+        if (hours != 0) {
+            s += " " + fmtI.format(hours) + (hours > 1 ? " hours" : "hour");
+        }
+        return s;
+    }
+
+    void printSysValue(String prop, int pad) {
+        printValue(prop, pad, System.getProperty(prop));
+    }
+
+    void printValue(String name, int pad, String value) {
+        io.out.println("  " + renderer.render(Renderer.encode(StringUtils.rightPad(name,
pad), Code.BOLD)) + "   " + value);
+    }
+
+}

Modified: servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml?rev=605240&r1=605239&r2=605240&view=diff
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml
(original)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml
Tue Dec 18 07:48:31 2007
@@ -38,6 +38,10 @@
         <constructor-arg ref="branding" />
     </bean>
 
+    <bean id="info" class="org.apache.geronimo.gshell.commands.builtins.InfoCommand">
+        <constructor-arg ref="branding" />
+    </bean>
+
     <bean id="set" class="org.apache.geronimo.gshell.commands.builtins.SetCommand" />
 
     <bean id="source" class="org.apache.geronimo.gshell.commands.builtins.SourceCommand"
/>

Modified: servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml?rev=605240&r1=605239&r2=605240&view=diff
==============================================================================
--- servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml
(original)
+++ servicemix/smx4/runtime/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml
Tue Dec 18 07:48:31 2007
@@ -42,16 +42,19 @@
       </osgi:service-properties>
     </osgi:service>
     
+    <osgi:service ref="exit" interface="org.apache.geronimo.gshell.command.Command">
+        <osgi:service-properties>
+            <entry key="alias" value="exit"/>
+        </osgi:service-properties>
+    </osgi:service>
+
     <osgi:service ref="help" interface="org.apache.geronimo.gshell.command.Command">
       <osgi:service-properties>
       	<entry key="alias" value="help,?"/>
       </osgi:service-properties>
     </osgi:service>
 
-    <osgi:service ref="exit" interface="org.apache.geronimo.gshell.command.Command">
-        <osgi:service-properties>
-            <entry key="alias" value="exit"/>
-        </osgi:service-properties>
+    <osgi:service ref="info" interface="org.apache.geronimo.gshell.command.Command">
     </osgi:service>
 
     <osgi:service ref="set" interface="org.apache.geronimo.gshell.command.Command">

Modified: servicemix/smx4/runtime/trunk/main/src/main/java/org/apache/servicemix/runtime/main/Main.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/main/src/main/java/org/apache/servicemix/runtime/main/Main.java?rev=605240&r1=605239&r2=605240&view=diff
==============================================================================
--- servicemix/smx4/runtime/trunk/main/src/main/java/org/apache/servicemix/runtime/main/Main.java
(original)
+++ servicemix/smx4/runtime/trunk/main/src/main/java/org/apache/servicemix/runtime/main/Main.java
Tue Dec 18 07:48:31 2007
@@ -206,8 +206,8 @@
         main.servicemixHome = getServiceMixHome();
         main.servicemixBase = getServiceMixBase(main.servicemixHome);
         
-        System.out.println("ServiceMix Home: "+main.servicemixHome.getPath());
-        System.out.println("ServiceMix Base: "+main.servicemixBase.getPath());
+        //System.out.println("ServiceMix Home: "+main.servicemixHome.getPath());
+        //System.out.println("ServiceMix Base: "+main.servicemixBase.getPath());
         
         System.setProperty(PROP_SERVICEMIX_HOME, main.servicemixHome.getPath());
         System.setProperty(PROP_SERVICEMIX_BASE, main.servicemixBase.getPath());

Modified: servicemix/smx4/runtime/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/runtime/trunk/pom.xml?rev=605240&r1=605239&r2=605240&view=diff
==============================================================================
--- servicemix/smx4/runtime/trunk/pom.xml (original)
+++ servicemix/smx4/runtime/trunk/pom.xml Tue Dec 18 07:48:31 2007
@@ -78,7 +78,7 @@
       <jline.version>0.9.93</jline.version>
       <log4j.version>1.2.14</log4j.version>
       <mina.version>1.1.6-r602102</mina.version>
-      <pax.logging.version>0.9.8</pax.logging.version>
+      <pax.logging.version>1.0-RC2</pax.logging.version>
       <spring.osgi.version>1.0-m3</spring.osgi.version>
       <spring.version>2.5</spring.version>
       <xstream.version>1.2.2</xstream.version>
@@ -96,6 +96,10 @@
            <id>servicemix</id>
            <name>ServiceMix Repository</name>
            <url>http://svn.apache.org/repos/asf/servicemix/m2-repo</url>
+       </repository>
+       <repository>
+           <id>ops4j</id>
+           <url>http://repository.ops4j.org/maven2</url>
        </repository>
        <!-- Apache snapshot -->
        <repository>



Mime
View raw message