001: /*
002: * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.management;
027:
028: import java.lang.management.RuntimeMXBean;
029:
030: import java.util.List;
031: import java.util.HashMap;
032: import java.util.Map;
033: import java.util.Set;
034: import java.util.Properties;
035: import javax.management.openmbean.CompositeData;
036: import javax.management.openmbean.CompositeDataSupport;
037: import javax.management.openmbean.CompositeType;
038: import javax.management.openmbean.OpenType;
039: import javax.management.openmbean.SimpleType;
040: import javax.management.openmbean.OpenDataException;
041:
042: /**
043: * Implementation class for the runtime subsystem.
044: * Standard and committed hotspot-specific metrics if any.
045: *
046: * ManagementFactory.getRuntimeMXBean() returns an instance
047: * of this class.
048: */
049: class RuntimeImpl implements RuntimeMXBean {
050:
051: private final VMManagement jvm;
052: private final long vmStartupTime;
053:
054: /**
055: * Constructor of RuntimeImpl class.
056: */
057: RuntimeImpl(VMManagement vm) {
058: this .jvm = vm;
059: this .vmStartupTime = jvm.getStartupTime();
060: }
061:
062: public String getName() {
063: return jvm.getVmId();
064: }
065:
066: public String getManagementSpecVersion() {
067: return jvm.getManagementVersion();
068: }
069:
070: public String getVmName() {
071: return jvm.getVmName();
072: }
073:
074: public String getVmVendor() {
075: return jvm.getVmVendor();
076: }
077:
078: public String getVmVersion() {
079: return jvm.getVmVersion();
080: }
081:
082: public String getSpecName() {
083: return jvm.getVmSpecName();
084: }
085:
086: public String getSpecVendor() {
087: return jvm.getVmSpecVendor();
088: }
089:
090: public String getSpecVersion() {
091: return jvm.getVmSpecVersion();
092: }
093:
094: public String getClassPath() {
095: return jvm.getClassPath();
096: }
097:
098: public String getLibraryPath() {
099: return jvm.getLibraryPath();
100: }
101:
102: public String getBootClassPath() {
103: if (!isBootClassPathSupported()) {
104: throw new UnsupportedOperationException(
105: "Boot class path mechanism is not supported");
106: }
107: ManagementFactory.checkMonitorAccess();
108: return jvm.getBootClassPath();
109: }
110:
111: public List<String> getInputArguments() {
112: ManagementFactory.checkMonitorAccess();
113: return jvm.getVmArguments();
114: }
115:
116: public long getUptime() {
117: long current = System.currentTimeMillis();
118:
119: // TODO: If called from client side when we support
120: // MBean proxy to read performance counters from shared memory,
121: // need to check if the monitored VM exitd.
122: return (current - vmStartupTime);
123: }
124:
125: public long getStartTime() {
126: return vmStartupTime;
127: }
128:
129: public boolean isBootClassPathSupported() {
130: return jvm.isBootClassPathSupported();
131: }
132:
133: public Map<String, String> getSystemProperties() {
134: Properties sysProps = System.getProperties();
135: Map<String, String> map = new HashMap<String, String>();
136:
137: // Properties.entrySet() does not include the entries in
138: // the default properties. So use Properties.stringPropertyNames()
139: // to get the list of property keys including the default ones.
140: Set<String> keys = sysProps.stringPropertyNames();
141: for (String k : keys) {
142: String value = sysProps.getProperty(k);
143: map.put(k, value);
144: }
145:
146: return map;
147: }
148: }
|