KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > container > monitor > jvm > v15 > JVMRuntimeInfoImpl


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.container.monitor.jvm.v15;
6
7 import java.lang.management.*;
8 import java.util.* ;
9 import org.exoplatform.commons.utils.ExoProperties;
10 import org.exoplatform.container.configuration.* ;
11 import org.picocontainer.Startable;
12 import org.exoplatform.container.monitor.jvm.JVMRuntimeInfo;
13 /**
14  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
15  * @since Nov 8, 2004
16  * @version $Id$
17  */

18 public class JVMRuntimeInfoImpl implements JVMRuntimeInfo, Startable {
19   private RuntimeMXBean mxbean_ ;
20   
21   public JVMRuntimeInfoImpl(ConfigurationManager manager ) throws Exception JavaDoc {
22     mxbean_ = ManagementFactory.getRuntimeMXBean();
23     
24     ServiceConfiguration sconf =
25       manager.getServiceConfiguration(JVMRuntimeInfo.class) ;
26     PropertiesParam param = sconf.getPropertiesParam("add.system.properties") ;
27     if(param != null) {
28       ExoProperties props = param.getProperties() ;
29       Iterator i = props.entrySet().iterator() ;
30       while(i.hasNext()) {
31         Map.Entry entry = (Map.Entry)i.next() ;
32         System.setProperty((String JavaDoc) entry.getKey(), (String JavaDoc) entry.getValue()) ;
33       }
34     }
35   }
36   
37   public String JavaDoc getName() { return mxbean_.getName() ; }
38   public String JavaDoc getSpecName() { return mxbean_.getSpecName() ; }
39   public String JavaDoc getSpecVendor() { return mxbean_.getSpecVendor() ; }
40   public String JavaDoc getSpecVersion() { return mxbean_.getSpecVersion() ; }
41   public String JavaDoc getManagementSpecVersion() { return mxbean_.getManagementSpecVersion();}
42   
43   public String JavaDoc getVmName() { return mxbean_.getVmName(); }
44   public String JavaDoc getVmVendor() { return mxbean_.getVmVendor() ; }
45   public String JavaDoc getVmVersion() { return mxbean_.getVmVersion() ; }
46   
47   public List getInputArguments() { return mxbean_.getInputArguments() ; }
48   public Map getSystemProperties() { return mxbean_.getSystemProperties() ; }
49   
50   public boolean getBootClassPathSupported() { return mxbean_.isBootClassPathSupported();}
51   public String JavaDoc getBootClassPath() { return mxbean_.getBootClassPath(); }
52   public String JavaDoc getClassPath() { return mxbean_.getClassPath() ; }
53   public String JavaDoc getLibraryPath() { return mxbean_.getLibraryPath() ; }
54   
55   public long getStartTime() { return mxbean_.getStartTime() ; }
56   public long getUptime() { return mxbean_.getUptime() ; }
57   
58   public boolean isManagementSupported() { return true ; }
59   
60   public String JavaDoc getSystemPropertiesAsText() {
61     StringBuffer JavaDoc b = new StringBuffer JavaDoc() ;
62     Iterator i = System.getProperties().entrySet().iterator() ;
63     while(i.hasNext()) {
64       Map.Entry entry = (Map.Entry)i.next() ;
65       b.append(entry.getKey()).append("=").append(entry.getValue()).append("\n") ;
66     }
67     return b.toString() ;
68   }
69   
70   public void start() {}
71   public void stop() {}
72  
73   public String JavaDoc toString() {
74     StringBuilder JavaDoc b = new StringBuilder JavaDoc() ;
75     b.append("Name: ").append(getName()).append("\n") ;
76     b.append("Specification Name: ").append(getSpecName()).append("\n") ;
77     b.append("Specification Vendor: ").append(getSpecVendor()).append("\n") ;
78     b.append("Specification Version: ").append(getSpecVersion()).append("\n") ;
79     b.append("Management Spec Version: ").append(getManagementSpecVersion()).append("\n\n") ;
80     
81     b.append("Virtual Machine Name: ").append(getVmName()).append("\n") ;
82     b.append("Virtual Machine Vendor: ").append(getVmVendor()).append("\n") ;
83     b.append("Virtual Machine Version: ").append(getVmVersion()).append("\n\n") ;
84     
85     b.append("Input Arguments: ").append(getInputArguments()).append("\n") ;
86     b.append("System Properties: ").append(getSystemProperties()).append("\n\n") ;
87     
88     b.append("Boot Class Path Support: ").append(getBootClassPathSupported()).append("\n") ;
89     b.append("Boot Class Path: ").append(getBootClassPath()).append("\n") ;
90     b.append("Class Path: ").append(getClassPath()).append("\n") ;
91     b.append("Library Path: ").append(getLibraryPath()).append("\n\n") ;
92     
93     b.append("Start Time: ").append(new Date(getStartTime())).append("\n") ;
94     b.append("Up Time: ").append(getUptime()/(1000 * 60)).append("min\n") ;
95     return b.toString() ;
96   }
97 }
Popular Tags