feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,694 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.util.Hashtable;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.lang.ref.WeakReference;
// jmx imports
//
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.InstanceAlreadyExistsException;
import javax.management.NotificationEmitter;
import javax.management.NotificationListener;
import javax.management.Notification;
import javax.management.ListenerNotFoundException;
import javax.management.openmbean.CompositeData;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.daemon.SnmpAdaptorServer;
import com.sun.jmx.snmp.SnmpPeer;
import com.sun.jmx.snmp.SnmpParameters;
import com.sun.jmx.snmp.SnmpOidTable;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpVarBindList;
import com.sun.jmx.snmp.SnmpVarBind;
import com.sun.jmx.snmp.SnmpCounter;
import com.sun.jmx.snmp.SnmpCounter64;
import com.sun.jmx.snmp.SnmpString;
import com.sun.jmx.snmp.SnmpInt;
import com.sun.jmx.snmp.Enumerated;
import com.sun.jmx.snmp.agent.SnmpMibTable;
import sun.management.snmp.jvmmib.JVM_MANAGEMENT_MIBOidTable;
import sun.management.snmp.jvmmib.JVM_MANAGEMENT_MIB;
import sun.management.snmp.jvmmib.JvmMemoryMeta;
import sun.management.snmp.jvmmib.JvmThreadingMeta;
import sun.management.snmp.jvmmib.JvmRuntimeMeta;
import sun.management.snmp.jvmmib.JvmClassLoadingMeta;
import sun.management.snmp.jvmmib.JvmCompilationMeta;
import sun.management.snmp.util.MibLogger;
import sun.management.snmp.util.SnmpCachedData;
import sun.management.snmp.util.SnmpTableHandler;
//java management imports
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryNotificationInfo;
import java.lang.management.MemoryType;
public class JVM_MANAGEMENT_MIB_IMPL extends JVM_MANAGEMENT_MIB {
private static final long serialVersionUID = -8104825586888859831L;
private static final MibLogger log =
new MibLogger(JVM_MANAGEMENT_MIB_IMPL.class);
private static WeakReference<SnmpOidTable> tableRef;
public static SnmpOidTable getOidTable() {
SnmpOidTable table = null;
if(tableRef == null) {
table = new JVM_MANAGEMENT_MIBOidTable();
tableRef = new WeakReference<>(table);
return table;
}
table = tableRef.get();
if(table == null) {
table = new JVM_MANAGEMENT_MIBOidTable();
tableRef = new WeakReference<>(table);
}
return table;
}
/**
* Handler waiting for memory <CODE>Notification</CODE>.
* Translate each JMX notification in SNMP trap.
*/
private class NotificationHandler implements NotificationListener {
public void handleNotification(Notification notification,
Object handback) {
log.debug("handleNotification", "Received notification [ " +
notification.getType() + "]");
String type = notification.getType();
if (type.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED) ||
type.equals(MemoryNotificationInfo.
MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
MemoryNotificationInfo minfo = MemoryNotificationInfo.
from((CompositeData) notification.getUserData());
SnmpCounter64 count = new SnmpCounter64(minfo.getCount());
SnmpCounter64 used =
new SnmpCounter64(minfo.getUsage().getUsed());
SnmpString poolName = new SnmpString(minfo.getPoolName());
SnmpOid entryIndex =
getJvmMemPoolEntryIndex(minfo.getPoolName());
if (entryIndex == null) {
log.error("handleNotification",
"Error: Can't find entry index for Memory Pool: "
+ minfo.getPoolName() +": " +
"No trap emitted for " + type);
return;
}
SnmpOid trap = null;
final SnmpOidTable mibTable = getOidTable();
try {
SnmpOid usedOid = null;
SnmpOid countOid = null;
if (type.equals(MemoryNotificationInfo.
MEMORY_THRESHOLD_EXCEEDED)) {
trap = new SnmpOid(mibTable.
resolveVarName("jvmLowMemoryPoolUsageNotif").getOid());
usedOid =
new SnmpOid(mibTable.
resolveVarName("jvmMemPoolUsed").getOid() +
"." + entryIndex);
countOid =
new SnmpOid(mibTable.
resolveVarName("jvmMemPoolThreshdCount").getOid()
+ "." + entryIndex);
} else if (type.equals(MemoryNotificationInfo.
MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
trap = new SnmpOid(mibTable.
resolveVarName("jvmLowMemoryPoolCollectNotif").
getOid());
usedOid =
new SnmpOid(mibTable.
resolveVarName("jvmMemPoolCollectUsed").getOid() +
"." + entryIndex);
countOid =
new SnmpOid(mibTable.
resolveVarName("jvmMemPoolCollectThreshdCount").
getOid() +
"." + entryIndex);
}
//Datas
SnmpVarBindList list = new SnmpVarBindList();
SnmpOid poolNameOid =
new SnmpOid(mibTable.
resolveVarName("jvmMemPoolName").getOid() +
"." + entryIndex);
SnmpVarBind varCount = new SnmpVarBind(countOid, count);
SnmpVarBind varUsed = new SnmpVarBind(usedOid, used);
SnmpVarBind varPoolName = new SnmpVarBind(poolNameOid,
poolName);
list.add(varPoolName);
list.add(varCount);
list.add(varUsed);
sendTrap(trap, list);
}catch(Exception e) {
log.error("handleNotification",
"Exception occurred : " + e);
}
}
}
}
/**
* List of notification targets.
*/
private ArrayList<NotificationTarget> notificationTargets =
new ArrayList<>();
private final NotificationEmitter emitter;
private final NotificationHandler handler;
/**
* Instantiate a JVM MIB intrusmentation.
* A <CODE>NotificationListener</CODE> is added to the <CODE>MemoryMXBean</CODE>
* <CODE>NotificationEmitter</CODE>
*/
public JVM_MANAGEMENT_MIB_IMPL() {
handler = new NotificationHandler();
emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
emitter.addNotificationListener(handler, null, null);
}
private synchronized void sendTrap(SnmpOid trap, SnmpVarBindList list) {
final Iterator<NotificationTarget> iterator = notificationTargets.iterator();
final SnmpAdaptorServer adaptor =
(SnmpAdaptorServer) getSnmpAdaptor();
if (adaptor == null) {
log.error("sendTrap", "Cannot send trap: adaptor is null.");
return;
}
if (!adaptor.isActive()) {
log.config("sendTrap", "Adaptor is not active: trap not sent.");
return;
}
while(iterator.hasNext()) {
NotificationTarget target = null;
try {
target = iterator.next();
SnmpPeer peer =
new SnmpPeer(target.getAddress(), target.getPort());
SnmpParameters p = new SnmpParameters();
p.setRdCommunity(target.getCommunity());
peer.setParams(p);
log.debug("handleNotification", "Sending trap to " +
target.getAddress() + ":" + target.getPort());
adaptor.snmpV2Trap(peer, trap, list, null);
}catch(Exception e) {
log.error("sendTrap",
"Exception occurred while sending trap to [" +
target + "]. Exception : " + e);
log.debug("sendTrap",e);
}
}
}
/**
* Add a notification target.
* @param target The target to add
* @throws IllegalArgumentException If target parameter is null.
*/
public synchronized void addTarget(NotificationTarget target)
throws IllegalArgumentException {
if(target == null)
throw new IllegalArgumentException("Target is null");
notificationTargets.add(target);
}
/**
* Remove notification listener.
*/
public void terminate() {
try {
emitter.removeNotificationListener(handler);
}catch(ListenerNotFoundException e) {
log.error("terminate", "Listener Not found : " + e);
}
}
/**
* Add notification targets.
* @param targets A list of
* <CODE>sun.management.snmp.jvminstr.NotificationTarget</CODE>
* @throws IllegalArgumentException If targets parameter is null.
*/
public synchronized void addTargets(List<NotificationTarget> targets)
throws IllegalArgumentException {
if(targets == null)
throw new IllegalArgumentException("Target list is null");
notificationTargets.addAll(targets);
}
/**
* Factory method for "JvmMemory" group MBean.
*
* You can redefine this method if you need to replace the default
* generated MBean class with your own customized class.
*
* @param groupName Name of the group ("JvmMemory")
* @param groupOid OID of this group
* @param groupObjname ObjectName for this group (may be null)
* @param server MBeanServer for this group (may be null)
*
* @return An instance of the MBean class generated for the
* "JvmMemory" group (JvmMemory)
*
* Note that when using standard metadata,
* the returned object must implement the "JvmMemoryMBean"
* interface.
**/
protected Object createJvmMemoryMBean(String groupName,
String groupOid, ObjectName groupObjname,
MBeanServer server) {
// Note that when using standard metadata,
// the returned object must implement the "JvmMemoryMBean"
// interface.
//
if (server != null)
return new JvmMemoryImpl(this,server);
else
return new JvmMemoryImpl(this);
}
/**
* Factory method for "JvmMemory" group metadata class.
*
* You can redefine this method if you need to replace the default
* generated metadata class with your own customized class.
*
* @param groupName Name of the group ("JvmMemory")
* @param groupOid OID of this group
* @param groupObjname ObjectName for this group (may be null)
* @param server MBeanServer for this group (may be null)
*
* @return An instance of the metadata class generated for the
* "JvmMemory" group (JvmMemoryMeta)
*
**/
protected JvmMemoryMeta createJvmMemoryMetaNode(String groupName,
String groupOid,
ObjectName groupObjname,
MBeanServer server) {
return new JvmMemoryMetaImpl(this, objectserver);
}
/**
* Factory method for "JvmThreading" group metadata class.
*
* You can redefine this method if you need to replace the default
* generated metadata class with your own customized class.
*
* @param groupName Name of the group ("JvmThreading")
* @param groupOid OID of this group
* @param groupObjname ObjectName for this group (may be null)
* @param server MBeanServer for this group (may be null)
*
* @return An instance of the metadata class generated for the
* "JvmThreading" group (JvmThreadingMeta)
*
**/
protected JvmThreadingMeta createJvmThreadingMetaNode(String groupName,
String groupOid,
ObjectName groupObjname,
MBeanServer server) {
return new JvmThreadingMetaImpl(this, objectserver);
}
/**
* Factory method for "JvmThreading" group MBean.
*
* You can redefine this method if you need to replace the default
* generated MBean class with your own customized class.
*
* @param groupName Name of the group ("JvmThreading")
* @param groupOid OID of this group
* @param groupObjname ObjectName for this group (may be null)
* @param server MBeanServer for this group (may be null)
*
* @return An instance of the MBean class generated for the
* "JvmThreading" group (JvmThreading)
*
* Note that when using standard metadata,
* the returned object must implement the "JvmThreadingMBean"
* interface.
**/
protected Object createJvmThreadingMBean(String groupName,
String groupOid,
ObjectName groupObjname,
MBeanServer server) {
// Note that when using standard metadata,
// the returned object must implement the "JvmThreadingMBean"
// interface.
//
if (server != null)
return new JvmThreadingImpl(this,server);
else
return new JvmThreadingImpl(this);
}
/**
* Factory method for "JvmRuntime" group metadata class.
*
* You can redefine this method if you need to replace the default
* generated metadata class with your own customized class.
*
* @param groupName Name of the group ("JvmRuntime")
* @param groupOid OID of this group
* @param groupObjname ObjectName for this group (may be null)
* @param server MBeanServer for this group (may be null)
*
* @return An instance of the metadata class generated for the
* "JvmRuntime" group (JvmRuntimeMeta)
*
**/
protected JvmRuntimeMeta createJvmRuntimeMetaNode(String groupName,
String groupOid,
ObjectName groupObjname,
MBeanServer server) {
return new JvmRuntimeMetaImpl(this, objectserver);
}
/**
* Factory method for "JvmRuntime" group MBean.
*
* You can redefine this method if you need to replace the default
* generated MBean class with your own customized class.
*
* @param groupName Name of the group ("JvmRuntime")
* @param groupOid OID of this group
* @param groupObjname ObjectName for this group (may be null)
* @param server MBeanServer for this group (may be null)
*
* @return An instance of the MBean class generated for the
* "JvmRuntime" group (JvmRuntime)
*
* Note that when using standard metadata,
* the returned object must implement the "JvmRuntimeMBean"
* interface.
**/
protected Object createJvmRuntimeMBean(String groupName,
String groupOid,
ObjectName groupObjname,
MBeanServer server) {
// Note that when using standard metadata,
// the returned object must implement the "JvmRuntimeMBean"
// interface.
//
if (server != null)
return new JvmRuntimeImpl(this,server);
else
return new JvmRuntimeImpl(this);
}
/**
* Factory method for "JvmCompilation" group metadata class.
*
* You can redefine this method if you need to replace the default
* generated metadata class with your own customized class.
*
* @param groupName Name of the group ("JvmCompilation")
* @param groupOid OID of this group
* @param groupObjname ObjectName for this group (may be null)
* @param server MBeanServer for this group (may be null)
*
* @return An instance of the metadata class generated for the
* "JvmCompilation" group (JvmCompilationMeta)
*
**/
protected JvmCompilationMeta
createJvmCompilationMetaNode(String groupName,
String groupOid,
ObjectName groupObjname,
MBeanServer server) {
// If there is no compilation system, the jvmCompilation will not
// be instantiated.
//
if (ManagementFactory.getCompilationMXBean() == null) return null;
return super.createJvmCompilationMetaNode(groupName,groupOid,
groupObjname,server);
}
/**
* Factory method for "JvmCompilation" group MBean.
*
* You can redefine this method if you need to replace the default
* generated MBean class with your own customized class.
*
* @param groupName Name of the group ("JvmCompilation")
* @param groupOid OID of this group
* @param groupObjname ObjectName for this group (may be null)
* @param server MBeanServer for this group (may be null)
*
* @return An instance of the MBean class generated for the
* "JvmCompilation" group (JvmCompilation)
*
* Note that when using standard metadata,
* the returned object must implement the "JvmCompilationMBean"
* interface.
**/
protected Object createJvmCompilationMBean(String groupName,
String groupOid, ObjectName groupObjname, MBeanServer server) {
// Note that when using standard metadata,
// the returned object must implement the "JvmCompilationMBean"
// interface.
//
if (server != null)
return new JvmCompilationImpl(this,server);
else
return new JvmCompilationImpl(this);
}
/**
* Factory method for "JvmOS" group MBean.
*
* You can redefine this method if you need to replace the default
* generated MBean class with your own customized class.
*
* @param groupName Name of the group ("JvmOS")
* @param groupOid OID of this group
* @param groupObjname ObjectName for this group (may be null)
* @param server MBeanServer for this group (may be null)
*
* @return An instance of the MBean class generated for the
* "JvmOS" group (JvmOS)
*
* Note that when using standard metadata,
* the returned object must implement the "JvmOSMBean"
* interface.
**/
protected Object createJvmOSMBean(String groupName,
String groupOid, ObjectName groupObjname, MBeanServer server) {
// Note that when using standard metadata,
// the returned object must implement the "JvmOSMBean"
// interface.
//
if (server != null)
return new JvmOSImpl(this,server);
else
return new JvmOSImpl(this);
}
/**
* Factory method for "JvmClassLoading" group MBean.
*
* You can redefine this method if you need to replace the default
* generated MBean class with your own customized class.
*
* @param groupName Name of the group ("JvmClassLoading")
* @param groupOid OID of this group
* @param groupObjname ObjectName for this group (may be null)
* @param server MBeanServer for this group (may be null)
*
* @return An instance of the MBean class generated for the
* "JvmClassLoading" group (JvmClassLoading)
*
* Note that when using standard metadata,
* the returned object must implement the "JvmClassLoadingMBean"
* interface.
**/
protected Object createJvmClassLoadingMBean(String groupName,
String groupOid,
ObjectName groupObjname,
MBeanServer server) {
// Note that when using standard metadata,
// the returned object must implement the "JvmClassLoadingMBean"
// interface.
//
if (server != null)
return new JvmClassLoadingImpl(this,server);
else
return new JvmClassLoadingImpl(this);
}
static String validDisplayStringTC(String str) {
if(str == null) return "";
if(str.length() > DISPLAY_STRING_MAX_LENGTH) {
return str.substring(0, DISPLAY_STRING_MAX_LENGTH);
}
else
return str;
}
static String validJavaObjectNameTC(String str) {
if(str == null) return "";
if(str.length() > JAVA_OBJECT_NAME_MAX_LENGTH) {
return str.substring(0, JAVA_OBJECT_NAME_MAX_LENGTH);
}
else
return str;
}
static String validPathElementTC(String str) {
if(str == null) return "";
if(str.length() > PATH_ELEMENT_MAX_LENGTH) {
return str.substring(0, PATH_ELEMENT_MAX_LENGTH);
}
else
return str;
}
static String validArgValueTC(String str) {
if(str == null) return "";
if(str.length() > ARG_VALUE_MAX_LENGTH) {
return str.substring(0, ARG_VALUE_MAX_LENGTH);
}
else
return str;
}
/**
* WARNING: This should probably be moved to JvmMemPoolTableMetaImpl
**/
private SnmpTableHandler getJvmMemPoolTableHandler(Object userData) {
final SnmpMibTable meta =
getRegisteredTableMeta("JvmMemPoolTable");
if (! (meta instanceof JvmMemPoolTableMetaImpl)) {
final String err = ((meta==null)?"No metadata for JvmMemPoolTable":
"Bad metadata class for JvmMemPoolTable: " +
meta.getClass().getName());
log.error("getJvmMemPoolTableHandler", err);
return null;
}
final JvmMemPoolTableMetaImpl memPoolTable =
(JvmMemPoolTableMetaImpl) meta;
return memPoolTable.getHandler(userData);
}
/**
* WARNING: This should probably be moved to JvmMemPoolTableMetaImpl
**/
private int findInCache(SnmpTableHandler handler,
String poolName) {
if (!(handler instanceof SnmpCachedData)) {
if (handler != null) {
final String err = "Bad class for JvmMemPoolTable datas: " +
handler.getClass().getName();
log.error("getJvmMemPoolEntry", err);
}
return -1;
}
final SnmpCachedData data = (SnmpCachedData)handler;
final int len = data.datas.length;
for (int i=0; i < data.datas.length ; i++) {
final MemoryPoolMXBean pool = (MemoryPoolMXBean) data.datas[i];
if (poolName.equals(pool.getName())) return i;
}
return -1;
}
/**
* WARNING: This should probably be moved to JvmMemPoolTableMetaImpl
**/
private SnmpOid getJvmMemPoolEntryIndex(SnmpTableHandler handler,
String poolName) {
final int index = findInCache(handler,poolName);
if (index < 0) return null;
return ((SnmpCachedData)handler).indexes[index];
}
private SnmpOid getJvmMemPoolEntryIndex(String poolName) {
return getJvmMemPoolEntryIndex(getJvmMemPoolTableHandler(null),
poolName);
}
// cache validity
//
// Should we define a property for this? Should we have different
// cache validity periods depending on which table we cache?
//
public long validity() {
return DEFAULT_CACHE_VALIDITY_PERIOD;
}
// Defined in RFC 2579
private final static int DISPLAY_STRING_MAX_LENGTH=255;
private final static int JAVA_OBJECT_NAME_MAX_LENGTH=1023;
private final static int PATH_ELEMENT_MAX_LENGTH=1023;
private final static int ARG_VALUE_MAX_LENGTH=1023;
private final static int DEFAULT_CACHE_VALIDITY_PERIOD=1000;
}

View File

@@ -0,0 +1,149 @@
/*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
import java.lang.management.ClassLoadingMXBean;
import java.lang.management.ManagementFactory;
// jmx imports
//
import javax.management.MBeanServer;
import com.sun.jmx.snmp.SnmpString;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import sun.management.snmp.jvmmib.JvmClassLoadingMBean;
import sun.management.snmp.jvmmib.EnumJvmClassesVerboseLevel;
import sun.management.snmp.util.MibLogger;
/**
* The class is used for implementing the "JvmClassLoading" group.
*/
public class JvmClassLoadingImpl implements JvmClassLoadingMBean {
/**
* Variable for storing the value of "JvmClassesVerboseLevel".
*
* "verbose: if the -verbose:class flag is set.
* silent: otherwise.
*
* See java.management.ClassLoadingMXBean.isVerbose(),
* java.management.ClassLoadingMXBean.setVerbose()
* "
*
*/
static final EnumJvmClassesVerboseLevel JvmClassesVerboseLevelVerbose =
new EnumJvmClassesVerboseLevel("verbose");
static final EnumJvmClassesVerboseLevel JvmClassesVerboseLevelSilent =
new EnumJvmClassesVerboseLevel("silent");
/**
* Constructor for the "JvmClassLoading" group.
* If the group contains a table, the entries created through an
* SNMP SET will not be registered in Java DMK.
*/
public JvmClassLoadingImpl(SnmpMib myMib) {
}
/**
* Constructor for the "JvmClassLoading" group.
* If the group contains a table, the entries created through an SNMP SET
* will be AUTOMATICALLY REGISTERED in Java DMK.
*/
public JvmClassLoadingImpl(SnmpMib myMib, MBeanServer server) {
}
static ClassLoadingMXBean getClassLoadingMXBean() {
return ManagementFactory.getClassLoadingMXBean();
}
/**
* Getter for the "JvmClassesVerboseLevel" variable.
*/
public EnumJvmClassesVerboseLevel getJvmClassesVerboseLevel()
throws SnmpStatusException {
if(getClassLoadingMXBean().isVerbose())
return JvmClassesVerboseLevelVerbose;
else
return JvmClassesVerboseLevelSilent;
}
/**
* Setter for the "JvmClassesVerboseLevel" variable.
*/
public void setJvmClassesVerboseLevel(EnumJvmClassesVerboseLevel x)
throws SnmpStatusException {
final boolean verbose;
if (JvmClassesVerboseLevelVerbose.equals(x)) verbose=true;
else if (JvmClassesVerboseLevelSilent.equals(x)) verbose=false;
// Should never happen, this case is handled by
// checkJvmClassesVerboseLevel();
else throw new
SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
getClassLoadingMXBean().setVerbose(verbose);
}
/**
* Checker for the "JvmClassesVerboseLevel" variable.
*/
public void checkJvmClassesVerboseLevel(EnumJvmClassesVerboseLevel x)
throws SnmpStatusException {
//
// Add your own checking policy.
//
if (JvmClassesVerboseLevelVerbose.equals(x)) return;
if (JvmClassesVerboseLevelSilent.equals(x)) return;
throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
}
/**
* Getter for the "JvmClassesUnloadedCount" variable.
*/
public Long getJvmClassesUnloadedCount() throws SnmpStatusException {
return new Long(getClassLoadingMXBean().getUnloadedClassCount());
}
/**
* Getter for the "JvmClassesTotalLoadedCount" variable.
*/
public Long getJvmClassesTotalLoadedCount() throws SnmpStatusException {
return new Long(getClassLoadingMXBean().getTotalLoadedClassCount());
}
/**
* Getter for the "JvmClassesLoadedCount" variable.
*/
public Long getJvmClassesLoadedCount() throws SnmpStatusException {
return new Long(getClassLoadingMXBean().getLoadedClassCount());
}
}

View File

@@ -0,0 +1,129 @@
/*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.lang.management.CompilationMXBean;
// jmx imports
//
import javax.management.MBeanServer;
import com.sun.jmx.snmp.SnmpString;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import sun.management.snmp.jvmmib.JvmCompilationMBean;
import sun.management.snmp.jvmmib.EnumJvmJITCompilerTimeMonitoring;
import sun.management.snmp.util.MibLogger;
/**
* The class is used for implementing the "JvmCompilation" group.
*/
public class JvmCompilationImpl implements JvmCompilationMBean {
/**
* Variable for storing the value of "JvmJITCompilerTimeMonitoring".
*
* "Indicates whether the Java virtual machine supports
* compilation time monitoring.
*
* See java.management.CompilationMXBean.
* isCompilationTimeMonitoringSupported()
* "
*
*/
static final EnumJvmJITCompilerTimeMonitoring
JvmJITCompilerTimeMonitoringSupported =
new EnumJvmJITCompilerTimeMonitoring("supported");
static final EnumJvmJITCompilerTimeMonitoring
JvmJITCompilerTimeMonitoringUnsupported =
new EnumJvmJITCompilerTimeMonitoring("unsupported");
/**
* Constructor for the "JvmCompilation" group.
* If the group contains a table, the entries created through an SNMP SET
* will not be registered in Java DMK.
*/
public JvmCompilationImpl(SnmpMib myMib) {
}
/**
* Constructor for the "JvmCompilation" group.
* If the group contains a table, the entries created through an SNMP
* SET will be AUTOMATICALLY REGISTERED in Java DMK.
*/
public JvmCompilationImpl(SnmpMib myMib, MBeanServer server) {
}
private static CompilationMXBean getCompilationMXBean() {
return ManagementFactory.getCompilationMXBean();
}
/**
* Getter for the "JvmJITCompilerTimeMonitoring" variable.
*/
public EnumJvmJITCompilerTimeMonitoring getJvmJITCompilerTimeMonitoring()
throws SnmpStatusException {
// If we reach this point, then we can safely assume that
// getCompilationMXBean() will not return null, because this
// object will not be instantiated when there is no compilation
// system (see JVM_MANAGEMENT_MIB_IMPL).
//
if(getCompilationMXBean().isCompilationTimeMonitoringSupported())
return JvmJITCompilerTimeMonitoringSupported;
else
return JvmJITCompilerTimeMonitoringUnsupported;
}
/**
* Getter for the "JvmJITCompilerTimeMs" variable.
*/
public Long getJvmJITCompilerTimeMs() throws SnmpStatusException {
final long t;
if(getCompilationMXBean().isCompilationTimeMonitoringSupported())
t = getCompilationMXBean().getTotalCompilationTime();
else
t = 0;
return new Long(t);
}
/**
* Getter for the "JvmJITCompilerName" variable.
*/
public String getJvmJITCompilerName() throws SnmpStatusException {
return JVM_MANAGEMENT_MIB_IMPL.
validJavaObjectNameTC(getCompilationMXBean().getName());
}
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
// jmx imports
//
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import java.lang.management.GarbageCollectorMXBean;
import sun.management.snmp.jvmmib.JvmMemGCEntryMBean;
import sun.management.snmp.util.MibLogger;
/**
* The class is used for implementing the "JvmMemGCEntry" group.
*/
public class JvmMemGCEntryImpl implements JvmMemGCEntryMBean {
/**
* Variable for storing the value of "JvmMemManagerIndex".
*
* "An index opaquely computed by the agent and which uniquely
* identifies a Memory Manager."
*
*/
protected final int JvmMemManagerIndex;
protected final GarbageCollectorMXBean gcm;
/**
* Constructor for the "JvmMemGCEntry" group.
*/
public JvmMemGCEntryImpl(GarbageCollectorMXBean gcm, int index) {
this.gcm=gcm;
this.JvmMemManagerIndex = index;
}
/**
* Getter for the "JvmMemGCTimeMs" variable.
*/
// Don't bother to uses the request contextual cache for this.
public Long getJvmMemGCTimeMs() throws SnmpStatusException {
return new Long(gcm.getCollectionTime());
}
/**
* Getter for the "JvmMemGCCount" variable.
*/
// Don't bother to uses the request contextual cache for this.
public Long getJvmMemGCCount() throws SnmpStatusException {
return new Long(gcm.getCollectionCount());
}
/**
* Getter for the "JvmMemManagerIndex" variable.
*/
public Integer getJvmMemManagerIndex() throws SnmpStatusException {
return new Integer(JvmMemManagerIndex);
}
}

View File

@@ -0,0 +1,362 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
// jmx imports
//
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
import java.lang.management.MemoryManagerMXBean;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import sun.management.snmp.jvmmib.JvmMemGCTableMeta;
import sun.management.snmp.util.SnmpCachedData;
import sun.management.snmp.util.SnmpTableCache;
import sun.management.snmp.util.SnmpTableHandler;
import sun.management.snmp.util.MibLogger;
import sun.management.snmp.util.JvmContextFactory;
/**
* The class is used for implementing the "JvmMemGCTable" table.
*/
public class JvmMemGCTableMetaImpl extends JvmMemGCTableMeta {
static final long serialVersionUID = 8250461197108867607L;
/**
* This class acts as a filter over the SnmpTableHandler
* used for the JvmMemoryManagerTable. It filters out
* (skip) all MemoryManagerMXBean that are not instances of
* GarbageCollectorMXBean so that only Garbage Collectors are
* seen. This is a better solution than relying on
* ManagementFactory.getGarbageCollectorMXBeans() because it makes it
* possible to guarantee the consistency betwen the MemoryManager table
* and the GCTable since both will be sharing the same cache.
**/
protected static class GCTableFilter {
/**
* Returns the index that immediately follows the given
* <var>index</var>. The returned index is strictly greater
* than the given <var>index</var>, and is contained in the table.
* <br>If the given <var>index</var> is null, returns the first
* index in the table.
* <br>If there are no index after the given <var>index</var>,
* returns null.
* This method is an optimization for the case where the
* SnmpTableHandler is in fact an instance of SnmpCachedData.
**/
public SnmpOid getNext(SnmpCachedData datas, SnmpOid index) {
final boolean dbg = log.isDebugOn();
// We're going to loop until we find an instance of
// GarbageCollectorMXBean. First we attempt to find
// the next element whose OID follows the given index.
// If `index' is null, the insertion point is -1
// (the next is 0 = -insertion - 1)
//
final int insertion = (index==null)?-1:datas.find(index);
if (dbg) log.debug("GCTableFilter","oid="+index+
" at insertion="+insertion);
int next;
if (insertion > -1) next = insertion+1;
else next = -insertion -1;
// Now `next' points to the element that imediately
// follows the given `index'. We're going to loop
// through the table, starting at `next' (included),
// and return the first element which is an instance
// of GarbageCollectorMXBean.
//
for (;next<datas.indexes.length;next++) {
if (dbg) log.debug("GCTableFilter","next="+next);
final Object value = datas.datas[next];
if (dbg) log.debug("GCTableFilter","value["+next+"]=" +
((MemoryManagerMXBean)value).getName());
if (value instanceof GarbageCollectorMXBean) {
// That's the next: return it.
if (dbg) log.debug("GCTableFilter",
((MemoryManagerMXBean)value).getName() +
" is a GarbageCollectorMXBean.");
return datas.indexes[next];
}
if (dbg) log.debug("GCTableFilter",
((MemoryManagerMXBean)value).getName() +
" is not a GarbageCollectorMXBean: " +
value.getClass().getName());
// skip to next index...
}
return null;
}
/**
* Returns the index that immediately follows the given
* <var>index</var>. The returned index is strictly greater
* than the given <var>index</var>, and is contained in the table.
* <br>If the given <var>index</var> is null, returns the first
* index in the table.
* <br>If there are no index after the given <var>index</var>,
* returns null.
**/
public SnmpOid getNext(SnmpTableHandler handler, SnmpOid index) {
// try to call the optimized method
if (handler instanceof SnmpCachedData)
return getNext((SnmpCachedData)handler, index);
// too bad - revert to non-optimized generic algorithm
SnmpOid next = index;
do {
next = handler.getNext(next);
final Object value = handler.getData(next);
if (value instanceof GarbageCollectorMXBean)
// That's the next! return it
return next;
// skip to next index...
} while (next != null);
return null;
}
/**
* Returns the data associated with the given index.
* If the given index is not found, null is returned.
* Note that returning null does not necessarily means that
* the index was not found.
**/
public Object getData(SnmpTableHandler handler, SnmpOid index) {
final Object value = handler.getData(index);
if (value instanceof GarbageCollectorMXBean) return value;
// Behaves as if there was nothing at this index...
//
return null;
}
/**
* Returns true if the given <var>index</var> is present.
**/
public boolean contains(SnmpTableHandler handler, SnmpOid index) {
if (handler.getData(index) instanceof GarbageCollectorMXBean)
return true;
// Behaves as if there was nothing at this index...
//
return false;
}
}
private transient JvmMemManagerTableMetaImpl managers = null;
private static GCTableFilter filter = new GCTableFilter();
/**
* Constructor for the table. Initialize metadata for "JvmMemGCTableMeta".
*/
public JvmMemGCTableMetaImpl(SnmpMib myMib,
SnmpStandardObjectServer objserv) {
super(myMib,objserv);
}
// Returns a pointer to the JvmMemManager meta node - we're going
// to reuse its SnmpTableHandler by filtering out all that is
// not a GarbageCollectorMXBean.
private final JvmMemManagerTableMetaImpl getManagers(SnmpMib mib) {
if (managers == null) {
managers = (JvmMemManagerTableMetaImpl)
mib.getRegisteredTableMeta("JvmMemManagerTable");
}
return managers;
}
/**
* Returns the JvmMemManagerTable SnmpTableHandler
**/
protected SnmpTableHandler getHandler(Object userData) {
JvmMemManagerTableMetaImpl managerTable= getManagers(theMib);
return managerTable.getHandler(userData);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(Object userData)
throws SnmpStatusException {
// null means get the first OID.
return getNextOid(null,userData);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(SnmpOid oid, Object userData)
throws SnmpStatusException {
final boolean dbg = log.isDebugOn();
try {
if (dbg) log.debug("getNextOid", "previous=" + oid);
// Get the data handler.
//
SnmpTableHandler handler = getHandler(userData);
if (handler == null) {
// This should never happen.
// If we get here it's a bug.
//
if (dbg) log.debug("getNextOid", "handler is null!");
throw new
SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the next oid, using the GC filter.
//
final SnmpOid next = filter.getNext(handler,oid);
if (dbg) log.debug("getNextOid", "next=" + next);
// if next is null: we reached the end of the table.
//
if (next == null)
throw new
SnmpStatusException(SnmpStatusException.noSuchInstance);
return next;
} catch (RuntimeException x) {
// debug. This should never happen.
//
if (dbg) log.debug("getNextOid",x);
throw x;
}
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected boolean contains(SnmpOid oid, Object userData) {
// Get the handler.
//
SnmpTableHandler handler = getHandler(userData);
// handler should never be null.
//
if (handler == null)
return false;
return filter.contains(handler,oid);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
public Object getEntry(SnmpOid oid)
throws SnmpStatusException {
if (oid == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// Get the request contextual cache (userData).
//
final Map<Object, Object> m = JvmContextFactory.getUserData();
// First look in the request contextual cache: maybe we've already
// created this entry...
//
// We know in the case of this table that the index is an integer,
// it is thus the first OID arc of the index OID.
//
final long index = oid.getOidArc(0);
// We're going to use this name to store/retrieve the entry in
// the request contextual cache.
//
// Revisit: Probably better programming to put all these strings
// in some interface.
//
final String entryTag = ((m==null)?null:("JvmMemGCTable.entry." +
index));
// If the entry is in the cache, simply return it.
//
if (m != null) {
final Object entry = m.get(entryTag);
if (entry != null) return entry;
}
// Entry was not in request cache. Make a new one.
//
// Get the data hanler.
//
SnmpTableHandler handler = getHandler(m);
// handler should never be null.
//
if (handler == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// Use the filter to retrieve only GarabageCollectorMBean data.
//
final Object data = filter.getData(handler,oid);
// data may be null if the OID we were given is not valid.
// (e.g. it identifies a MemoryManager which is not a
// GarbageCollector)
//
if (data == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// Make a new entryy (transient object that will be kept only
// for the duration of the request.
//
final Object entry =
new JvmMemGCEntryImpl((GarbageCollectorMXBean)data,(int)index);
// Put the entry in the request cache in case we need it later
// in the processing of the request. Note that we could have
// optimized this by making JvmMemGCEntryImpl extend
// JvmMemManagerEntryImpl, and then make sure that
// JvmMemManagerTableMetaImpl creates an instance of JvmMemGCEntryImpl
// instead of JvmMemManagerEntryImpl when the associated data is
// an instance of GarbageCollectorMXBean. This would have made it
// possible to share the transient entry object.
// As it is, we may have two transient objects that points to
// the same underlying MemoryManagerMXBean (which is definitely
// not a problem - but is only a small dysatisfaction)
//
if (m != null && entry != null) {
m.put(entryTag,entry);
}
return entry;
}
static final MibLogger log = new MibLogger(JvmMemGCTableMetaImpl.class);
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
// jmx imports
//
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import java.lang.management.MemoryManagerMXBean;
import sun.management.snmp.jvmmib.JvmMemManagerEntryMBean;
import sun.management.snmp.jvmmib.EnumJvmMemManagerState;
/**
* The class is used for implementing the "JvmMemManagerEntry" group.
* The group is defined with the following
*/
public class JvmMemManagerEntryImpl implements JvmMemManagerEntryMBean {
/**
* Variable for storing the value of "JvmMemManagerIndex".
*
* "An index opaquely computed by the agent and which uniquely
* identifies a Memory Manager."
*
*/
protected final int JvmMemManagerIndex;
protected MemoryManagerMXBean manager;
/**
* Constructor for the "JvmMemManagerEntry" group.
*/
public JvmMemManagerEntryImpl(MemoryManagerMXBean m, int myindex) {
manager = m;
JvmMemManagerIndex = myindex;
}
/**
* Getter for the "JvmMemManagerName" variable.
*/
public String getJvmMemManagerName() throws SnmpStatusException {
return JVM_MANAGEMENT_MIB_IMPL.
validJavaObjectNameTC(manager.getName());
}
/**
* Getter for the "JvmMemManagerIndex" variable.
*/
public Integer getJvmMemManagerIndex() throws SnmpStatusException {
return new Integer(JvmMemManagerIndex);
}
/**
* Getter for the "JvmMemManagerState" variable.
*/
public EnumJvmMemManagerState getJvmMemManagerState()
throws SnmpStatusException {
if (manager.isValid())
return JvmMemManagerStateValid;
else
return JvmMemManagerStateInvalid;
}
private final static EnumJvmMemManagerState JvmMemManagerStateValid =
new EnumJvmMemManagerState("valid");
private final static EnumJvmMemManagerState JvmMemManagerStateInvalid =
new EnumJvmMemManagerState("invalid");
}

View File

@@ -0,0 +1,303 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import com.sun.jmx.mbeanserver.Util;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
// jmx imports
//
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
import java.lang.management.MemoryManagerMXBean;
import java.lang.management.ManagementFactory;
import sun.management.snmp.jvmmib.JvmMemManagerTableMeta;
import sun.management.snmp.util.SnmpTableCache;
import sun.management.snmp.util.SnmpNamedListTableCache;
import sun.management.snmp.util.SnmpTableHandler;
import sun.management.snmp.util.MibLogger;
import sun.management.snmp.util.JvmContextFactory;
/**
* The class is used for implementing the "JvmMemManagerTable" table.
*
* This custom implementation show how to implement an SNMP table
* over a weak cache, recomputing the cahed data when needed.
*/
public class JvmMemManagerTableMetaImpl extends JvmMemManagerTableMeta {
static final long serialVersionUID = 36176771566817592L;
/**
* A concrete implementation of {@link SnmpNamedListTableCache}, for the
* jvmMemManagerTable.
**/
private static class JvmMemManagerTableCache
extends SnmpNamedListTableCache {
static final long serialVersionUID = 6564294074653009240L;
/**
* Create a weak cache for the jvmMemManagerTable.
* @param validity validity of the cached data, in ms.
**/
JvmMemManagerTableCache(long validity) {
this.validity = validity;
}
/**
* Use the MemoryManagerMXBean name as key.
* @param context A {@link TreeMap} as allocated by the parent
* {@link SnmpNamedListTableCache} class.
* @param rawDatas List of {@link MemoryManagerMXBean}, as
* returned by
* <code>ManagementFactory.getMemoryMBean().getMemoryManagers()</code>
* @param rank The <var>rank</var> of <var>item</var> in the list.
* @param item The <var>rank</var><super>th</super>
* <code>MemoryManagerMXBean</code> in the list.
* @return <code>((MemoryManagerMXBean)item).getName()</code>
**/
protected String getKey(Object context, List<?> rawDatas,
int rank, Object item) {
if (item == null) return null;
final String name = ((MemoryManagerMXBean)item).getName();
log.debug("getKey", "key=" + name);
return name;
}
/**
* Call <code>getTableHandler(JvmContextFactory.getUserData())</code>.
**/
public SnmpTableHandler getTableHandler() {
final Map<Object, Object> userData = JvmContextFactory.getUserData();
return getTableDatas(userData);
}
/**
* Return the key used to cache the raw data of this table.
**/
protected String getRawDatasKey() {
return "JvmMemManagerTable.getMemoryManagers";
}
/**
* Call ManagementFactory.getMemoryManagerMXBeans() to
* load the raw data of this table.
**/
protected List<MemoryManagerMXBean> loadRawDatas(Map<Object, Object> userData) {
return ManagementFactory.getMemoryManagerMXBeans();
}
}
// The weak cache for this table.
protected SnmpTableCache cache;
/**
* Constructor for the table. Initialize metadata for
* "JvmMemManagerTableMeta".
* The reference on the MBean server is updated so the entries
* created through an SNMP SET will be AUTOMATICALLY REGISTERED
* in Java DMK.
*/
public JvmMemManagerTableMetaImpl(SnmpMib myMib,
SnmpStandardObjectServer objserv) {
super(myMib,objserv);
this.cache = new
JvmMemManagerTableCache(((JVM_MANAGEMENT_MIB_IMPL)myMib).
validity());
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(Object userData)
throws SnmpStatusException {
// null means get the first OID.
return getNextOid(null,userData);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(SnmpOid oid, Object userData)
throws SnmpStatusException {
final boolean dbg = log.isDebugOn();
if (dbg) log.debug("getNextOid", "previous=" + oid);
// Get the data handler.
//
SnmpTableHandler handler = getHandler(userData);
if (handler == null) {
// This should never happen.
// If we get here it's a bug.
//
if (dbg) log.debug("getNextOid", "handler is null!");
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the next oid
//
final SnmpOid next = handler.getNext(oid);
if (dbg) log.debug("getNextOid", "next=" + next);
// if next is null: we reached the end of the table.
//
if (next == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
return next;
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected boolean contains(SnmpOid oid, Object userData) {
// Get the handler.
//
SnmpTableHandler handler = getHandler(userData);
// handler should never be null.
//
if (handler == null)
return false;
return handler.contains(oid);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
public Object getEntry(SnmpOid oid)
throws SnmpStatusException {
if (oid == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// Get the request contextual cache (userData).
//
final Map<Object, Object> m = JvmContextFactory.getUserData();
// We know in the case of this table that the index is an integer,
// it is thus the first OID arc of the index OID.
//
final long index = oid.getOidArc(0);
// We're going to use this name to store/retrieve the entry in
// the request contextual cache.
//
// Revisit: Probably better programming to put all these strings
// in some interface.
//
final String entryTag = ((m==null)?null:("JvmMemManagerTable.entry." +
index));
// If the entry is in the cache, simply return it.
//
if (m != null) {
final Object entry = m.get(entryTag);
if (entry != null) return entry;
}
// The entry was not in the cache, make a new one.
//
// Get the data hanler.
//
SnmpTableHandler handler = getHandler(m);
// handler should never be null.
//
if (handler == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// Get the data associated with our entry.
//
final Object data = handler.getData(oid);
// data may be null if the OID we were given is not valid.
//
if (data == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// make the new entry (transient object that will be kept only
// for the duration of the request.
//
final Object entry =
new JvmMemManagerEntryImpl((MemoryManagerMXBean)data,(int)index);
// Put the entry in the cache in case we need it later while processing
// the request.
//
if (m != null && entry != null) {
m.put(entryTag,entry);
}
return entry;
}
/**
* Get the SnmpTableHandler that holds the jvmMemManagerTable data.
* First look it up in the request contextual cache, and if it is
* not found, obtain it from the weak cache.
* <br>The request contextual cache will be released at the end of the
* current requests, and is used only to process this request.
* <br>The weak cache is shared by all requests, and is only
* recomputed when it is found to be obsolete.
* <br>Note that the data put in the request contextual cache is
* never considered to be obsolete, in order to preserve data
* coherency.
**/
protected SnmpTableHandler getHandler(Object userData) {
final Map<Object, Object> m;
if (userData instanceof Map) m=Util.cast(userData);
else m=null;
// Look in the contextual cache.
if (m != null) {
final SnmpTableHandler handler =
(SnmpTableHandler)m.get("JvmMemManagerTable.handler");
if (handler != null) return handler;
}
// No handler in contextual cache, make a new one.
final SnmpTableHandler handler = cache.getTableHandler();
if (m != null && handler != null )
m.put("JvmMemManagerTable.handler",handler);
return handler;
}
static final MibLogger log =
new MibLogger(JvmMemManagerTableMetaImpl.class);
}

View File

@@ -0,0 +1,105 @@
/*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// jmx imports
//
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import sun.management.snmp.jvmmib.JvmMemMgrPoolRelEntryMBean;
/**
* The class is used for implementing the "JvmMemMgrPoolRelEntry" group.
*/
public class JvmMemMgrPoolRelEntryImpl
implements JvmMemMgrPoolRelEntryMBean {
/**
* Variable for storing the value of "JvmMemManagerIndex".
*
* "An index opaquely computed by the agent and which uniquely
* identifies a Memory Manager."
*
*/
final protected int JvmMemManagerIndex;
/**
* Variable for storing the value of "JvmMemPoolIndex".
*
* "An index value opaquely computed by the agent which uniquely
* identifies a row in the jvmMemPoolTable.
* "
*
*/
final protected int JvmMemPoolIndex;
final protected String mmmName;
final protected String mpmName;
/**
* Constructor for the "JvmMemMgrPoolRelEntry" group.
*/
public JvmMemMgrPoolRelEntryImpl(String mmmName,
String mpmName,
int mmarc, int mparc) {
JvmMemManagerIndex = mmarc;
JvmMemPoolIndex = mparc;
this.mmmName = mmmName;
this.mpmName = mpmName;
}
/**
* Getter for the "JvmMemMgrRelPoolName" variable.
*/
public String getJvmMemMgrRelPoolName() throws SnmpStatusException {
return JVM_MANAGEMENT_MIB_IMPL.validJavaObjectNameTC(mpmName);
}
/**
* Getter for the "JvmMemMgrRelManagerName" variable.
*/
public String getJvmMemMgrRelManagerName() throws SnmpStatusException {
return JVM_MANAGEMENT_MIB_IMPL.validJavaObjectNameTC(mmmName);
}
/**
* Getter for the "JvmMemManagerIndex" variable.
*/
public Integer getJvmMemManagerIndex() throws SnmpStatusException {
return new Integer(JvmMemManagerIndex);
}
/**
* Getter for the "JvmMemPoolIndex" variable.
*/
public Integer getJvmMemPoolIndex() throws SnmpStatusException {
return new Integer(JvmMemPoolIndex);
}
}

View File

@@ -0,0 +1,523 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import com.sun.jmx.mbeanserver.Util;
import java.io.Serializable;
import java.util.List;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.Collections;
// jmx imports
//
import javax.management.MBeanServer;
import javax.management.ObjectName;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
import com.sun.jmx.snmp.agent.SnmpMibTable;
import java.lang.management.MemoryManagerMXBean;
import java.lang.management.MemoryPoolMXBean;
import sun.management.snmp.jvmmib.JvmMemMgrPoolRelTableMeta;
import sun.management.snmp.util.SnmpTableCache;
import sun.management.snmp.util.SnmpCachedData;
import sun.management.snmp.util.SnmpTableHandler;
import sun.management.snmp.util.MibLogger;
import sun.management.snmp.util.JvmContextFactory;
/**
* The class is used for implementing the "JvmMemMgrPoolRelTable" group.
*/
public class JvmMemMgrPoolRelTableMetaImpl extends JvmMemMgrPoolRelTableMeta
implements Serializable {
static final long serialVersionUID = 1896509775012355443L;
/**
* A concrete implementation of {@link SnmpTableCache}, for the
* jvmMemMgrPoolRelTable.
**/
private static class JvmMemMgrPoolRelTableCache
extends SnmpTableCache {
static final long serialVersionUID = 6059937161990659184L;
final private JvmMemMgrPoolRelTableMetaImpl meta;
/**
* Create a weak cache for the jvmMemMgrPoolRelTable.
* @param validity validity of the cached data, in ms.
**/
JvmMemMgrPoolRelTableCache(JvmMemMgrPoolRelTableMetaImpl meta,
long validity) {
this.validity = validity;
this.meta = meta;
}
/**
* Call <code>getTableDatas(JvmContextFactory.getUserData())</code>.
**/
public SnmpTableHandler getTableHandler() {
final Map<Object,Object> userData = JvmContextFactory.getUserData();
return getTableDatas(userData);
}
/**
* Builds a map pool-name => pool-index from the SnmpTableHandler
* of the JvmMemPoolTable.
**/
private static Map<String, SnmpOid> buildPoolIndexMap(SnmpTableHandler handler) {
// optimization...
if (handler instanceof SnmpCachedData)
return buildPoolIndexMap((SnmpCachedData)handler);
// not optimizable... too bad.
final Map<String, SnmpOid> m = new HashMap<>();
SnmpOid index=null;
while ((index = handler.getNext(index))!=null) {
final MemoryPoolMXBean mpm =
(MemoryPoolMXBean)handler.getData(index);
if (mpm == null) continue;
final String name = mpm.getName();
if (name == null) continue;
m.put(name,index);
}
return m;
}
/**
* Builds a map pool-name => pool-index from the SnmpTableHandler
* of the JvmMemPoolTable.
* Optimized algorithm.
**/
private static Map<String, SnmpOid> buildPoolIndexMap(SnmpCachedData cached) {
if (cached == null) return Collections.emptyMap();
final SnmpOid[] indexes = cached.indexes;
final Object[] datas = cached.datas;
final int len = indexes.length;
final Map<String, SnmpOid> m = new HashMap<>(len);
for (int i=0; i<len; i++) {
final SnmpOid index = indexes[i];
if (index == null) continue;
final MemoryPoolMXBean mpm =
(MemoryPoolMXBean)datas[i];
if (mpm == null) continue;
final String name = mpm.getName();
if (name == null) continue;
m.put(name,index);
}
return m;
}
/**
* Return a table handler that holds the jvmMemManagerTable table data.
* This method return the cached table data if it is still
* valid, recompute it and cache the new value if it's not.
* If it needs to recompute the cached data, it first
* try to obtain the list of memory managers from the request
* contextual cache, and if it is not found, it calls
* <code>ManagementFactory.getMemoryMBean().getMemoryManagers()</code>
* and caches the value.
* This ensures that
* <code>ManagementFactory.getMemoryMBean().getMemoryManagers()</code>
* is not called more than once per request, thus ensuring a
* consistent view of the table.
**/
protected SnmpCachedData updateCachedDatas(Object userData) {
// Get the MemoryManager table
final SnmpTableHandler mmHandler =
meta.getManagerHandler(userData);
// Get the MemoryPool table
final SnmpTableHandler mpHandler =
meta.getPoolHandler(userData);
// Time stamp for the cache
final long time = System.currentTimeMillis();
// Build a Map poolname -> index
final Map<String,SnmpOid> poolIndexMap = buildPoolIndexMap(mpHandler);
// For each memory manager, get the list of memory pools
// For each memory pool, find its index in the memory pool table
// Create a row in the relation table.
final TreeMap<SnmpOid, Object> table =
new TreeMap<>(SnmpCachedData.oidComparator);
updateTreeMap(table,userData,mmHandler,mpHandler,poolIndexMap);
return new SnmpCachedData(time,table);
}
/**
* Get the list of memory pool associated with the
* given MemoryManagerMXBean.
**/
protected String[] getMemoryPools(Object userData,
MemoryManagerMXBean mmm, long mmarc) {
final String listTag =
"JvmMemManager." + mmarc + ".getMemoryPools";
String[] result=null;
if (userData instanceof Map) {
result = (String[])((Map)userData).get(listTag);
if (result != null) return result;
}
if (mmm!=null) {
result = mmm.getMemoryPoolNames();
}
if ((result!=null)&&(userData instanceof Map)) {
Map<Object, Object> map = Util.cast(userData);
map.put(listTag,result);
}
return result;
}
protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData,
MemoryManagerMXBean mmm,
SnmpOid mmIndex,
Map<String, SnmpOid> poolIndexMap) {
// The MemoryManager index is an int, so it's the first
// and only subidentifier.
final long mmarc;
try {
mmarc = mmIndex.getOidArc(0);
} catch (SnmpStatusException x) {
log.debug("updateTreeMap",
"Bad MemoryManager OID index: "+mmIndex);
log.debug("updateTreeMap",x);
return;
}
// Cache this in userData + get it from cache?
final String[] mpList = getMemoryPools(userData,mmm,mmarc);
if (mpList == null || mpList.length < 1) return;
final String mmmName = mmm.getName();
for (int i = 0; i < mpList.length; i++) {
final String mpmName = mpList[i];
if (mpmName == null) continue;
final SnmpOid mpIndex = poolIndexMap.get(mpmName);
if (mpIndex == null) continue;
// The MemoryPool index is an int, so it's the first
// and only subidentifier.
final long mparc;
try {
mparc = mpIndex.getOidArc(0);
} catch (SnmpStatusException x) {
log.debug("updateTreeMap","Bad MemoryPool OID index: " +
mpIndex);
log.debug("updateTreeMap",x);
continue;
}
// The MemoryMgrPoolRel table indexed is composed
// of the MemoryManager index, to which the MemoryPool
// index is appended.
final long[] arcs = { mmarc, mparc };
final SnmpOid index = new SnmpOid(arcs);
table.put(index, new JvmMemMgrPoolRelEntryImpl(mmmName,
mpmName,
(int)mmarc,
(int)mparc));
}
}
protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData,
SnmpTableHandler mmHandler,
SnmpTableHandler mpHandler,
Map<String, SnmpOid> poolIndexMap) {
if (mmHandler instanceof SnmpCachedData) {
updateTreeMap(table,userData,(SnmpCachedData)mmHandler,
mpHandler,poolIndexMap);
return;
}
SnmpOid mmIndex=null;
while ((mmIndex = mmHandler.getNext(mmIndex))!=null) {
final MemoryManagerMXBean mmm =
(MemoryManagerMXBean)mmHandler.getData(mmIndex);
if (mmm == null) continue;
updateTreeMap(table,userData,mmm,mmIndex,poolIndexMap);
}
}
protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData,
SnmpCachedData mmHandler,
SnmpTableHandler mpHandler,
Map<String, SnmpOid> poolIndexMap) {
final SnmpOid[] indexes = mmHandler.indexes;
final Object[] datas = mmHandler.datas;
final int size = indexes.length;
for (int i=size-1; i>-1; i--) {
final MemoryManagerMXBean mmm =
(MemoryManagerMXBean)datas[i];
if (mmm == null) continue;
updateTreeMap(table,userData,mmm,indexes[i],poolIndexMap);
}
}
}
// The weak cache for this table.
protected SnmpTableCache cache;
private transient JvmMemManagerTableMetaImpl managers = null;
private transient JvmMemPoolTableMetaImpl pools = null;
/**
* Constructor for the table. Initialize metadata for
* "JvmMemMgrPoolRelTableMeta".
* The reference on the MBean server is updated so the entries
* created through an SNMP SET will be AUTOMATICALLY REGISTERED
* in Java DMK.
*/
public JvmMemMgrPoolRelTableMetaImpl(SnmpMib myMib,
SnmpStandardObjectServer objserv) {
super(myMib,objserv);
this.cache = new
JvmMemMgrPoolRelTableCache(this,((JVM_MANAGEMENT_MIB_IMPL)myMib).
validity());
}
// Returns a pointer to the JvmMemManager meta node - we're going
// to reuse its SnmpTableHandler in order to implement the
// relation table.
private final JvmMemManagerTableMetaImpl getManagers(SnmpMib mib) {
if (managers == null) {
managers = (JvmMemManagerTableMetaImpl)
mib.getRegisteredTableMeta("JvmMemManagerTable");
}
return managers;
}
// Returns a pointer to the JvmMemPool meta node - we're going
// to reuse its SnmpTableHandler in order to implement the
// relation table.
private final JvmMemPoolTableMetaImpl getPools(SnmpMib mib) {
if (pools == null) {
pools = (JvmMemPoolTableMetaImpl)
mib.getRegisteredTableMeta("JvmMemPoolTable");
}
return pools;
}
/**
* Returns the JvmMemManagerTable SnmpTableHandler
**/
protected SnmpTableHandler getManagerHandler(Object userData) {
final JvmMemManagerTableMetaImpl managerTable = getManagers(theMib);
return managerTable.getHandler(userData);
}
/**
* Returns the JvmMemPoolTable SnmpTableHandler
**/
protected SnmpTableHandler getPoolHandler(Object userData) {
final JvmMemPoolTableMetaImpl poolTable = getPools(theMib);
return poolTable.getHandler(userData);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(Object userData)
throws SnmpStatusException {
// null means get the first OID.
return getNextOid(null,userData);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(SnmpOid oid, Object userData)
throws SnmpStatusException {
final boolean dbg = log.isDebugOn();
if (dbg) log.debug("getNextOid", "previous=" + oid);
// Get the data handler.
//
SnmpTableHandler handler = getHandler(userData);
if (handler == null) {
// This should never happen.
// If we get here it's a bug.
//
if (dbg) log.debug("getNextOid", "handler is null!");
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the next oid
//
final SnmpOid next = handler.getNext(oid);
if (dbg) log.debug("getNextOid", "next=" + next);
// if next is null: we reached the end of the table.
//
if (next == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
return next;
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected boolean contains(SnmpOid oid, Object userData) {
// Get the handler.
//
SnmpTableHandler handler = getHandler(userData);
// handler should never be null.
//
if (handler == null)
return false;
return handler.contains(oid);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
public Object getEntry(SnmpOid oid)
throws SnmpStatusException {
if (oid == null || oid.getLength() < 2)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// Get the request contextual cache (userData).
//
final Map<Object, Object> m = JvmContextFactory.getUserData();
// We know in the case of this table that the index is composed
// of two integers,
// o The MemoryManager is the first OID arc of the index OID.
// o The MemoryPool is the second OID arc of the index OID.
//
final long mgrIndex = oid.getOidArc(0);
final long poolIndex = oid.getOidArc(1);
// We're going to use this name to store/retrieve the entry in
// the request contextual cache.
//
// Revisit: Probably better programming to put all these strings
// in some interface.
//
final String entryTag = ((m==null)?null:
("JvmMemMgrPoolRelTable.entry." +
mgrIndex + "." + poolIndex));
// If the entry is in the cache, simply return it.
//
if (m != null) {
final Object entry = m.get(entryTag);
if (entry != null) return entry;
}
// The entry was not in the cache, make a new one.
//
// Get the data hanler.
//
SnmpTableHandler handler = getHandler(m);
// handler should never be null.
//
if (handler == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// Get the data associated with our entry.
//
final Object data = handler.getData(oid);
// data may be null if the OID we were given is not valid.
//
if (!(data instanceof JvmMemMgrPoolRelEntryImpl))
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// make the new entry (transient object that will be kept only
// for the duration of the request.
//
final Object entry = (JvmMemMgrPoolRelEntryImpl)data;
// XXXXX Revisit
// new JvmMemMgrPoolRelEntryImpl((MemoryManagerMXBean)data,
// (int)mgrIndex,(int)poolIndex);
// Put the entry in the cache in case we need it later while processing
// the request.
//
if (m != null && entry != null) {
m.put(entryTag,entry);
}
return entry;
}
/**
* Get the SnmpTableHandler that holds the jvmMemManagerTable data.
* First look it up in the request contextual cache, and if it is
* not found, obtain it from the weak cache.
* <br>The request contextual cache will be released at the end of the
* current requests, and is used only to process this request.
* <br>The weak cache is shared by all requests, and is only
* recomputed when it is found to be obsolete.
* <br>Note that the data put in the request contextual cache is
* never considered to be obsolete, in order to preserve data
* coherency.
**/
protected SnmpTableHandler getHandler(Object userData) {
final Map<Object, Object> m;
if (userData instanceof Map) m=Util.cast(userData);
else m=null;
// Look in the contextual cache.
if (m != null) {
final SnmpTableHandler handler =
(SnmpTableHandler)m.get("JvmMemMgrPoolRelTable.handler");
if (handler != null) return handler;
}
// No handler in contextual cache, make a new one.
final SnmpTableHandler handler = cache.getTableHandler();
if (m != null && handler != null )
m.put("JvmMemMgrPoolRelTable.handler",handler);
return handler;
}
static final MibLogger log =
new MibLogger(JvmMemMgrPoolRelTableMetaImpl.class);
}

View File

@@ -0,0 +1,506 @@
/*
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.util.Map;
// jmx imports
//
import com.sun.jmx.snmp.SnmpStatusException;
import com.sun.jmx.snmp.SnmpDefinitions;
// jdmk imports
//
import java.lang.management.MemoryUsage;
import java.lang.management.MemoryType;
import java.lang.management.MemoryPoolMXBean;
import sun.management.snmp.jvmmib.JvmMemPoolEntryMBean;
import sun.management.snmp.jvmmib.EnumJvmMemPoolState;
import sun.management.snmp.jvmmib.EnumJvmMemPoolType;
import sun.management.snmp.jvmmib.EnumJvmMemPoolThreshdSupport;
import sun.management.snmp.jvmmib.EnumJvmMemPoolCollectThreshdSupport;
import sun.management.snmp.util.MibLogger;
import sun.management.snmp.util.JvmContextFactory;
/**
* The class is used for implementing the "JvmMemPoolEntry" group.
*/
public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean {
/**
* Variable for storing the value of "JvmMemPoolIndex".
*
* "An index value opaquely computed by the agent which uniquely
* identifies a row in the jvmMemPoolTable.
* "
*
*/
final protected int jvmMemPoolIndex;
final static String memoryTag = "jvmMemPoolEntry.getUsage";
final static String peakMemoryTag = "jvmMemPoolEntry.getPeakUsage";
final static String collectMemoryTag =
"jvmMemPoolEntry.getCollectionUsage";
final static MemoryUsage ZEROS = new MemoryUsage(0,0,0,0);
final String entryMemoryTag;
final String entryPeakMemoryTag;
final String entryCollectMemoryTag;
MemoryUsage getMemoryUsage() {
try {
final Map<Object, Object> m = JvmContextFactory.getUserData();
if (m != null) {
final MemoryUsage cached = (MemoryUsage)
m.get(entryMemoryTag);
if (cached != null) {
log.debug("getMemoryUsage",entryMemoryTag+
" found in cache.");
return cached;
}
MemoryUsage u = pool.getUsage();
if (u == null) u = ZEROS;
m.put(entryMemoryTag,u);
return u;
}
// Should never come here.
// Log error!
log.trace("getMemoryUsage", "ERROR: should never come here!");
return pool.getUsage();
} catch (RuntimeException x) {
log.trace("getMemoryUsage",
"Failed to get MemoryUsage: " + x);
log.debug("getMemoryUsage",x);
throw x;
}
}
MemoryUsage getPeakMemoryUsage() {
try {
final Map<Object, Object> m = JvmContextFactory.getUserData();
if (m != null) {
final MemoryUsage cached = (MemoryUsage)
m.get(entryPeakMemoryTag);
if (cached != null) {
if (log.isDebugOn())
log.debug("getPeakMemoryUsage",
entryPeakMemoryTag + " found in cache.");
return cached;
}
MemoryUsage u = pool.getPeakUsage();
if (u == null) u = ZEROS;
m.put(entryPeakMemoryTag,u);
return u;
}
// Should never come here.
// Log error!
log.trace("getPeakMemoryUsage", "ERROR: should never come here!");
return ZEROS;
} catch (RuntimeException x) {
log.trace("getPeakMemoryUsage",
"Failed to get MemoryUsage: " + x);
log.debug("getPeakMemoryUsage",x);
throw x;
}
}
MemoryUsage getCollectMemoryUsage() {
try {
final Map<Object, Object> m = JvmContextFactory.getUserData();
if (m != null) {
final MemoryUsage cached = (MemoryUsage)
m.get(entryCollectMemoryTag);
if (cached != null) {
if (log.isDebugOn())
log.debug("getCollectMemoryUsage",
entryCollectMemoryTag + " found in cache.");
return cached;
}
MemoryUsage u = pool.getCollectionUsage();
if (u == null) u = ZEROS;
m.put(entryCollectMemoryTag,u);
return u;
}
// Should never come here.
// Log error!
log.trace("getCollectMemoryUsage",
"ERROR: should never come here!");
return ZEROS;
} catch (RuntimeException x) {
log.trace("getPeakMemoryUsage",
"Failed to get MemoryUsage: " + x);
log.debug("getPeakMemoryUsage",x);
throw x;
}
}
final MemoryPoolMXBean pool;
/**
* Constructor for the "JvmMemPoolEntry" group.
*/
public JvmMemPoolEntryImpl(MemoryPoolMXBean mp, final int index) {
this.pool=mp;
this.jvmMemPoolIndex = index;
this.entryMemoryTag = memoryTag + "." + index;
this.entryPeakMemoryTag = peakMemoryTag + "." + index;
this.entryCollectMemoryTag = collectMemoryTag + "." + index;
}
/**
* Getter for the "JvmMemPoolMaxSize" variable.
*/
public Long getJvmMemPoolMaxSize() throws SnmpStatusException {
final long val = getMemoryUsage().getMax();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
/**
* Getter for the "JvmMemPoolUsed" variable.
*/
public Long getJvmMemPoolUsed() throws SnmpStatusException {
final long val = getMemoryUsage().getUsed();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
/**
* Getter for the "JvmMemPoolInitSize" variable.
*/
public Long getJvmMemPoolInitSize() throws SnmpStatusException {
final long val = getMemoryUsage().getInit();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
/**
* Getter for the "JvmMemPoolCommitted" variable.
*/
public Long getJvmMemPoolCommitted() throws SnmpStatusException {
final long val = getMemoryUsage().getCommitted();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
/**
* Getter for the "JvmMemPoolPeakMaxSize" variable.
*/
public Long getJvmMemPoolPeakMaxSize() throws SnmpStatusException {
final long val = getPeakMemoryUsage().getMax();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
/**
* Getter for the "JvmMemPoolPeakUsed" variable.
*/
public Long getJvmMemPoolPeakUsed() throws SnmpStatusException {
final long val = getPeakMemoryUsage().getUsed();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
/**
* Getter for the "JvmMemPoolPeakCommitted" variable.
*/
public Long getJvmMemPoolPeakCommitted() throws SnmpStatusException {
final long val = getPeakMemoryUsage().getCommitted();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
/**
* Getter for the "JvmMemPoolCollectMaxSize" variable.
*/
public Long getJvmMemPoolCollectMaxSize() throws SnmpStatusException {
final long val = getCollectMemoryUsage().getMax();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
/**
* Getter for the "JvmMemPoolCollectUsed" variable.
*/
public Long getJvmMemPoolCollectUsed() throws SnmpStatusException {
final long val = getCollectMemoryUsage().getUsed();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
/**
* Getter for the "JvmMemPoolCollectCommitted" variable.
*/
public Long getJvmMemPoolCollectCommitted() throws SnmpStatusException {
final long val = getCollectMemoryUsage().getCommitted();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
/**
* Getter for the "JvmMemPoolThreshold" variable.
*/
public Long getJvmMemPoolThreshold() throws SnmpStatusException {
if (!pool.isUsageThresholdSupported())
return JvmMemoryImpl.Long0;
final long val = pool.getUsageThreshold();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
/**
* Setter for the "JvmMemPoolThreshold" variable.
*/
public void setJvmMemPoolThreshold(Long x) throws SnmpStatusException {
final long val = x.longValue();
if (val < 0 )
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
// This should never throw an exception has the checks have
// already been performed in checkJvmMemPoolThreshold().
//
pool.setUsageThreshold(val);
}
/**
* Checker for the "JvmMemPoolThreshold" variable.
*/
public void checkJvmMemPoolThreshold(Long x) throws SnmpStatusException {
// if threshold is -1, it means that low memory detection is not
// supported.
if (!pool.isUsageThresholdSupported())
throw new
SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
final long val = x.longValue();
if (val < 0 )
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
/**
* Getter for the "JvmMemPoolThreshdSupport" variable.
*/
public EnumJvmMemPoolThreshdSupport getJvmMemPoolThreshdSupport()
throws SnmpStatusException {
if (pool.isUsageThresholdSupported())
return EnumJvmMemPoolThreshdSupported;
else
return EnumJvmMemPoolThreshdUnsupported;
}
/**
* Getter for the "JvmMemPoolThreshdCount" variable.
*/
public Long getJvmMemPoolThreshdCount()
throws SnmpStatusException {
if (!pool.isUsageThresholdSupported())
return JvmMemoryImpl.Long0;
final long val = pool.getUsageThresholdCount();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
/**
* Getter for the "JvmMemPoolCollectThreshold" variable.
*/
public Long getJvmMemPoolCollectThreshold() throws SnmpStatusException {
if (!pool.isCollectionUsageThresholdSupported())
return JvmMemoryImpl.Long0;
final long val = pool.getCollectionUsageThreshold();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
/**
* Setter for the "JvmMemPoolCollectThreshold" variable.
*/
public void setJvmMemPoolCollectThreshold(Long x)
throws SnmpStatusException {
final long val = x.longValue();
if (val < 0 )
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
// This should never throw an exception has the checks have
// already been performed in checkJvmMemPoolCollectThreshold().
//
pool.setCollectionUsageThreshold(val);
}
/**
* Checker for the "JvmMemPoolCollectThreshold" variable.
*/
public void checkJvmMemPoolCollectThreshold(Long x)
throws SnmpStatusException {
// if threshold is -1, it means that low memory detection is not
// supported.
if (!pool.isCollectionUsageThresholdSupported())
throw new
SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
final long val = x.longValue();
if (val < 0 )
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
/**
* Getter for the "JvmMemPoolThreshdSupport" variable.
*/
public EnumJvmMemPoolCollectThreshdSupport
getJvmMemPoolCollectThreshdSupport()
throws SnmpStatusException {
if (pool.isCollectionUsageThresholdSupported())
return EnumJvmMemPoolCollectThreshdSupported;
else
return EnumJvmMemPoolCollectThreshdUnsupported;
}
/**
* Getter for the "JvmMemPoolCollectThreshdCount" variable.
*/
public Long getJvmMemPoolCollectThreshdCount()
throws SnmpStatusException {
if (!pool.isCollectionUsageThresholdSupported())
return JvmMemoryImpl.Long0;
final long val = pool.getCollectionUsageThresholdCount();
if (val > -1) return new Long(val);
else return JvmMemoryImpl.Long0;
}
public static EnumJvmMemPoolType jvmMemPoolType(MemoryType type)
throws SnmpStatusException {
if (type.equals(MemoryType.HEAP))
return EnumJvmMemPoolTypeHeap;
else if (type.equals(MemoryType.NON_HEAP))
return EnumJvmMemPoolTypeNonHeap;
throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
}
/**
* Getter for the "JvmMemPoolType" variable.
*/
public EnumJvmMemPoolType getJvmMemPoolType() throws SnmpStatusException {
return jvmMemPoolType(pool.getType());
}
/**
* Getter for the "JvmMemPoolName" variable.
*/
public String getJvmMemPoolName() throws SnmpStatusException {
return JVM_MANAGEMENT_MIB_IMPL.validJavaObjectNameTC(pool.getName());
}
/**
* Getter for the "JvmMemPoolIndex" variable.
*/
public Integer getJvmMemPoolIndex() throws SnmpStatusException {
return new Integer(jvmMemPoolIndex);
}
/**
* Getter for the "JvmMemPoolState" variable.
*/
public EnumJvmMemPoolState getJvmMemPoolState()
throws SnmpStatusException {
if (pool.isValid())
return JvmMemPoolStateValid;
else
return JvmMemPoolStateInvalid;
}
/**
* Getter for the "JvmMemPoolPeakReset" variable.
*/
public synchronized Long getJvmMemPoolPeakReset()
throws SnmpStatusException {
return new Long(jvmMemPoolPeakReset);
}
/**
* Setter for the "JvmMemPoolPeakReset" variable.
*/
public synchronized void setJvmMemPoolPeakReset(Long x)
throws SnmpStatusException {
final long l = x.longValue();
if (l > jvmMemPoolPeakReset) {
final long stamp = System.currentTimeMillis();
pool.resetPeakUsage();
jvmMemPoolPeakReset = stamp;
log.debug("setJvmMemPoolPeakReset",
"jvmMemPoolPeakReset="+stamp);
}
}
/**
* Checker for the "JvmMemPoolPeakReset" variable.
*/
public void checkJvmMemPoolPeakReset(Long x) throws SnmpStatusException {
}
/* Last time peak usage was reset */
private long jvmMemPoolPeakReset = 0;
private final static EnumJvmMemPoolState JvmMemPoolStateValid =
new EnumJvmMemPoolState("valid");
private final static EnumJvmMemPoolState JvmMemPoolStateInvalid =
new EnumJvmMemPoolState("invalid");
private static final EnumJvmMemPoolType EnumJvmMemPoolTypeHeap =
new EnumJvmMemPoolType("heap");
private static final EnumJvmMemPoolType EnumJvmMemPoolTypeNonHeap =
new EnumJvmMemPoolType("nonheap");
private static final EnumJvmMemPoolThreshdSupport
EnumJvmMemPoolThreshdSupported =
new EnumJvmMemPoolThreshdSupport("supported");
private static final EnumJvmMemPoolThreshdSupport
EnumJvmMemPoolThreshdUnsupported =
new EnumJvmMemPoolThreshdSupport("unsupported");
private static final EnumJvmMemPoolCollectThreshdSupport
EnumJvmMemPoolCollectThreshdSupported =
new EnumJvmMemPoolCollectThreshdSupport("supported");
private static final EnumJvmMemPoolCollectThreshdSupport
EnumJvmMemPoolCollectThreshdUnsupported=
new EnumJvmMemPoolCollectThreshdSupport("unsupported");
static final MibLogger log = new MibLogger(JvmMemPoolEntryImpl.class);
}

View File

@@ -0,0 +1,311 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import com.sun.jmx.mbeanserver.Util;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
// jmx imports
//
import javax.management.MBeanServer;
import javax.management.ObjectName;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.agent.SnmpMibSubRequest;
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.ManagementFactory;
import sun.management.snmp.jvmmib.JvmMemPoolTableMeta;
import sun.management.snmp.util.SnmpTableCache;
import sun.management.snmp.util.SnmpNamedListTableCache;
import sun.management.snmp.util.SnmpTableHandler;
import sun.management.snmp.util.MibLogger;
import sun.management.snmp.util.JvmContextFactory;
/**
* The class is used for implementing the "JvmMemPoolTable" group.
*/
public class JvmMemPoolTableMetaImpl extends JvmMemPoolTableMeta {
static final long serialVersionUID = -2525820976094284957L;
/**
* A concrete implementation of {@link SnmpNamedListTableCache}, for the
* jvmMemPoolTable.
**/
private static class JvmMemPoolTableCache extends SnmpNamedListTableCache {
static final long serialVersionUID = -1755520683086760574L;
/**
* Create a weak cache for the jvmMemPoolTable.
* @param validity validity of the cached data, in ms.
**/
JvmMemPoolTableCache(long validity) {
this.validity = validity;
}
/**
* Use the MemoryPoolMXBean name as key.
* @param context A {@link TreeMap} as allocated by the parent
* {@link SnmpNamedListTableCache} class.
* @param rawDatas List of {@link MemoryPoolMXBean}, as
* returned by
* <code>ManagementFactory.getMemoryPoolMXBeans()</code>
* @param rank The <var>rank</var> of <var>item</var> in the list.
* @param item The <var>rank</var><super>th</super>
* <code>MemoryPoolMXBean</code> in the list.
* @return <code>((MemoryPoolMXBean)item).getName()</code>
**/
protected String getKey(Object context, List<?> rawDatas,
int rank, Object item) {
if (item == null) return null;
final String name = ((MemoryPoolMXBean)item).getName();
log.debug("getKey", "key=" + name);
return name;
}
/**
* Call <code>getTableDatas(JvmContextFactory.getUserData())</code>.
**/
public SnmpTableHandler getTableHandler() {
final Map<Object, Object> userData = JvmContextFactory.getUserData();
return getTableDatas(userData);
}
/**
* Return the key used to cache the raw data of this table.
**/
protected String getRawDatasKey() {
return "JvmMemManagerTable.getMemoryPools";
}
/**
* Call ManagementFactory.getMemoryPoolMXBeans() to
* load the raw data of this table.
**/
protected List<MemoryPoolMXBean> loadRawDatas(Map<Object, Object> userData) {
return ManagementFactory.getMemoryPoolMXBeans();
}
}
// The weak cache for this table.
protected SnmpTableCache cache;
/**
* Constructor for the table.
* Initialize metadata for "JvmMemPoolTableMeta".
*/
public JvmMemPoolTableMetaImpl(SnmpMib myMib,
SnmpStandardObjectServer objserv) {
super(myMib,objserv);
this.cache = new
JvmMemPoolTableCache(((JVM_MANAGEMENT_MIB_IMPL)myMib).
validity()*30);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(Object userData)
throws SnmpStatusException {
// null means get the first OID.
return getNextOid(null,userData);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(SnmpOid oid, Object userData)
throws SnmpStatusException {
final boolean dbg = log.isDebugOn();
try {
if (dbg) log.debug("getNextOid", "previous=" + oid);
// Get the data handler.
//
SnmpTableHandler handler = getHandler(userData);
if (handler == null) {
// This should never happen.
// If we get here it's a bug.
//
if (dbg) log.debug("getNextOid", "handler is null!");
throw new
SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the next oid
//
final SnmpOid next = handler.getNext(oid);
if (dbg) log.debug("getNextOid", "next=" + next);
// if next is null: we reached the end of the table.
//
if (next == null)
throw new
SnmpStatusException(SnmpStatusException.noSuchInstance);
return next;
} catch (SnmpStatusException x) {
if (dbg) log.debug("getNextOid", "End of MIB View: " + x);
throw x;
} catch (RuntimeException r) {
if (dbg) log.debug("getNextOid", "Unexpected exception: " + r);
if (dbg) log.debug("getNextOid",r);
throw r;
}
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected boolean contains(SnmpOid oid, Object userData) {
// Get the handler.
//
SnmpTableHandler handler = getHandler(userData);
// handler should never be null.
//
if (handler == null)
return false;
return handler.contains(oid);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
public Object getEntry(SnmpOid oid)
throws SnmpStatusException {
if (oid == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// Get the request contextual cache (userData).
//
final Map<Object, Object> m = Util.cast(JvmContextFactory.getUserData());
// We know in the case of this table that the index is an integer,
// it is thus the first OID arc of the index OID.
//
final long index = oid.getOidArc(0);
// We're going to use this name to store/retrieve the entry in
// the request contextual cache.
//
// Revisit: Probably better programming to put all these strings
// in some interface.
//
final String entryTag = ((m==null)?null:("JvmMemPoolTable.entry." +
index));
// If the entry is in the cache, simply return it.
//
if (m != null) {
final Object entry = m.get(entryTag);
if (entry != null) return entry;
}
// The entry was not in the cache, make a new one.
//
// Get the data hanler.
//
SnmpTableHandler handler = getHandler(m);
// handler should never be null.
//
if (handler == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// Get the data associated with our entry.
//
final Object data = handler.getData(oid);
// data may be null if the OID we were given is not valid.
//
if (data == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// make the new entry (transient object that will be kept only
// for the duration of the request.
//
if (log.isDebugOn())
log.debug("getEntry","data is a: " + data.getClass().getName());
final Object entry =
new JvmMemPoolEntryImpl((MemoryPoolMXBean)data,(int)index);
// Put the entry in the cache in case we need it later while processing
// the request.
//
if (m != null && entry != null) {
m.put(entryTag,entry);
}
return entry;
}
/**
* Get the SnmpTableHandler that holds the jvmMemPoolTable data.
* First look it up in the request contextual cache, and if it is
* not found, obtain it from the weak cache.
* <br>The request contextual cache will be released at the end of the
* current requests, and is used only to process this request.
* <br>The weak cache is shared by all requests, and is only
* recomputed when it is found to be obsolete.
* <br>Note that the data put in the request contextual cache is
* never considered to be obsolete, in order to preserve data
* coherency.
**/
protected SnmpTableHandler getHandler(Object userData) {
final Map<Object, Object> m;
if (userData instanceof Map) m = Util.cast(userData);
else m = null;
// Look in the contextual cache.
if (m != null) {
final SnmpTableHandler handler =
(SnmpTableHandler)m.get("JvmMemPoolTable.handler");
if (handler != null) return handler;
}
// No handler in contextual cache, make a new one.
final SnmpTableHandler handler = cache.getTableHandler();
if (m != null && handler != null )
m.put("JvmMemPoolTable.handler",handler);
return handler;
}
static final MibLogger log = new MibLogger(JvmMemPoolTableMetaImpl.class);
}

View File

@@ -0,0 +1,391 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// jmx imports
//
import javax.management.MBeanServer;
import com.sun.jmx.snmp.SnmpStatusException;
import com.sun.jmx.snmp.SnmpDefinitions;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import java.util.Map;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryUsage;
import java.lang.management.MemoryType;
import java.lang.management.MemoryMXBean;
import javax.management.openmbean.CompositeData;
import sun.management.snmp.jvmmib.JvmMemoryMBean;
import sun.management.snmp.jvmmib.EnumJvmMemoryGCCall;
import sun.management.snmp.jvmmib.EnumJvmMemoryGCVerboseLevel;
import sun.management.snmp.util.MibLogger;
import sun.management.snmp.util.JvmContextFactory;
/**
* The class is used for implementing the "JvmMemory" group.
*/
public class JvmMemoryImpl implements JvmMemoryMBean {
/**
* Variable for storing the value of "JvmMemoryGCCall".
*
* "This object makes it possible to remotelly trigger the
* Garbage Collector in the JVM.
*
* This object's syntax is an enumeration which defines:
*
* * Two state values, that can be returned from a GET request:
*
* unsupported(1): means that remote invocation of gc() is not
* supported by the SNMP agent.
* supported(2) : means that remote invocation of gc() is supported
* by the SNMP agent.
*
* * One action value, that can be provided in a SET request to
* trigger the garbage collector:
*
* start(3) : means that a manager wishes to trigger
* garbage collection.
*
* * Two result value, that will be returned as a result of a
* SET request when remote invocation of gc is supported
* by the SNMP agent:
*
* started(4) : means that garbage collection was
* successfully triggered. It does not mean
* however that the action was successfullly
* completed: gc might still be running when
* this value is returned.
* failed(5) : means that garbage collection couldn't be
* triggered.
*
* * If remote invocation is not supported by the SNMP agent, then
* unsupported(1) will always be returned as a result of either
* a GET request, or a SET request with start(3) as input value.
*
* * If a SET request with anything but start(3) is received, then
* the agent will return a wrongValue error.
*
* See java.management.MemoryMXBean.gc()
* "
*
*/
final static EnumJvmMemoryGCCall JvmMemoryGCCallSupported
= new EnumJvmMemoryGCCall("supported");
final static EnumJvmMemoryGCCall JvmMemoryGCCallStart
= new EnumJvmMemoryGCCall("start");
final static EnumJvmMemoryGCCall JvmMemoryGCCallFailed
= new EnumJvmMemoryGCCall("failed");
final static EnumJvmMemoryGCCall JvmMemoryGCCallStarted
= new EnumJvmMemoryGCCall("started");
/**
* Variable for storing the value of "JvmMemoryGCVerboseLevel".
*
* "State of the -verbose:gc state.
*
* verbose: if the -verbose:gc flag is on,
* silent: otherwise.
*
* See java.management.MemoryMXBean.isVerbose(),
* java.management.MemoryMXBean.setVerbose()
* "
*
*/
final static EnumJvmMemoryGCVerboseLevel JvmMemoryGCVerboseLevelVerbose =
new EnumJvmMemoryGCVerboseLevel("verbose");
final static EnumJvmMemoryGCVerboseLevel JvmMemoryGCVerboseLevelSilent =
new EnumJvmMemoryGCVerboseLevel("silent");
/**
* Constructor for the "JvmMemory" group.
* If the group contains a table, the entries created through an
* SNMP SET will not be registered in Java DMK.
*/
public JvmMemoryImpl(SnmpMib myMib) {
}
/**
* Constructor for the "JvmMemory" group.
* If the group contains a table, the entries created through an
* SNMP SET will be AUTOMATICALLY REGISTERED in Java DMK.
*/
public JvmMemoryImpl(SnmpMib myMib, MBeanServer server) {
// no entry will be registered since the table is virtual.
}
final static String heapMemoryTag = "jvmMemory.getHeapMemoryUsage";
final static String nonHeapMemoryTag = "jvmMemory.getNonHeapMemoryUsage";
private MemoryUsage getMemoryUsage(MemoryType type) {
if (type == MemoryType.HEAP) {
return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
} else {
return ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
}
}
MemoryUsage getNonHeapMemoryUsage() {
try {
final Map<Object, Object> m = JvmContextFactory.getUserData();
if (m != null) {
final MemoryUsage cached = (MemoryUsage)
m.get(nonHeapMemoryTag);
if (cached != null) {
log.debug("getNonHeapMemoryUsage",
"jvmMemory.getNonHeapMemoryUsage found in cache.");
return cached;
}
final MemoryUsage u = getMemoryUsage(MemoryType.NON_HEAP);
// getNonHeapMemoryUsage() never returns null.
//
// if (u == null) u=MemoryUsage.INVALID;
m.put(nonHeapMemoryTag,u);
return u;
}
// Should never come here.
// Log error!
log.trace("getNonHeapMemoryUsage",
"ERROR: should never come here!");
return getMemoryUsage(MemoryType.NON_HEAP);
} catch (RuntimeException x) {
log.trace("getNonHeapMemoryUsage",
"Failed to get NonHeapMemoryUsage: " + x);
log.debug("getNonHeapMemoryUsage",x);
throw x;
}
}
MemoryUsage getHeapMemoryUsage() {
try {
final Map<Object, Object> m = JvmContextFactory.getUserData();
if (m != null) {
final MemoryUsage cached = (MemoryUsage)m.get(heapMemoryTag);
if (cached != null) {
log.debug("getHeapMemoryUsage",
"jvmMemory.getHeapMemoryUsage found in cache.");
return cached;
}
final MemoryUsage u = getMemoryUsage(MemoryType.HEAP);
// getHeapMemoryUsage() never returns null.
//
// if (u == null) u=MemoryUsage.INVALID;
m.put(heapMemoryTag,u);
return u;
}
// Should never come here.
// Log error!
log.trace("getHeapMemoryUsage", "ERROR: should never come here!");
return getMemoryUsage(MemoryType.HEAP);
} catch (RuntimeException x) {
log.trace("getHeapMemoryUsage",
"Failed to get HeapMemoryUsage: " + x);
log.debug("getHeapMemoryUsage",x);
throw x;
}
}
static final Long Long0 = new Long(0);
/**
* Getter for the "JvmMemoryNonHeapMaxSize" variable.
*/
public Long getJvmMemoryNonHeapMaxSize()
throws SnmpStatusException {
final long val = getNonHeapMemoryUsage().getMax();
if (val > -1) return new Long(val);
else return Long0;
}
/**
* Getter for the "JvmMemoryNonHeapCommitted" variable.
*/
public Long getJvmMemoryNonHeapCommitted() throws SnmpStatusException {
final long val = getNonHeapMemoryUsage().getCommitted();
if (val > -1) return new Long(val);
else return Long0;
}
/**
* Getter for the "JvmMemoryNonHeapUsed" variable.
*/
public Long getJvmMemoryNonHeapUsed() throws SnmpStatusException {
final long val = getNonHeapMemoryUsage().getUsed();
if (val > -1) return new Long(val);
else return Long0;
}
/**
* Getter for the "JvmMemoryNonHeapInitSize" variable.
*/
public Long getJvmMemoryNonHeapInitSize() throws SnmpStatusException {
final long val = getNonHeapMemoryUsage().getInit();
if (val > -1) return new Long(val);
else return Long0;
}
/**
* Getter for the "JvmMemoryHeapMaxSize" variable.
*/
public Long getJvmMemoryHeapMaxSize() throws SnmpStatusException {
final long val = getHeapMemoryUsage().getMax();
if (val > -1) return new Long(val);
else return Long0;
}
/**
* Getter for the "JvmMemoryGCCall" variable.
*/
public EnumJvmMemoryGCCall getJvmMemoryGCCall()
throws SnmpStatusException {
final Map<Object,Object> m = JvmContextFactory.getUserData();
if (m != null) {
final EnumJvmMemoryGCCall cached
= (EnumJvmMemoryGCCall) m.get("jvmMemory.getJvmMemoryGCCall");
if (cached != null) return cached;
}
return JvmMemoryGCCallSupported;
}
/**
* Setter for the "JvmMemoryGCCall" variable.
*/
public void setJvmMemoryGCCall(EnumJvmMemoryGCCall x)
throws SnmpStatusException {
if (x.intValue() == JvmMemoryGCCallStart.intValue()) {
final Map<Object, Object> m = JvmContextFactory.getUserData();
try {
ManagementFactory.getMemoryMXBean().gc();
if (m != null) m.put("jvmMemory.getJvmMemoryGCCall",
JvmMemoryGCCallStarted);
} catch (Exception ex) {
if (m != null) m.put("jvmMemory.getJvmMemoryGCCall",
JvmMemoryGCCallFailed);
}
return;
}
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
/**
* Checker for the "JvmMemoryGCCall" variable.
*/
public void checkJvmMemoryGCCall(EnumJvmMemoryGCCall x)
throws SnmpStatusException {
if (x.intValue() != JvmMemoryGCCallStart.intValue())
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
/**
* Getter for the "JvmMemoryHeapCommitted" variable.
*/
public Long getJvmMemoryHeapCommitted() throws SnmpStatusException {
final long val = getHeapMemoryUsage().getCommitted();
if (val > -1) return new Long(val);
else return Long0;
}
/**
* Getter for the "JvmMemoryGCVerboseLevel" variable.
*/
public EnumJvmMemoryGCVerboseLevel getJvmMemoryGCVerboseLevel()
throws SnmpStatusException {
if (ManagementFactory.getMemoryMXBean().isVerbose())
return JvmMemoryGCVerboseLevelVerbose;
else
return JvmMemoryGCVerboseLevelSilent;
}
/**
* Setter for the "JvmMemoryGCVerboseLevel" variable.
*/
public void setJvmMemoryGCVerboseLevel(EnumJvmMemoryGCVerboseLevel x)
throws SnmpStatusException {
if (JvmMemoryGCVerboseLevelVerbose.intValue() == x.intValue())
ManagementFactory.getMemoryMXBean().setVerbose(true);
else
ManagementFactory.getMemoryMXBean().setVerbose(false);
}
/**
* Checker for the "JvmMemoryGCVerboseLevel" variable.
*/
public void checkJvmMemoryGCVerboseLevel(EnumJvmMemoryGCVerboseLevel x)
throws SnmpStatusException {
// Nothing to check...
}
/**
* Getter for the "JvmMemoryHeapUsed" variable.
*/
public Long getJvmMemoryHeapUsed() throws SnmpStatusException {
final long val = getHeapMemoryUsage().getUsed();
if (val > -1) return new Long(val);
else return Long0;
}
/**
* Getter for the "JvmMemoryHeapInitSize" variable.
*/
public Long getJvmMemoryHeapInitSize() throws SnmpStatusException {
final long val = getHeapMemoryUsage().getInit();
if (val > -1) return new Long(val);
else return Long0;
}
/**
* Getter for the "JvmMemoryPendingFinalCount" variable.
*/
public Long getJvmMemoryPendingFinalCount()
throws SnmpStatusException {
final long val = ManagementFactory.getMemoryMXBean().
getObjectPendingFinalizationCount();
if (val > -1) return new Long((int)val);
// Should never happen... but stay safe all the same.
//
else return new Long(0);
}
static final MibLogger log = new MibLogger(JvmMemoryImpl.class);
}

View File

@@ -0,0 +1,151 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
// jmx imports
//
import javax.management.MBeanServer;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
import sun.management.snmp.jvmmib.JvmMemoryMeta;
import sun.management.snmp.jvmmib.JvmMemManagerTableMeta;
import sun.management.snmp.jvmmib.JvmMemGCTableMeta;
import sun.management.snmp.jvmmib.JvmMemPoolTableMeta;
import sun.management.snmp.jvmmib.JvmMemMgrPoolRelTableMeta;
import sun.management.snmp.util.MibLogger;
/**
* The class is used for representing SNMP metadata for the "JvmMemory" group.
*/
public class JvmMemoryMetaImpl extends JvmMemoryMeta {
static final long serialVersionUID = -6500448253825893071L;
/**
* Constructor for the metadata associated to "JvmMemory".
*/
public JvmMemoryMetaImpl(SnmpMib myMib, SnmpStandardObjectServer objserv) {
super(myMib,objserv);
}
/**
* Factory method for "JvmMemManagerTable" table metadata class.
*
* You can redefine this method if you need to replace the default
* generated metadata class with your own customized class.
*
* @param tableName Name of the table object ("JvmMemManagerTable")
* @param groupName Name of the group to which this table belong
* ("JvmMemory")
* @param mib The SnmpMib object in which this table is registered
* @param server MBeanServer for this table entries (may be null)
*
* @return An instance of the metadata class generated for the
* "JvmMemManagerTable" table (JvmMemManagerTableMeta)
*
**/
protected JvmMemManagerTableMeta createJvmMemManagerTableMetaNode(
String tableName, String groupName, SnmpMib mib, MBeanServer server) {
return new JvmMemManagerTableMetaImpl(mib, objectserver);
}
/**
* Factory method for "JvmMemGCTable" table metadata class.
*
* You can redefine this method if you need to replace the default
* generated metadata class with your own customized class.
*
* @param tableName Name of the table object ("JvmMemGCTable")
* @param groupName Name of the group to which this table belong
* ("JvmMemory")
* @param mib The SnmpMib object in which this table is registered
* @param server MBeanServer for this table entries (may be null)
*
* @return An instance of the metadata class generated for the
* "JvmMemGCTable" table (JvmMemGCTableMeta)
*
**/
protected JvmMemGCTableMeta createJvmMemGCTableMetaNode(String tableName,
String groupName, SnmpMib mib, MBeanServer server) {
return new JvmMemGCTableMetaImpl(mib, objectserver);
}
/**
* Factory method for "JvmMemPoolTable" table metadata class.
*
* You can redefine this method if you need to replace the default
* generated metadata class with your own customized class.
*
* @param tableName Name of the table object ("JvmMemPoolTable")
* @param groupName Name of the group to which this table belong
* ("JvmMemory")
* @param mib The SnmpMib object in which this table is registered
* @param server MBeanServer for this table entries (may be null)
*
* @return An instance of the metadata class generated for the
* "JvmMemPoolTable" table (JvmMemPoolTableMeta)
*
**/
protected JvmMemPoolTableMeta
createJvmMemPoolTableMetaNode(String tableName, String groupName,
SnmpMib mib, MBeanServer server) {
return new JvmMemPoolTableMetaImpl(mib, objectserver);
}
/**
* Factory method for "JvmMemMgrPoolRelTable" table metadata class.
*
* You can redefine this method if you need to replace the default
* generated metadata class with your own customized class.
*
* @param tableName Name of the table object ("JvmMemMgrPoolRelTable")
* @param groupName Name of the group to which this table belong
* ("JvmMemory")
* @param mib The SnmpMib object in which this table is registered
* @param server MBeanServer for this table entries (may be null)
*
* @return An instance of the metadata class generated for the
* "JvmMemMgrPoolRelTable" table (JvmMemMgrPoolRelTableMeta)
*
**/
protected JvmMemMgrPoolRelTableMeta
createJvmMemMgrPoolRelTableMetaNode(String tableName,
String groupName,
SnmpMib mib, MBeanServer server) {
return new JvmMemMgrPoolRelTableMetaImpl(mib, objectserver);
}
}

View File

@@ -0,0 +1,110 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
// jmx imports
//
import javax.management.MBeanServer;
import com.sun.jmx.snmp.SnmpString;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import sun.management.snmp.jvmmib.JvmOSMBean;
/**
* The class is used for implementing the "JvmOS" group.
*/
public class JvmOSImpl implements JvmOSMBean, Serializable {
static final long serialVersionUID = 1839834731763310809L;
/**
* Constructor for the "JvmOS" group.
* If the group contains a table, the entries created through an
* SNMP SET will not be registered in Java DMK.
*/
public JvmOSImpl(SnmpMib myMib) {
}
/**
* Constructor for the "JvmOS" group.
* If the group contains a table, the entries created through an
* SNMP SET will be AUTOMATICALLY REGISTERED in Java DMK.
*/
public JvmOSImpl(SnmpMib myMib, MBeanServer server) {
}
static OperatingSystemMXBean getOSMBean() {
return ManagementFactory.getOperatingSystemMXBean();
}
private static String validDisplayStringTC(String str) {
return JVM_MANAGEMENT_MIB_IMPL.validDisplayStringTC(str);
}
private static String validJavaObjectNameTC(String str) {
return JVM_MANAGEMENT_MIB_IMPL.validJavaObjectNameTC(str);
}
/**
* Getter for the "JvmRTProcessorCount" variable.
*/
public Integer getJvmOSProcessorCount() throws SnmpStatusException {
return new Integer(getOSMBean().getAvailableProcessors());
}
/**
* Getter for the "JvmOSVersion" variable.
*/
public String getJvmOSVersion() throws SnmpStatusException {
return validDisplayStringTC(getOSMBean().getVersion());
}
/**
* Getter for the "JvmOSArch" variable.
*/
public String getJvmOSArch() throws SnmpStatusException {
return validDisplayStringTC(getOSMBean().getArch());
}
/**
* Getter for the "JvmOSName" variable.
*/
public String getJvmOSName() throws SnmpStatusException {
return validJavaObjectNameTC(getOSMBean().getName());
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
// jmx imports
//
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import sun.management.snmp.jvmmib.JvmRTBootClassPathEntryMBean;
/**
* The class is used for implementing the "JvmRTBootClassPathEntry" group.
*/
public class JvmRTBootClassPathEntryImpl
implements JvmRTBootClassPathEntryMBean, Serializable {
static final long serialVersionUID = -2282652055235913013L;
private final String item;
private final int index;
/**
* Constructor for the "JvmRTBootClassPathEntry" group.
*/
public JvmRTBootClassPathEntryImpl(String item, int index) {
this.item = validPathElementTC(item);
this.index = index;
}
private String validPathElementTC(String str) {
return JVM_MANAGEMENT_MIB_IMPL.validPathElementTC(str);
}
/**
* Getter for the "JvmRTBootClassPathItem" variable.
*/
public String getJvmRTBootClassPathItem() throws SnmpStatusException {
return item;
}
/**
* Getter for the "JvmRTBootClassPathIndex" variable.
*/
public Integer getJvmRTBootClassPathIndex() throws SnmpStatusException {
return new Integer(index);
}
}

View File

@@ -0,0 +1,303 @@
/*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import com.sun.jmx.mbeanserver.Util;
import java.util.List;
import java.util.Map;
// jmx imports
//
import javax.management.MBeanServer;
import javax.management.ObjectName;
import com.sun.jmx.snmp.SnmpCounter;
import com.sun.jmx.snmp.SnmpCounter64;
import com.sun.jmx.snmp.SnmpGauge;
import com.sun.jmx.snmp.SnmpInt;
import com.sun.jmx.snmp.SnmpUnsignedInt;
import com.sun.jmx.snmp.SnmpIpAddress;
import com.sun.jmx.snmp.SnmpTimeticks;
import com.sun.jmx.snmp.SnmpOpaque;
import com.sun.jmx.snmp.SnmpString;
import com.sun.jmx.snmp.SnmpStringFixed;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpNull;
import com.sun.jmx.snmp.SnmpValue;
import com.sun.jmx.snmp.SnmpVarBind;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpIndex;
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.agent.SnmpMibTable;
import com.sun.jmx.snmp.agent.SnmpMibSubRequest;
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
import sun.management.snmp.jvmmib.JvmRTBootClassPathTableMeta;
import sun.management.snmp.util.SnmpCachedData;
import sun.management.snmp.util.SnmpTableCache;
import sun.management.snmp.util.SnmpTableHandler;
import sun.management.snmp.util.MibLogger;
import sun.management.snmp.util.JvmContextFactory;
/**
* The class is used for implementing the "JvmRTBootClassPathTable".
*/
public class JvmRTBootClassPathTableMetaImpl
extends JvmRTBootClassPathTableMeta {
static final long serialVersionUID = -8659886610487538299L;
private SnmpTableCache cache;
/**
* A concrete implementation of {@link SnmpTableCache}, for the
* JvmRTBootClassPathTable.
**/
private static class JvmRTBootClassPathTableCache extends SnmpTableCache {
static final long serialVersionUID = -2637458695413646098L;
private JvmRTBootClassPathTableMetaImpl meta;
JvmRTBootClassPathTableCache(JvmRTBootClassPathTableMetaImpl meta,
long validity) {
this.meta = meta;
this.validity = validity;
}
/**
* Call <code>getTableDatas(JvmContextFactory.getUserData())</code>.
**/
public SnmpTableHandler getTableHandler() {
final Map<Object,Object> userData = JvmContextFactory.getUserData();
return getTableDatas(userData);
}
/**
* Return a table handler containing the Thread indexes.
* Indexes are computed from the ThreadId.
**/
protected SnmpCachedData updateCachedDatas(Object userData) {
// We are getting all the input args
final String[] path =
JvmRuntimeImpl.getBootClassPath(userData);
// Time stamp for the cache
final long time = System.currentTimeMillis();
final int len = path.length;
SnmpOid indexes[] = new SnmpOid[len];
for(int i = 0; i < len; i++) {
indexes[i] = new SnmpOid(i + 1);
}
return new SnmpCachedData(time, indexes, path);
}
}
/**
* Constructor for the table. Initialize metadata for
* "JvmRTBootClassPathTableMeta".
* The reference on the MBean server is updated so the entries
* created through an SNMP SET will be AUTOMATICALLY REGISTERED
* in Java DMK.
*/
public JvmRTBootClassPathTableMetaImpl(SnmpMib myMib,
SnmpStandardObjectServer objserv) {
super(myMib, objserv);
cache = new JvmRTBootClassPathTableCache(this, -1);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(Object userData)
throws SnmpStatusException {
// null means get the first OID.
return getNextOid(null,userData);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(SnmpOid oid, Object userData)
throws SnmpStatusException {
final boolean dbg = log.isDebugOn();
if (dbg) log.debug("getNextOid", "previous=" + oid);
// Get the data handler.
//
SnmpTableHandler handler = getHandler(userData);
if (handler == null) {
// This should never happen.
// If we get here it's a bug.
//
if (dbg) log.debug("getNextOid", "handler is null!");
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the next oid
//
final SnmpOid next = handler.getNext(oid);
if (dbg) log.debug("*** **** **** **** getNextOid", "next=" + next);
// if next is null: we reached the end of the table.
//
if (next == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
return next;
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected boolean contains(SnmpOid oid, Object userData) {
// Get the handler.
//
SnmpTableHandler handler = getHandler(userData);
// handler should never be null.
//
if (handler == null)
return false;
return handler.contains(oid);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
public Object getEntry(SnmpOid oid)
throws SnmpStatusException {
final boolean dbg = log.isDebugOn();
if (dbg) log.debug("getEntry", "oid [" + oid + "]");
if (oid == null || oid.getLength() != 1) {
if (dbg) log.debug("getEntry", "Invalid oid [" + oid + "]");
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the request contextual cache (userData).
//
final Map<Object, Object> m = JvmContextFactory.getUserData();
// We're going to use this name to store/retrieve the entry in
// the request contextual cache.
//
// Revisit: Probably better programming to put all these strings
// in some interface.
//
final String entryTag = ((m==null)?null:
("JvmRTBootClassPathTable.entry." +
oid.toString()));
// If the entry is in the cache, simply return it.
//
if (m != null) {
final Object entry = m.get(entryTag);
if (entry != null) {
if (dbg)
log.debug("getEntry", "Entry is already in the cache");
return entry;
} else
if (dbg) log.debug("getEntry", "Entry is not in the cache");
}
// The entry was not in the cache, make a new one.
//
// Get the data hanler.
//
SnmpTableHandler handler = getHandler(m);
// handler should never be null.
//
if (handler == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// Get the data associated with our entry.
//
final Object data = handler.getData(oid);
// data may be null if the OID we were given is not valid.
//
if (data == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// make the new entry (transient object that will be kept only
// for the duration of the request.
//
if (dbg)
log.debug("getEntry","data is a: " + data.getClass().getName());
final Object entry =
new JvmRTBootClassPathEntryImpl((String) data,
(int) oid.getOidArc(0));
// Put the entry in the cache in case we need it later while processing
// the request.
//
if (m != null && entry != null) {
m.put(entryTag,entry);
}
return entry;
}
/**
* Get the SnmpTableHandler that holds the jvmThreadInstanceTable data.
* First look it up in the request contextual cache, and if it is
* not found, obtain it from the weak cache.
* <br>The request contextual cache will be released at the end of the
* current requests, and is used only to process this request.
* <br>The weak cache is shared by all requests, and is only
* recomputed when it is found to be obsolete.
* <br>Note that the data put in the request contextual cache is
* never considered to be obsolete, in order to preserve data
* coherency.
**/
protected SnmpTableHandler getHandler(Object userData) {
final Map<Object, Object> m;
if (userData instanceof Map) m=Util.cast(userData);
else m=null;
// Look in the contextual cache.
if (m != null) {
final SnmpTableHandler handler =
(SnmpTableHandler)m.get("JvmRTBootClassPathTable.handler");
if (handler != null) return handler;
}
// No handler in contextual cache, make a new one.
final SnmpTableHandler handler = cache.getTableHandler();
if (m != null && handler != null )
m.put("JvmRTBootClassPathTable.handler",handler);
return handler;
}
static final MibLogger log =
new MibLogger(JvmRTBootClassPathTableMetaImpl.class);
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
// jmx imports
//
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import sun.management.snmp.jvmmib.JvmRTClassPathEntryMBean;
/**
* The class is used for implementing the "JvmRTClassPathEntry" group.
*/
public class JvmRTClassPathEntryImpl implements JvmRTClassPathEntryMBean,
Serializable {
static final long serialVersionUID = 8524792845083365742L;
private final String item;
private final int index;
/**
* Constructor for the "JvmRTClassPathEntry" group.
*/
public JvmRTClassPathEntryImpl(String item, int index) {
this.item = validPathElementTC(item);
this.index = index;
}
private String validPathElementTC(String str) {
return JVM_MANAGEMENT_MIB_IMPL.validPathElementTC(str);
}
/**
* Getter for the "JvmRTClassPathItem" variable.
*/
public String getJvmRTClassPathItem() throws SnmpStatusException {
return item;
}
/**
* Getter for the "JvmRTClassPathIndex" variable.
*/
public Integer getJvmRTClassPathIndex() throws SnmpStatusException {
return new Integer(index);
}
}

View File

@@ -0,0 +1,301 @@
/*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import com.sun.jmx.mbeanserver.Util;
import java.util.List;
import java.util.Map;
// jmx imports
//
import javax.management.MBeanServer;
import javax.management.ObjectName;
import com.sun.jmx.snmp.SnmpCounter;
import com.sun.jmx.snmp.SnmpCounter64;
import com.sun.jmx.snmp.SnmpGauge;
import com.sun.jmx.snmp.SnmpInt;
import com.sun.jmx.snmp.SnmpUnsignedInt;
import com.sun.jmx.snmp.SnmpIpAddress;
import com.sun.jmx.snmp.SnmpTimeticks;
import com.sun.jmx.snmp.SnmpOpaque;
import com.sun.jmx.snmp.SnmpString;
import com.sun.jmx.snmp.SnmpStringFixed;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpNull;
import com.sun.jmx.snmp.SnmpValue;
import com.sun.jmx.snmp.SnmpVarBind;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpIndex;
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.agent.SnmpMibTable;
import com.sun.jmx.snmp.agent.SnmpMibSubRequest;
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
import sun.management.snmp.jvmmib.JvmRTClassPathTableMeta;
import sun.management.snmp.util.SnmpCachedData;
import sun.management.snmp.util.SnmpTableCache;
import sun.management.snmp.util.SnmpTableHandler;
import sun.management.snmp.util.MibLogger;
import sun.management.snmp.util.JvmContextFactory;
/**
* The class is used for implementing the "JvmRTClassPathTable".
*/
public class JvmRTClassPathTableMetaImpl extends JvmRTClassPathTableMeta {
static final long serialVersionUID = -6914494148818455166L;
private SnmpTableCache cache;
/**
* A concrete implementation of {@link SnmpTableCache}, for the
* JvmRTClassPathTable.
**/
private static class JvmRTClassPathTableCache extends SnmpTableCache {
static final long serialVersionUID = 3805032372592117315L;
private JvmRTClassPathTableMetaImpl meta;
JvmRTClassPathTableCache(JvmRTClassPathTableMetaImpl meta,
long validity) {
this.meta = meta;
this.validity = validity;
}
/**
* Call <code>getTableDatas(JvmContextFactory.getUserData())</code>.
**/
public SnmpTableHandler getTableHandler() {
final Map<Object, Object> userData = JvmContextFactory.getUserData();
return getTableDatas(userData);
}
/**
* Return a table handler containing the Thread indexes.
* Indexes are computed from the ThreadId.
**/
protected SnmpCachedData updateCachedDatas(Object userData) {
// We are getting all the input args
final String[] path =
JvmRuntimeImpl.getClassPath(userData);
// Time stamp for the cache
final long time = System.currentTimeMillis();
final int len = path.length;
SnmpOid indexes[] = new SnmpOid[len];
for(int i = 0; i < len; i++) {
indexes[i] = new SnmpOid(i + 1);
}
return new SnmpCachedData(time, indexes, path);
}
}
/**
* Constructor for the table. Initialize metadata for
* "JvmRTClassPathTableMeta".
* The reference on the MBean server is updated so the entries
* created through an SNMP SET will be AUTOMATICALLY REGISTERED
* in Java DMK.
*/
public JvmRTClassPathTableMetaImpl(SnmpMib myMib,
SnmpStandardObjectServer objserv) {
super(myMib, objserv);
cache = new JvmRTClassPathTableCache(this, -1);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(Object userData)
throws SnmpStatusException {
// null means get the first OID.
return getNextOid(null,userData);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(SnmpOid oid, Object userData)
throws SnmpStatusException {
final boolean dbg = log.isDebugOn();
if (dbg) log.debug("getNextOid", "previous=" + oid);
// Get the data handler.
//
SnmpTableHandler handler = getHandler(userData);
if (handler == null) {
// This should never happen.
// If we get here it's a bug.
//
if (dbg) log.debug("getNextOid", "handler is null!");
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the next oid
//
final SnmpOid next = handler.getNext(oid);
if (dbg) log.debug("*** **** **** **** getNextOid", "next=" + next);
// if next is null: we reached the end of the table.
//
if (next == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
return next;
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected boolean contains(SnmpOid oid, Object userData) {
// Get the handler.
//
SnmpTableHandler handler = getHandler(userData);
// handler should never be null.
//
if (handler == null)
return false;
return handler.contains(oid);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
public Object getEntry(SnmpOid oid)
throws SnmpStatusException {
final boolean dbg = log.isDebugOn();
if (dbg) log.debug("getEntry", "oid [" + oid + "]");
if (oid == null || oid.getLength() != 1) {
if (dbg) log.debug("getEntry", "Invalid oid [" + oid + "]");
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the request contextual cache (userData).
//
final Map<Object, Object> m = JvmContextFactory.getUserData();
// We're going to use this name to store/retrieve the entry in
// the request contextual cache.
//
// Revisit: Probably better programming to put all these strings
// in some interface.
//
final String entryTag = ((m==null)?null:
("JvmRTClassPathTable.entry." +
oid.toString()));
// If the entry is in the cache, simply return it.
//
if (m != null) {
final Object entry = m.get(entryTag);
if (entry != null) {
if (dbg)
log.debug("getEntry", "Entry is already in the cache");
return entry;
} else
if (dbg) log.debug("getEntry", "Entry is not in the cache");
}
// The entry was not in the cache, make a new one.
//
// Get the data hanler.
//
SnmpTableHandler handler = getHandler(m);
// handler should never be null.
//
if (handler == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// Get the data associated with our entry.
//
final Object data = handler.getData(oid);
// data may be null if the OID we were given is not valid.
//
if (data == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// make the new entry (transient object that will be kept only
// for the duration of the request.
//
if (dbg)
log.debug("getEntry","data is a: " + data.getClass().getName());
final Object entry =
new JvmRTClassPathEntryImpl((String) data, (int) oid.getOidArc(0));
// Put the entry in the cache in case we need it later while processing
// the request.
//
if (m != null && entry != null) {
m.put(entryTag,entry);
}
return entry;
}
/**
* Get the SnmpTableHandler that holds the jvmThreadInstanceTable data.
* First look it up in the request contextual cache, and if it is
* not found, obtain it from the weak cache.
* <br>The request contextual cache will be released at the end of the
* current requests, and is used only to process this request.
* <br>The weak cache is shared by all requests, and is only
* recomputed when it is found to be obsolete.
* <br>Note that the data put in the request contextual cache is
* never considered to be obsolete, in order to preserve data
* coherency.
**/
protected SnmpTableHandler getHandler(Object userData) {
final Map<Object, Object> m;
if (userData instanceof Map) m=Util.cast(userData);
else m=null;
// Look in the contextual cache.
if (m != null) {
final SnmpTableHandler handler =
(SnmpTableHandler)m.get("JvmRTClassPathTable.handler");
if (handler != null) return handler;
}
// No handler in contextual cache, make a new one.
final SnmpTableHandler handler = cache.getTableHandler();
if (m != null && handler != null )
m.put("JvmRTClassPathTable.handler",handler);
return handler;
}
static final MibLogger log =
new MibLogger(JvmRTClassPathTableMetaImpl.class);
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
// jmx imports
//
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import sun.management.snmp.jvmmib.JvmRTInputArgsEntryMBean;
/**
* The class is used for implementing the "JvmRTInputArgsEntry" group.
*/
public class JvmRTInputArgsEntryImpl implements JvmRTInputArgsEntryMBean,
Serializable {
static final long serialVersionUID = 1000306518436503395L;
private final String item;
private final int index;
/**
* Constructor for the "JvmRTInputArgsEntry" group.
*/
public JvmRTInputArgsEntryImpl(String item, int index) {
this.item = validArgValueTC(item);
this.index = index;
}
private String validArgValueTC(String str) {
return JVM_MANAGEMENT_MIB_IMPL.validArgValueTC(str);
}
/**
* Getter for the "JvmRTInputArgsItem" variable.
*/
public String getJvmRTInputArgsItem() throws SnmpStatusException {
return item;
}
/**
* Getter for the "JvmRTInputArgsIndex" variable.
*/
public Integer getJvmRTInputArgsIndex() throws SnmpStatusException {
return new Integer(index);
}
}

View File

@@ -0,0 +1,297 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import com.sun.jmx.mbeanserver.Util;
import java.util.List;
import java.util.Map;
// jmx imports
//
import javax.management.MBeanServer;
import javax.management.ObjectName;
import com.sun.jmx.snmp.SnmpCounter;
import com.sun.jmx.snmp.SnmpCounter64;
import com.sun.jmx.snmp.SnmpGauge;
import com.sun.jmx.snmp.SnmpInt;
import com.sun.jmx.snmp.SnmpUnsignedInt;
import com.sun.jmx.snmp.SnmpIpAddress;
import com.sun.jmx.snmp.SnmpTimeticks;
import com.sun.jmx.snmp.SnmpOpaque;
import com.sun.jmx.snmp.SnmpString;
import com.sun.jmx.snmp.SnmpStringFixed;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpNull;
import com.sun.jmx.snmp.SnmpValue;
import com.sun.jmx.snmp.SnmpVarBind;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpIndex;
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.agent.SnmpMibTable;
import com.sun.jmx.snmp.agent.SnmpMibSubRequest;
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
import sun.management.snmp.jvmmib.JvmRTInputArgsTableMeta;
import sun.management.snmp.util.SnmpCachedData;
import sun.management.snmp.util.SnmpTableCache;
import sun.management.snmp.util.SnmpTableHandler;
import sun.management.snmp.util.MibLogger;
import sun.management.snmp.util.JvmContextFactory;
/**
* The class is used for implementing the "JvmRTInputArgsTable" group.
*/
public class JvmRTInputArgsTableMetaImpl extends JvmRTInputArgsTableMeta {
static final long serialVersionUID = -2083438094888099238L;
private SnmpTableCache cache;
/**
* A concrete implementation of {@link SnmpTableCache}, for the
* JvmRTInputArgsTable.
**/
private static class JvmRTInputArgsTableCache extends SnmpTableCache {
static final long serialVersionUID = 1693751105464785192L;
private JvmRTInputArgsTableMetaImpl meta;
JvmRTInputArgsTableCache(JvmRTInputArgsTableMetaImpl meta,
long validity) {
this.meta = meta;
this.validity = validity;
}
/**
* Call <code>getTableDatas(JvmContextFactory.getUserData())</code>.
**/
public SnmpTableHandler getTableHandler() {
final Map<Object,Object> userData = JvmContextFactory.getUserData();
return getTableDatas(userData);
}
/**
* Return a table handler containing the Thread indexes.
* Indexes are computed from the ThreadId.
**/
protected SnmpCachedData updateCachedDatas(Object userData) {
// We are getting all the input args
final String[] args = JvmRuntimeImpl.getInputArguments(userData);
// Time stamp for the cache
final long time = System.currentTimeMillis();
SnmpOid indexes[] = new SnmpOid[args.length];
for(int i = 0; i < args.length; i++) {
indexes[i] = new SnmpOid(i + 1);
}
return new SnmpCachedData(time, indexes, args);
}
}
/**
* Constructor for the table. Initialize metadata for
* "JvmRTInputArgsTableMeta".
* The reference on the MBean server is updated so the entries
* created through an SNMP SET will be AUTOMATICALLY REGISTERED
* in Java DMK.
*/
public JvmRTInputArgsTableMetaImpl(SnmpMib myMib,
SnmpStandardObjectServer objserv) {
super(myMib, objserv);
cache = new JvmRTInputArgsTableCache(this, -1);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(Object userData)
throws SnmpStatusException {
// null means get the first OID.
return getNextOid(null,userData);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(SnmpOid oid, Object userData)
throws SnmpStatusException {
final boolean dbg = log.isDebugOn();
if (dbg) log.debug("getNextOid", "previous=" + oid);
// Get the data handler.
//
SnmpTableHandler handler = getHandler(userData);
if (handler == null) {
// This should never happen.
// If we get here it's a bug.
//
if (dbg) log.debug("getNextOid", "handler is null!");
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the next oid
//
final SnmpOid next = handler.getNext(oid);
if (dbg) log.debug("*** **** **** **** getNextOid", "next=" + next);
// if next is null: we reached the end of the table.
//
if (next == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
return next;
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected boolean contains(SnmpOid oid, Object userData) {
// Get the handler.
//
SnmpTableHandler handler = getHandler(userData);
// handler should never be null.
//
if (handler == null)
return false;
return handler.contains(oid);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
public Object getEntry(SnmpOid oid)
throws SnmpStatusException {
final boolean dbg = log.isDebugOn();
if (dbg) log.debug("getEntry", "oid [" + oid + "]");
if (oid == null || oid.getLength() != 1) {
if (dbg) log.debug("getEntry", "Invalid oid [" + oid + "]");
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the request contextual cache (userData).
//
final Map<Object, Object> m = JvmContextFactory.getUserData();
// We're going to use this name to store/retrieve the entry in
// the request contextual cache.
//
// Revisit: Probably better programming to put all these strings
// in some interface.
//
final String entryTag = ((m==null)?null:
("JvmRTInputArgsTable.entry." +
oid.toString()));
// If the entry is in the cache, simply return it.
//
if (m != null) {
final Object entry = m.get(entryTag);
if (entry != null) {
if (dbg)
log.debug("getEntry", "Entry is already in the cache");
return entry;
} else if (dbg) log.debug("getEntry", "Entry is not in the cache");
}
// The entry was not in the cache, make a new one.
//
// Get the data hanler.
//
SnmpTableHandler handler = getHandler(m);
// handler should never be null.
//
if (handler == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// Get the data associated with our entry.
//
final Object data = handler.getData(oid);
// data may be null if the OID we were given is not valid.
//
if (data == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// make the new entry (transient object that will be kept only
// for the duration of the request.
//
if (dbg) log.debug("getEntry","data is a: " +
data.getClass().getName());
final Object entry =
new JvmRTInputArgsEntryImpl((String) data, (int) oid.getOidArc(0));
// Put the entry in the cache in case we need it later while processing
// the request.
//
if (m != null && entry != null) {
m.put(entryTag,entry);
}
return entry;
}
/**
* Get the SnmpTableHandler that holds the jvmThreadInstanceTable data.
* First look it up in the request contextual cache, and if it is
* not found, obtain it from the weak cache.
* <br>The request contextual cache will be released at the end of the
* current requests, and is used only to process this request.
* <br>The weak cache is shared by all requests, and is only
* recomputed when it is found to be obsolete.
* <br>Note that the data put in the request contextual cache is
* never considered to be obsolete, in order to preserve data
* coherency.
**/
protected SnmpTableHandler getHandler(Object userData) {
final Map<Object, Object> m;
if (userData instanceof Map) m=Util.cast(userData);
else m=null;
// Look in the contextual cache.
if (m != null) {
final SnmpTableHandler handler =
(SnmpTableHandler)m.get("JvmRTInputArgsTable.handler");
if (handler != null) return handler;
}
// No handler in contextual cache, make a new one.
final SnmpTableHandler handler = cache.getTableHandler();
if (m != null && handler != null )
m.put("JvmRTInputArgsTable.handler",handler);
return handler;
}
static final MibLogger log =
new MibLogger(JvmRTInputArgsTableMetaImpl.class);
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
// jmx imports
//
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import sun.management.snmp.jvmmib.JvmRTLibraryPathEntryMBean;
/**
* The class is used for implementing the "JvmRTLibraryPathEntry" group.
*/
public class JvmRTLibraryPathEntryImpl implements JvmRTLibraryPathEntryMBean,
Serializable {
static final long serialVersionUID = -3322438153507369765L;
private final String item;
private final int index;
/**
* Constructor for the "JvmRTLibraryPathEntry" group.
*/
public JvmRTLibraryPathEntryImpl(String item, int index) {
this.item = validPathElementTC(item);
this.index = index;
}
private String validPathElementTC(String str) {
return JVM_MANAGEMENT_MIB_IMPL.validPathElementTC(str);
}
/**
* Getter for the "JvmRTLibraryPathItem" variable.
*/
public String getJvmRTLibraryPathItem() throws SnmpStatusException {
return item;
}
/**
* Getter for the "JvmRTLibraryPathIndex" variable.
*/
public Integer getJvmRTLibraryPathIndex() throws SnmpStatusException {
return new Integer(index);
}
}

View File

@@ -0,0 +1,300 @@
/*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import com.sun.jmx.mbeanserver.Util;
import java.util.List;
import java.util.Map;
// jmx imports
//
import javax.management.MBeanServer;
import javax.management.ObjectName;
import com.sun.jmx.snmp.SnmpCounter;
import com.sun.jmx.snmp.SnmpCounter64;
import com.sun.jmx.snmp.SnmpGauge;
import com.sun.jmx.snmp.SnmpInt;
import com.sun.jmx.snmp.SnmpUnsignedInt;
import com.sun.jmx.snmp.SnmpIpAddress;
import com.sun.jmx.snmp.SnmpTimeticks;
import com.sun.jmx.snmp.SnmpOpaque;
import com.sun.jmx.snmp.SnmpString;
import com.sun.jmx.snmp.SnmpStringFixed;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpNull;
import com.sun.jmx.snmp.SnmpValue;
import com.sun.jmx.snmp.SnmpVarBind;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpIndex;
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.agent.SnmpMibTable;
import com.sun.jmx.snmp.agent.SnmpMibSubRequest;
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
import sun.management.snmp.jvmmib.JvmRTLibraryPathTableMeta;
import sun.management.snmp.util.SnmpCachedData;
import sun.management.snmp.util.SnmpTableCache;
import sun.management.snmp.util.SnmpTableHandler;
import sun.management.snmp.util.MibLogger;
import sun.management.snmp.util.JvmContextFactory;
/**
* The class is used for implementing the "JvmRTLibraryPathTable".
*/
public class JvmRTLibraryPathTableMetaImpl extends JvmRTLibraryPathTableMeta {
static final long serialVersionUID = 6713252710712502068L;
private SnmpTableCache cache;
/**
* A concrete implementation of {@link SnmpTableCache}, for the
* JvmRTLibraryPathTable.
**/
private static class JvmRTLibraryPathTableCache extends SnmpTableCache {
static final long serialVersionUID = 2035304445719393195L;
private JvmRTLibraryPathTableMetaImpl meta;
JvmRTLibraryPathTableCache(JvmRTLibraryPathTableMetaImpl meta,
long validity) {
this.meta = meta;
this.validity = validity;
}
/**
* Call <code>getTableDatas(JvmContextFactory.getUserData())</code>.
**/
public SnmpTableHandler getTableHandler() {
final Map<Object,Object> userData = JvmContextFactory.getUserData();
return getTableDatas(userData);
}
/**
* Return a table handler containing the Thread indexes.
* Indexes are computed from the ThreadId.
**/
protected SnmpCachedData updateCachedDatas(Object userData) {
// We are getting all the input args
final String[] path =
JvmRuntimeImpl.getLibraryPath(userData);
// Time stamp for the cache
final long time = System.currentTimeMillis();
final int len = path.length;
SnmpOid indexes[] = new SnmpOid[len];
for(int i = 0; i < len; i++) {
indexes[i] = new SnmpOid(i + 1);
}
return new SnmpCachedData(time, indexes, path);
}
}
/**
* Constructor for the table. Initialize metadata for
* "JvmRTLibraryPathTableMeta".
* The reference on the MBean server is updated so the entries
* created through an SNMP SET will be AUTOMATICALLY REGISTERED
* in Java DMK.
*/
public JvmRTLibraryPathTableMetaImpl(SnmpMib myMib,
SnmpStandardObjectServer objserv) {
super(myMib, objserv);
cache = new JvmRTLibraryPathTableCache(this, -1);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(Object userData)
throws SnmpStatusException {
// null means get the first OID.
return getNextOid(null,userData);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(SnmpOid oid, Object userData)
throws SnmpStatusException {
final boolean dbg = log.isDebugOn();
if (dbg) log.debug("getNextOid", "previous=" + oid);
// Get the data handler.
//
SnmpTableHandler handler = getHandler(userData);
if (handler == null) {
// This should never happen.
// If we get here it's a bug.
//
if (dbg) log.debug("getNextOid", "handler is null!");
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the next oid
//
final SnmpOid next = handler.getNext(oid);
if (dbg) log.debug("*** **** **** **** getNextOid", "next=" + next);
// if next is null: we reached the end of the table.
//
if (next == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
return next;
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected boolean contains(SnmpOid oid, Object userData) {
// Get the handler.
//
SnmpTableHandler handler = getHandler(userData);
// handler should never be null.
//
if (handler == null)
return false;
return handler.contains(oid);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
public Object getEntry(SnmpOid oid)
throws SnmpStatusException {
final boolean dbg = log.isDebugOn();
if (dbg) log.debug("getEntry", "oid [" + oid + "]");
if (oid == null || oid.getLength() != 1) {
if (dbg) log.debug("getEntry", "Invalid oid [" + oid + "]");
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the request contextual cache (userData).
//
final Map<Object, Object> m = JvmContextFactory.getUserData();
// We're going to use this name to store/retrieve the entry in
// the request contextual cache.
//
// Revisit: Probably better programming to put all these strings
// in some interface.
//
final String entryTag = ((m==null)?null:
("JvmRTLibraryPathTable.entry." +
oid.toString()));
// If the entry is in the cache, simply return it.
//
if (m != null) {
final Object entry = m.get(entryTag);
if (entry != null) {
if (dbg)
log.debug("getEntry", "Entry is already in the cache");
return entry;
} else if (dbg) log.debug("getEntry", "Entry is not in the cache");
}
// The entry was not in the cache, make a new one.
//
// Get the data hanler.
//
SnmpTableHandler handler = getHandler(m);
// handler should never be null.
//
if (handler == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// Get the data associated with our entry.
//
final Object data = handler.getData(oid);
// data may be null if the OID we were given is not valid.
//
if (data == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
// make the new entry (transient object that will be kept only
// for the duration of the request.
//
if (dbg) log.debug("getEntry","data is a: "+
data.getClass().getName());
final Object entry =
new JvmRTLibraryPathEntryImpl((String) data,(int)oid.getOidArc(0));
// Put the entry in the cache in case we need it later while processing
// the request.
//
if (m != null && entry != null) {
m.put(entryTag,entry);
}
return entry;
}
/**
* Get the SnmpTableHandler that holds the jvmThreadInstanceTable data.
* First look it up in the request contextual cache, and if it is
* not found, obtain it from the weak cache.
* <br>The request contextual cache will be released at the end of the
* current requests, and is used only to process this request.
* <br>The weak cache is shared by all requests, and is only
* recomputed when it is found to be obsolete.
* <br>Note that the data put in the request contextual cache is
* never considered to be obsolete, in order to preserve data
* coherency.
**/
protected SnmpTableHandler getHandler(Object userData) {
final Map<Object, Object> m;
if (userData instanceof Map) m=Util.cast(userData);
else m=null;
// Look in the contextual cache.
if (m != null) {
final SnmpTableHandler handler =
(SnmpTableHandler)m.get("JvmRTLibraryPathTable.handler");
if (handler != null) return handler;
}
// No handler in contextual cache, make a new one.
final SnmpTableHandler handler = cache.getTableHandler();
if (m != null && handler != null )
m.put("JvmRTLibraryPathTable.handler",handler);
return handler;
}
static final MibLogger log =
new MibLogger(JvmRTLibraryPathTableMetaImpl.class);
}

View File

@@ -0,0 +1,286 @@
/*
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import com.sun.jmx.mbeanserver.Util;
import java.io.Serializable;
import java.lang.management.RuntimeMXBean;
import java.lang.management.ManagementFactory;
import java.util.List;
import java.util.Map;
// jmx imports
//
import javax.management.MBeanServer;
import com.sun.jmx.snmp.SnmpString;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import sun.management.snmp.jvmmib.JvmRuntimeMBean;
import sun.management.snmp.jvmmib.EnumJvmRTBootClassPathSupport;
import sun.management.snmp.util.JvmContextFactory;
/**
* The class is used for implementing the "JvmRuntime" group.
*/
public class JvmRuntimeImpl implements JvmRuntimeMBean {
/**
* Variable for storing the value of "JvmRTBootClassPathSupport".
*
* "Indicates whether the Java virtual machine supports the
* boot class path mechanism used by the system class loader
* to search for class files.
*
* See java.management.RuntimeMXBean.isBootClassPathSupported()
* "
*
*/
static final EnumJvmRTBootClassPathSupport
JvmRTBootClassPathSupportSupported =
new EnumJvmRTBootClassPathSupport("supported");
static final EnumJvmRTBootClassPathSupport
JvmRTBootClassPathSupportUnSupported =
new EnumJvmRTBootClassPathSupport("unsupported");
/**
* Constructor for the "JvmRuntime" group.
* If the group contains a table, the entries created through an SNMP SET
* will not be registered in Java DMK.
*/
public JvmRuntimeImpl(SnmpMib myMib) {
}
/**
* Constructor for the "JvmRuntime" group.
* If the group contains a table, the entries created through an SNMP SET
* will be AUTOMATICALLY REGISTERED in Java DMK.
*/
public JvmRuntimeImpl(SnmpMib myMib, MBeanServer server) {
}
static RuntimeMXBean getRuntimeMXBean() {
return ManagementFactory.getRuntimeMXBean();
}
private static String validDisplayStringTC(String str) {
return JVM_MANAGEMENT_MIB_IMPL.validDisplayStringTC(str);
}
private static String validPathElementTC(String str) {
return JVM_MANAGEMENT_MIB_IMPL.validPathElementTC(str);
}
private static String validJavaObjectNameTC(String str) {
return JVM_MANAGEMENT_MIB_IMPL.validJavaObjectNameTC(str);
}
static String[] splitPath(String path) {
final String[] items = path.split(java.io.File.pathSeparator);
// for (int i=0;i<items.length;i++) {
// items[i]=validPathElementTC(items[i]);
// }
return items;
}
static String[] getClassPath(Object userData) {
final Map<Object, Object> m =
Util.cast((userData instanceof Map)?userData:null);
final String tag = "JvmRuntime.getClassPath";
// If the list is in the cache, simply return it.
//
if (m != null) {
final String[] cached = (String[])m.get(tag);
if (cached != null) return cached;
}
final String[] args = splitPath(getRuntimeMXBean().getClassPath());
if (m != null) m.put(tag,args);
return args;
}
static String[] getBootClassPath(Object userData) {
if (!getRuntimeMXBean().isBootClassPathSupported())
return new String[0];
final Map<Object, Object> m =
Util.cast((userData instanceof Map)?userData:null);
final String tag = "JvmRuntime.getBootClassPath";
// If the list is in the cache, simply return it.
//
if (m != null) {
final String[] cached = (String[])m.get(tag);
if (cached != null) return cached;
}
final String[] args = splitPath(getRuntimeMXBean().getBootClassPath());
if (m != null) m.put(tag,args);
return args;
}
static String[] getLibraryPath(Object userData) {
final Map<Object, Object> m =
Util.cast((userData instanceof Map)?userData:null);
final String tag = "JvmRuntime.getLibraryPath";
// If the list is in the cache, simply return it.
//
if (m != null) {
final String[] cached = (String[])m.get(tag);
if (cached != null) return cached;
}
final String[] args = splitPath(getRuntimeMXBean().getLibraryPath());
if (m != null) m.put(tag,args);
return args;
}
static String[] getInputArguments(Object userData) {
final Map<Object, Object> m =
Util.cast((userData instanceof Map)?userData:null);
final String tag = "JvmRuntime.getInputArguments";
// If the list is in the cache, simply return it.
//
if (m != null) {
final String[] cached = (String[])m.get(tag);
if (cached != null) return cached;
}
final List<String> l = getRuntimeMXBean().getInputArguments();
final String[] args = l.toArray(new String[0]);
if (m != null) m.put(tag,args);
return args;
}
/**
* Getter for the "JvmRTSpecVendor" variable.
*/
public String getJvmRTSpecVendor() throws SnmpStatusException {
return validDisplayStringTC(getRuntimeMXBean().getSpecVendor());
}
/**
* Getter for the "JvmRTSpecName" variable.
*/
public String getJvmRTSpecName() throws SnmpStatusException {
return validDisplayStringTC(getRuntimeMXBean().getSpecName());
}
/**
* Getter for the "JvmRTVersion" variable.
*/
public String getJvmRTVMVersion() throws SnmpStatusException {
return validDisplayStringTC(getRuntimeMXBean().getVmVersion());
}
/**
* Getter for the "JvmRTVendor" variable.
*/
public String getJvmRTVMVendor() throws SnmpStatusException {
return validDisplayStringTC(getRuntimeMXBean().getVmVendor());
}
/**
* Getter for the "JvmRTManagementSpecVersion" variable.
*/
public String getJvmRTManagementSpecVersion() throws SnmpStatusException {
return validDisplayStringTC(getRuntimeMXBean().
getManagementSpecVersion());
}
/**
* Getter for the "JvmRTVMName" variable.
*/
public String getJvmRTVMName() throws SnmpStatusException {
return validJavaObjectNameTC(getRuntimeMXBean().getVmName());
}
/**
* Getter for the "JvmRTInputArgsCount" variable.
*/
public Integer getJvmRTInputArgsCount() throws SnmpStatusException {
final String[] args = getInputArguments(JvmContextFactory.
getUserData());
return new Integer(args.length);
}
/**
* Getter for the "JvmRTBootClassPathSupport" variable.
*/
public EnumJvmRTBootClassPathSupport getJvmRTBootClassPathSupport()
throws SnmpStatusException {
if(getRuntimeMXBean().isBootClassPathSupported())
return JvmRTBootClassPathSupportSupported;
else
return JvmRTBootClassPathSupportUnSupported;
}
/**
* Getter for the "JvmRTUptimeMs" variable.
*/
public Long getJvmRTUptimeMs() throws SnmpStatusException {
return new Long(getRuntimeMXBean().getUptime());
}
/**
* Getter for the "JvmRTStartTimeMs" variable.
*/
public Long getJvmRTStartTimeMs() throws SnmpStatusException {
return new Long(getRuntimeMXBean().getStartTime());
}
/**
* Getter for the "JvmRTSpecVersion" variable.
*/
public String getJvmRTSpecVersion() throws SnmpStatusException {
return validDisplayStringTC(getRuntimeMXBean().getSpecVersion());
}
/**
* Getter for the "JvmRTName" variable.
*/
public String getJvmRTName() throws SnmpStatusException {
return validDisplayStringTC(getRuntimeMXBean().getName());
}
}

View File

@@ -0,0 +1,175 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
// jmx imports
//
import javax.management.MBeanServer;
import com.sun.jmx.snmp.SnmpCounter;
import com.sun.jmx.snmp.SnmpCounter64;
import com.sun.jmx.snmp.SnmpGauge;
import com.sun.jmx.snmp.SnmpInt;
import com.sun.jmx.snmp.SnmpUnsignedInt;
import com.sun.jmx.snmp.SnmpIpAddress;
import com.sun.jmx.snmp.SnmpTimeticks;
import com.sun.jmx.snmp.SnmpOpaque;
import com.sun.jmx.snmp.SnmpString;
import com.sun.jmx.snmp.SnmpStringFixed;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpNull;
import com.sun.jmx.snmp.SnmpValue;
import com.sun.jmx.snmp.SnmpVarBind;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.agent.SnmpMibGroup;
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
import com.sun.jmx.snmp.agent.SnmpStandardMetaServer;
import com.sun.jmx.snmp.agent.SnmpMibSubRequest;
import com.sun.jmx.snmp.agent.SnmpMibTable;
import com.sun.jmx.snmp.EnumRowStatus;
import sun.management.snmp.jvmmib.JvmRuntimeMeta;
import sun.management.snmp.jvmmib.JvmRTInputArgsTableMeta;
import sun.management.snmp.jvmmib.JvmRTClassPathTableMeta;
import sun.management.snmp.jvmmib.JvmRTBootClassPathTableMeta;
import sun.management.snmp.jvmmib.JvmRTLibraryPathTableMeta;
/**
* The class is used for representing SNMP metadata for the "JvmRuntime" group.
*/
public class JvmRuntimeMetaImpl extends JvmRuntimeMeta {
static final long serialVersionUID = -6570428414857608618L;
/**
* Constructor for the metadata associated to "JvmRuntime".
*/
public JvmRuntimeMetaImpl(SnmpMib myMib,
SnmpStandardObjectServer objserv) {
super(myMib, objserv);
}
/**
* Factory method for "JvmRTInputArgsTable" table metadata class.
*
* You can redefine this method if you need to replace the default
* generated metadata class with your own customized class.
*
* @param tableName Name of the table object ("JvmRTInputArgsTable")
* @param groupName Name of the group to which this table belong
* ("JvmRuntime")
* @param mib The SnmpMib object in which this table is registered
* @param server MBeanServer for this table entries (may be null)
*
* @return An instance of the metadata class generated for the
* "JvmRTInputArgsTable" table (JvmRTInputArgsTableMeta)
*
**/
protected JvmRTInputArgsTableMeta
createJvmRTInputArgsTableMetaNode(String tableName, String groupName,
SnmpMib mib, MBeanServer server) {
return new JvmRTInputArgsTableMetaImpl(mib, objectserver);
}
/**
* Factory method for "JvmRTLibraryPathTable" table metadata class.
*
* You can redefine this method if you need to replace the default
* generated metadata class with your own customized class.
*
* @param tableName Name of the table object ("JvmRTLibraryPathTable")
* @param groupName Name of the group to which this table belong
* ("JvmRuntime")
* @param mib The SnmpMib object in which this table is registered
* @param server MBeanServer for this table entries (may be null)
*
* @return An instance of the metadata class generated for the
* "JvmRTLibraryPathTable" table (JvmRTLibraryPathTableMeta)
*
**/
protected JvmRTLibraryPathTableMeta
createJvmRTLibraryPathTableMetaNode(String tableName,
String groupName,
SnmpMib mib,
MBeanServer server) {
return new JvmRTLibraryPathTableMetaImpl(mib, objectserver);
}
/**
* Factory method for "JvmRTClassPathTable" table metadata class.
*
* You can redefine this method if you need to replace the default
* generated metadata class with your own customized class.
*
* @param tableName Name of the table object ("JvmRTClassPathTable")
* @param groupName Name of the group to which this table belong
* ("JvmRuntime")
* @param mib The SnmpMib object in which this table is registered
* @param server MBeanServer for this table entries (may be null)
*
* @return An instance of the metadata class generated for the
* "JvmRTClassPathTable" table (JvmRTClassPathTableMeta)
*
**/
protected JvmRTClassPathTableMeta
createJvmRTClassPathTableMetaNode(String tableName, String groupName,
SnmpMib mib, MBeanServer server) {
return new JvmRTClassPathTableMetaImpl(mib, objectserver);
}
/**
* Factory method for "JvmRTBootClassPathTable" table metadata class.
*
* You can redefine this method if you need to replace the default
* generated metadata class with your own customized class.
*
* @param tableName Name of the table object ("JvmRTBootClassPathTable")
* @param groupName Name of the group to which this table belong
* ("JvmRuntime")
* @param mib The SnmpMib object in which this table is registered
* @param server MBeanServer for this table entries (may be null)
*
* @return An instance of the metadata class generated for the
* "JvmRTBootClassPathTable" table (JvmRTBootClassPathTableMeta)
*
**/
protected JvmRTBootClassPathTableMeta
createJvmRTBootClassPathTableMetaNode(String tableName,
String groupName,
SnmpMib mib,
MBeanServer server) {
return new JvmRTBootClassPathTableMetaImpl(mib, objectserver);
}
}

View File

@@ -0,0 +1,330 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
import java.lang.management.ThreadInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
// jmx imports
//
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpDefinitions;
import com.sun.jmx.snmp.SnmpOidTable;
import com.sun.jmx.snmp.SnmpOidRecord;
import sun.management.snmp.jvmmib.JvmThreadInstanceEntryMBean;
import sun.management.snmp.jvmmib.JVM_MANAGEMENT_MIBOidTable;
import sun.management.snmp.util.MibLogger;
/**
* The class is used for implementing the "JvmThreadInstanceEntry" group.
*/
public class JvmThreadInstanceEntryImpl
implements JvmThreadInstanceEntryMBean, Serializable {
static final long serialVersionUID = 910173589985461347L;
public final static class ThreadStateMap {
public final static class Byte0 {
public final static byte inNative = (byte)0x80; // bit 1
public final static byte suspended = (byte)0x40; // bit 2
public final static byte newThread = (byte)0x20; // bit 3
public final static byte runnable = (byte)0x10; // bit 4
public final static byte blocked = (byte)0x08; // bit 5
public final static byte terminated = (byte)0x04; // bit 6
public final static byte waiting = (byte)0x02; // bit 7
public final static byte timedWaiting = (byte)0x01; // bit 8
}
public final static class Byte1 {
public final static byte other = (byte)0x80; // bit 9
public final static byte reserved10 = (byte)0x40; // bit 10
public final static byte reserved11 = (byte)0x20; // bit 11
public final static byte reserved12 = (byte)0x10; // bit 12
public final static byte reserved13 = (byte)0x08; // bit 13
public final static byte reserved14 = (byte)0x04; // bit 14
public final static byte reserved15 = (byte)0x02; // bit 15
public final static byte reserved16 = (byte)0x01; // bit 16
}
public final static byte mask0 = (byte)0x3F;
public final static byte mask1 = (byte)0x80;
private static void setBit(byte[] bitmap, int index, byte state) {
bitmap[index] = (byte) (bitmap[index] | state);
}
public static void setNative(byte[] bitmap) {
setBit(bitmap,0,Byte0.inNative);
}
public static void setSuspended(byte[] bitmap) {
setBit(bitmap,0,Byte0.suspended);
}
public static void setState(byte[] bitmap, Thread.State state) {
switch(state) {
case BLOCKED:
setBit(bitmap,0,Byte0.blocked);
return;
case NEW:
setBit(bitmap,0,Byte0.newThread);
return;
case RUNNABLE:
setBit(bitmap,0,Byte0.runnable);
return;
case TERMINATED:
setBit(bitmap,0,Byte0.terminated);
return;
case TIMED_WAITING:
setBit(bitmap,0,Byte0.timedWaiting);
return;
case WAITING:
setBit(bitmap,0,Byte0.waiting);
return;
}
}
public static void checkOther(byte[] bitmap) {
if (((bitmap[0]&mask0)==(byte)0x00) &&
((bitmap[1]&mask1)==(byte)0x00))
setBit(bitmap,1,Byte1.other);
}
public static Byte[] getState(ThreadInfo info) {
byte[] bitmap = new byte[] {(byte)0x00, (byte)0x00};
try {
final Thread.State state = info.getThreadState();
final boolean inNative = info.isInNative();
final boolean suspended = info.isSuspended();
log.debug("getJvmThreadInstState",
"[State=" + state +
",isInNative=" + inNative +
",isSuspended=" + suspended + "]");
setState(bitmap,state);
if (inNative) setNative(bitmap);
if (suspended) setSuspended(bitmap);
checkOther(bitmap);
} catch (RuntimeException r) {
bitmap[0]=(byte)0x00;
bitmap[1]=Byte1.other;
log.trace("getJvmThreadInstState",
"Unexpected exception: " + r);
log.debug("getJvmThreadInstState",r);
}
Byte[] result = { new Byte(bitmap[0]), new Byte(bitmap[1]) };
return result;
}
}
private final ThreadInfo info;
private final Byte[] index;
/**
* Constructor for the "JvmThreadInstanceEntry" group.
*/
public JvmThreadInstanceEntryImpl(ThreadInfo info,
Byte[] index) {
this.info = info;
this.index = index;
}
private static String jvmThreadInstIndexOid = null;
public static String getJvmThreadInstIndexOid()
throws SnmpStatusException {
if (jvmThreadInstIndexOid == null) {
final SnmpOidTable table = new JVM_MANAGEMENT_MIBOidTable();
final SnmpOidRecord record =
table.resolveVarName("jvmThreadInstIndex");
jvmThreadInstIndexOid = record.getOid();
}
return jvmThreadInstIndexOid;
}
/**
* Getter for the "JvmThreadInstLockedOwnerId" variable.
*/
public String getJvmThreadInstLockOwnerPtr() throws SnmpStatusException {
long id = info.getLockOwnerId();
if(id == -1)
return new String("0.0");
SnmpOid oid = JvmThreadInstanceTableMetaImpl.makeOid(id);
return getJvmThreadInstIndexOid() + "." + oid.toString();
}
private String validDisplayStringTC(String str) {
return JVM_MANAGEMENT_MIB_IMPL.validDisplayStringTC(str);
}
private String validJavaObjectNameTC(String str) {
return JVM_MANAGEMENT_MIB_IMPL.validJavaObjectNameTC(str);
}
private String validPathElementTC(String str) {
return JVM_MANAGEMENT_MIB_IMPL.validPathElementTC(str);
}
/**
* Getter for the "JvmThreadInstLockName" variable.
*/
public String getJvmThreadInstLockName() throws SnmpStatusException {
return validJavaObjectNameTC(info.getLockName());
}
/**
* Getter for the "JvmThreadInstName" variable.
*/
public String getJvmThreadInstName() throws SnmpStatusException {
return validJavaObjectNameTC(info.getThreadName());
}
/**
* Getter for the "JvmThreadInstCpuTimeNs" variable.
*/
public Long getJvmThreadInstCpuTimeNs() throws SnmpStatusException {
long l = 0;
final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();
try {
if (tmb.isThreadCpuTimeSupported()) {
l = tmb.getThreadCpuTime(info.getThreadId());
log.debug("getJvmThreadInstCpuTimeNs", "Cpu time ns : " + l);
//Cpu time measurement is disabled or the id is not valid.
if(l == -1) l = 0;
}
} catch (UnsatisfiedLinkError e) {
// XXX Revisit: catch TO BE EVENTUALLY REMOVED
log.debug("getJvmThreadInstCpuTimeNs",
"Operation not supported: " + e);
}
return new Long(l);
}
/**
* Getter for the "JvmThreadInstBlockTimeMs" variable.
*/
public Long getJvmThreadInstBlockTimeMs() throws SnmpStatusException {
long l = 0;
final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();
if (tmb.isThreadContentionMonitoringSupported()) {
l = info.getBlockedTime();
//Monitoring is disabled
if(l == -1) l = 0;
}
return new Long(l);
}
/**
* Getter for the "JvmThreadInstBlockCount" variable.
*/
public Long getJvmThreadInstBlockCount() throws SnmpStatusException {
return new Long(info.getBlockedCount());
}
/**
* Getter for the "JvmThreadInstWaitTimeMs" variable.
*/
public Long getJvmThreadInstWaitTimeMs() throws SnmpStatusException {
long l = 0;
final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();
if (tmb.isThreadContentionMonitoringSupported()) {
l = info.getWaitedTime();
//Monitoring is disabled
if(l == -1) l = 0;
}
return new Long(l);
}
/**
* Getter for the "JvmThreadInstWaitCount" variable.
*/
public Long getJvmThreadInstWaitCount() throws SnmpStatusException {
return new Long(info.getWaitedCount());
}
/**
* Getter for the "JvmThreadInstState" variable.
*/
public Byte[] getJvmThreadInstState()
throws SnmpStatusException {
return ThreadStateMap.getState(info);
}
/**
* Getter for the "JvmThreadInstId" variable.
*/
public Long getJvmThreadInstId() throws SnmpStatusException {
return new Long(info.getThreadId());
}
/**
* Getter for the "JvmThreadInstIndex" variable.
*/
public Byte[] getJvmThreadInstIndex() throws SnmpStatusException {
return index;
}
/**
* Getter for the "JvmThreadInstStackTrace" variable.
*/
private String getJvmThreadInstStackTrace() throws SnmpStatusException {
StackTraceElement[] stackTrace = info.getStackTrace();
//We append the stack trace in a buffer
// XXX Revisit: should check isDebugOn()
StringBuffer b = new StringBuffer();
final int stackSize = stackTrace.length;
log.debug("getJvmThreadInstStackTrace", "Stack size : " + stackSize);
for(int i = 0; i < stackSize; i++) {
log.debug("getJvmThreadInstStackTrace", "Append " +
stackTrace[i].toString());
b.append(stackTrace[i].toString());
//Append \n at the end of each line except the last one
if(i < stackSize)
b.append("\n");
}
//The stack trace is truncated if its size exceeds 255.
return validPathElementTC(b.toString());
}
static final MibLogger log =
new MibLogger(JvmThreadInstanceEntryImpl.class);
}

View File

@@ -0,0 +1,404 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import com.sun.jmx.mbeanserver.Util;
import java.io.Serializable;
import java.util.Vector;
import java.util.Map;
import java.util.TreeMap;
import java.util.Enumeration;
import java.lang.management.ThreadInfo;
import java.lang.management.ManagementFactory;
// jmx imports
//
import javax.management.MBeanServer;
import javax.management.ObjectName;
import com.sun.jmx.snmp.SnmpCounter;
import com.sun.jmx.snmp.SnmpCounter64;
import com.sun.jmx.snmp.SnmpGauge;
import com.sun.jmx.snmp.SnmpInt;
import com.sun.jmx.snmp.SnmpUnsignedInt;
import com.sun.jmx.snmp.SnmpIpAddress;
import com.sun.jmx.snmp.SnmpTimeticks;
import com.sun.jmx.snmp.SnmpOpaque;
import com.sun.jmx.snmp.SnmpString;
import com.sun.jmx.snmp.SnmpStringFixed;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpNull;
import com.sun.jmx.snmp.SnmpValue;
import com.sun.jmx.snmp.SnmpVarBind;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpIndex;
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.agent.SnmpMibTable;
import com.sun.jmx.snmp.agent.SnmpMibSubRequest;
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
import sun.management.snmp.jvmmib.JvmThreadInstanceEntryMBean;
import sun.management.snmp.jvmmib.JvmThreadInstanceTableMeta;
import sun.management.snmp.util.SnmpTableCache;
import sun.management.snmp.util.SnmpCachedData;
import sun.management.snmp.util.SnmpTableHandler;
import sun.management.snmp.util.MibLogger;
import sun.management.snmp.util.JvmContextFactory;
/**
* The class is used for implementing the "JvmThreadInstanceTable" group.
*/
public class JvmThreadInstanceTableMetaImpl
extends JvmThreadInstanceTableMeta {
static final long serialVersionUID = -8432271929226397492L;
/**
* Maximum depth of the stacktrace that might be returned through
* SNMP.
*
* Since we do not export the stack trace through SNMP, we set
* MAX_STACK_TRACE_DEPTH=0 so that ThreadMXBean.getThreadInfo(long) does
* not compute the stack trace.
*
**/
public static final int MAX_STACK_TRACE_DEPTH=0;
/**
* Translate from a long to a Oid. Arc follow the long big-endian order.
* @param l The long to make the index from
* @return The arc array.
*/
static SnmpOid makeOid(long l) {
long[] x = new long [8];
x[0] = (l >> 56) & 0xFF;
x[1] = (l >> 48) & 0x00FF;
x[2] = (l >> 40) & 0x0000FF;
x[3] = (l >> 32) & 0x000000FF;
x[4] = (l >> 24) & 0x00000000FF;
x[5] = (l >> 16) & 0x0000000000FF;
x[6] = (l >> 8) & 0x000000000000FF;
x[7] = l & 0x00000000000000FF;
return new SnmpOid(x);
}
/**
* Translate an Oid to a thread id. Arc follow the long big-endian order.
* @param oid The oid to make the id from
* @return The thread id.
*/
static long makeId(SnmpOid oid) {
long id = 0;
long[] arcs = oid.longValue(false);
id |= arcs[0] << 56;
id |= arcs[1] << 48;
id |= arcs[2] << 40;
id |= arcs[3] << 32;
id |= arcs[4] << 24;
id |= arcs[5] << 16;
id |= arcs[6] << 8;
id |= arcs[7];
return id;
}
/**
* A concrete implementation of {@link SnmpTableCache}, for the
* JvmThreadInstanceTable.
**/
private static class JvmThreadInstanceTableCache
extends SnmpTableCache {
static final long serialVersionUID = 4947330124563406878L;
final private JvmThreadInstanceTableMetaImpl meta;
/**
* Create a weak cache for the JvmThreadInstanceTable.
* @param validity validity of the cached data, in ms.
**/
JvmThreadInstanceTableCache(JvmThreadInstanceTableMetaImpl meta,
long validity) {
this.validity = validity;
this.meta = meta;
}
/**
* Call <code>getTableDatas(JvmContextFactory.getUserData())</code>.
**/
public SnmpTableHandler getTableHandler() {
final Map<Object, Object> userData = JvmContextFactory.getUserData();
return getTableDatas(userData);
}
/**
* Return a table handler containing the Thread indexes.
* Indexes are computed from the ThreadId.
**/
protected SnmpCachedData updateCachedDatas(Object userData) {
// We are getting all the thread ids. WARNING.
// Some of them will be not valid when accessed for data...
// See getEntry
long[] id = JvmThreadingImpl.getThreadMXBean().getAllThreadIds();
// Time stamp for the cache
final long time = System.currentTimeMillis();
SnmpOid indexes[] = new SnmpOid[id.length];
final TreeMap<SnmpOid, Object> table =
new TreeMap<>(SnmpCachedData.oidComparator);
for(int i = 0; i < id.length; i++) {
log.debug("", "Making index for thread id [" + id[i] +"]");
//indexes[i] = makeOid(id[i]);
SnmpOid oid = makeOid(id[i]);
table.put(oid, oid);
}
return new SnmpCachedData(time, table);
}
}
// The weak cache for this table.
protected SnmpTableCache cache;
/**
* Constructor for the table. Initialize metadata for
* "JvmThreadInstanceTableMeta".
* The reference on the MBean server is updated so the entries created
* through an SNMP SET will be AUTOMATICALLY REGISTERED in Java DMK.
*/
public JvmThreadInstanceTableMetaImpl(SnmpMib myMib,
SnmpStandardObjectServer objserv) {
super(myMib, objserv);
cache = new JvmThreadInstanceTableCache(this,
((JVM_MANAGEMENT_MIB_IMPL)myMib).validity());
log.debug("JvmThreadInstanceTableMetaImpl", "Create Thread meta");
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(Object userData)
throws SnmpStatusException {
log.debug("JvmThreadInstanceTableMetaImpl", "getNextOid");
// null means get the first OID.
return getNextOid(null,userData);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected SnmpOid getNextOid(SnmpOid oid, Object userData)
throws SnmpStatusException {
log.debug("getNextOid", "previous=" + oid);
// Get the data handler.
//
SnmpTableHandler handler = getHandler(userData);
if (handler == null) {
// This should never happen.
// If we get here it's a bug.
//
log.debug("getNextOid", "handler is null!");
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the next oid
//
SnmpOid next = oid;
while(true) {
next = handler.getNext(next);
if (next == null) break;
if (getJvmThreadInstance(userData,next) != null) break;
}
log.debug("*** **** **** **** getNextOid", "next=" + next);
// if next is null: we reached the end of the table.
//
if (next == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
return next;
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
protected boolean contains(SnmpOid oid, Object userData) {
// Get the handler.
//
SnmpTableHandler handler = getHandler(userData);
// handler should never be null.
//
if (handler == null)
return false;
if(!handler.contains(oid))
return false;
JvmThreadInstanceEntryImpl inst = getJvmThreadInstance(userData, oid);
return (inst != null);
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
public Object getEntry(SnmpOid oid)
throws SnmpStatusException {
log.debug("*** **** **** **** getEntry", "oid [" + oid + "]");
if (oid == null || oid.getLength() != 8) {
log.debug("getEntry", "Invalid oid [" + oid + "]");
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// Get the request contextual cache (userData).
//
final Map<Object,Object> m = JvmContextFactory.getUserData();
// Get the handler.
//
SnmpTableHandler handler = getHandler(m);
// handler should never be null.
//
if (handler == null || !handler.contains(oid))
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
final JvmThreadInstanceEntryImpl entry = getJvmThreadInstance(m,oid);
if (entry == null)
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
return entry;
}
/**
* Get the SnmpTableHandler that holds the jvmThreadInstanceTable data.
* First look it up in the request contextual cache, and if it is
* not found, obtain it from the weak cache.
* <br>The request contextual cache will be released at the end of the
* current requests, and is used only to process this request.
* <br>The weak cache is shared by all requests, and is only
* recomputed when it is found to be obsolete.
* <br>Note that the data put in the request contextual cache is
* never considered to be obsolete, in order to preserve data
* coherency.
**/
protected SnmpTableHandler getHandler(Object userData) {
final Map<Object, Object> m;
if (userData instanceof Map) m=Util.cast(userData);
else m=null;
// Look in the contextual cache.
if (m != null) {
final SnmpTableHandler handler =
(SnmpTableHandler)m.get("JvmThreadInstanceTable.handler");
if (handler != null) return handler;
}
// No handler in contextual cache, make a new one.
final SnmpTableHandler handler = cache.getTableHandler();
if (m != null && handler != null )
m.put("JvmThreadInstanceTable.handler",handler);
return handler;
}
private ThreadInfo getThreadInfo(long id) {
return JvmThreadingImpl.getThreadMXBean().
getThreadInfo(id,MAX_STACK_TRACE_DEPTH);
}
private ThreadInfo getThreadInfo(SnmpOid oid) {
return getThreadInfo(makeId(oid));
}
private JvmThreadInstanceEntryImpl getJvmThreadInstance(Object userData,
SnmpOid oid) {
JvmThreadInstanceEntryImpl cached = null;
String entryTag = null;
Map<Object, Object> map = null;
final boolean dbg = log.isDebugOn();
if (userData instanceof Map) {
map = Util.cast(userData);
// We're going to use this name to store/retrieve the entry in
// the request contextual cache.
//
// Revisit: Probably better programming to put all these strings
// in some interface.
//
entryTag = "JvmThreadInstanceTable.entry." + oid.toString();
cached = (JvmThreadInstanceEntryImpl) map.get(entryTag);
}
// If the entry is in the cache, simply return it.
//
if (cached != null) {
if (dbg) log.debug("*** getJvmThreadInstance",
"Entry found in cache: " + entryTag);
return cached;
}
if (dbg) log.debug("*** getJvmThreadInstance", "Entry [" +
oid + "] is not in cache");
// Entry not in cache. We will create one if needed.
//
ThreadInfo info = null;
try {
info = getThreadInfo(oid);
} catch (RuntimeException r) {
log.trace("*** getJvmThreadInstance",
"Failed to get thread info for rowOid: " + oid);
log.debug("*** getJvmThreadInstance",r);
}
// No thread by that id => no entry.
//
if(info == null) {
if (dbg) log.debug("*** getJvmThreadInstance",
"No entry by that oid [" + oid + "]");
return null;
}
cached = new JvmThreadInstanceEntryImpl(info, oid.toByte());
if (map != null) map.put(entryTag, cached);
if (dbg) log.debug("*** getJvmThreadInstance",
"Entry created for Thread OID [" + oid + "]");
return cached;
}
static final MibLogger log =
new MibLogger(JvmThreadInstanceTableMetaImpl.class);
}

View File

@@ -0,0 +1,364 @@
/*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
import java.lang.management.ThreadMXBean;
import java.lang.management.ManagementFactory;
// jmx imports
//
import javax.management.MBeanServer;
import com.sun.jmx.snmp.SnmpString;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.SnmpDefinitions;
import sun.management.snmp.jvmmib.JvmThreadingMBean;
import sun.management.snmp.jvmmib.EnumJvmThreadCpuTimeMonitoring;
import sun.management.snmp.jvmmib.EnumJvmThreadContentionMonitoring;
import sun.management.snmp.util.MibLogger;
/**
* The class is used for implementing the "JvmThreading" group.
*/
public class JvmThreadingImpl implements JvmThreadingMBean {
/**
* Variable for storing the value of "JvmThreadCpuTimeMonitoring".
*
* "The state of the Thread CPU Time Monitoring feature.
* This feature can be:
*
* unsupported: The JVM does not support Thread CPU Time Monitoring.
* enabled : The JVM supports Thread CPU Time Monitoring, and it
* is enabled.
* disabled : The JVM supports Thread CPU Time Monitoring, and it
* is disabled.
*
* Only enabled(3) and disabled(4) may be supplied as values to a
* SET request. unsupported(1) can only be set internally by the
* agent.
*
* See java.lang.management.ThreadMXBean.isThreadCpuTimeSupported(),
* java.lang.management.ThreadMXBean.isThreadCpuTimeEnabled(),
* java.lang.management.ThreadMXBean.setThreadCpuTimeEnabled()
* "
*
*/
final static EnumJvmThreadCpuTimeMonitoring
JvmThreadCpuTimeMonitoringUnsupported =
new EnumJvmThreadCpuTimeMonitoring("unsupported");
final static EnumJvmThreadCpuTimeMonitoring
JvmThreadCpuTimeMonitoringEnabled =
new EnumJvmThreadCpuTimeMonitoring("enabled");
final static EnumJvmThreadCpuTimeMonitoring
JvmThreadCpuTimeMonitoringDisabled =
new EnumJvmThreadCpuTimeMonitoring("disabled");
/**
* Variable for storing the value of "JvmThreadContentionMonitoring".
*
* "The state of the Thread Contention Monitoring feature.
* This feature can be:
*
* unsupported: The JVM does not support Thread Contention Monitoring.
* enabled : The JVM supports Thread Contention Monitoring, and it
* is enabled.
* disabled : The JVM supports Thread Contention Monitoring, and it
* is disabled.
*
* Only enabled(3) and disabled(4) may be supplied as values to a
* SET request. unsupported(1) can only be set internally by the
* agent.
*
* See java.lang.management.ThreadMXBean.isThreadContentionMonitoringSupported(),
* java.lang.management.ThreadMXBean.isThreadContentionMonitoringEnabled(),
* java.lang.management.ThreadMXBean.setThreadContentionMonitoringEnabled()
* "
*
*/
static final EnumJvmThreadContentionMonitoring
JvmThreadContentionMonitoringUnsupported =
new EnumJvmThreadContentionMonitoring("unsupported");
static final EnumJvmThreadContentionMonitoring
JvmThreadContentionMonitoringEnabled =
new EnumJvmThreadContentionMonitoring("enabled");
static final EnumJvmThreadContentionMonitoring
JvmThreadContentionMonitoringDisabled =
new EnumJvmThreadContentionMonitoring("disabled");
/**
* Constructor for the "JvmThreading" group.
* If the group contains a table, the entries created through an SNMP SET
* will not be registered in Java DMK.
*/
public JvmThreadingImpl(SnmpMib myMib) {
log.debug("JvmThreadingImpl","Constructor");
}
/**
* Constructor for the "JvmThreading" group.
* If the group contains a table, the entries created through an SNMP SET
* will be AUTOMATICALLY REGISTERED in Java DMK.
*/
public JvmThreadingImpl(SnmpMib myMib, MBeanServer server) {
log.debug("JvmThreadingImpl","Constructor with server");
}
/**
* ThreadMXBean accessor. It is acquired from the
* java.lang.management.ManagementFactory
* @return The local ThreadMXBean.
*/
static ThreadMXBean getThreadMXBean() {
return ManagementFactory.getThreadMXBean();
}
/**
* Getter for the "JvmThreadCpuTimeMonitoring" variable.
*/
public EnumJvmThreadCpuTimeMonitoring getJvmThreadCpuTimeMonitoring()
throws SnmpStatusException {
ThreadMXBean mbean = getThreadMXBean();
if(!mbean.isThreadCpuTimeSupported()) {
log.debug("getJvmThreadCpuTimeMonitoring",
"Unsupported ThreadCpuTimeMonitoring");
return JvmThreadCpuTimeMonitoringUnsupported;
}
try {
if(mbean.isThreadCpuTimeEnabled()) {
log.debug("getJvmThreadCpuTimeMonitoring",
"Enabled ThreadCpuTimeMonitoring");
return JvmThreadCpuTimeMonitoringEnabled;
} else {
log.debug("getJvmThreadCpuTimeMonitoring",
"Disabled ThreadCpuTimeMonitoring");
return JvmThreadCpuTimeMonitoringDisabled;
}
}catch(UnsupportedOperationException e) {
log.debug("getJvmThreadCpuTimeMonitoring",
"Newly unsupported ThreadCpuTimeMonitoring");
return JvmThreadCpuTimeMonitoringUnsupported;
}
}
/**
* Setter for the "JvmThreadCpuTimeMonitoring" variable.
*/
public void setJvmThreadCpuTimeMonitoring(EnumJvmThreadCpuTimeMonitoring x)
throws SnmpStatusException {
ThreadMXBean mbean = getThreadMXBean();
// We can trust the received value, it has been checked in
// checkJvmThreadCpuTimeMonitoring
if(JvmThreadCpuTimeMonitoringEnabled.intValue() == x.intValue())
mbean.setThreadCpuTimeEnabled(true);
else
mbean.setThreadCpuTimeEnabled(false);
}
/**
* Checker for the "JvmThreadCpuTimeMonitoring" variable.
*/
public void checkJvmThreadCpuTimeMonitoring(EnumJvmThreadCpuTimeMonitoring
x)
throws SnmpStatusException {
//Can't be set externaly to unsupported state.
if(JvmThreadCpuTimeMonitoringUnsupported.intValue() == x.intValue()) {
log.debug("checkJvmThreadCpuTimeMonitoring",
"Try to set to illegal unsupported value");
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
if ((JvmThreadCpuTimeMonitoringEnabled.intValue() == x.intValue()) ||
(JvmThreadCpuTimeMonitoringDisabled.intValue() == x.intValue())) {
// The value is a valid value. But is the feature supported?
ThreadMXBean mbean = getThreadMXBean();
if(mbean.isThreadCpuTimeSupported()) return;
// Not supported.
log.debug("checkJvmThreadCpuTimeMonitoring",
"Unsupported operation, can't set state");
throw new
SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
}
// Unknown value.
log.debug("checkJvmThreadCpuTimeMonitoring",
"unknown enum value ");
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
/**
* Getter for the "JvmThreadContentionMonitoring" variable.
*/
public EnumJvmThreadContentionMonitoring getJvmThreadContentionMonitoring()
throws SnmpStatusException {
ThreadMXBean mbean = getThreadMXBean();
if(!mbean.isThreadContentionMonitoringSupported()) {
log.debug("getJvmThreadContentionMonitoring",
"Unsupported ThreadContentionMonitoring");
return JvmThreadContentionMonitoringUnsupported;
}
if(mbean.isThreadContentionMonitoringEnabled()) {
log.debug("getJvmThreadContentionMonitoring",
"Enabled ThreadContentionMonitoring");
return JvmThreadContentionMonitoringEnabled;
} else {
log.debug("getJvmThreadContentionMonitoring",
"Disabled ThreadContentionMonitoring");
return JvmThreadContentionMonitoringDisabled;
}
}
/**
* Setter for the "JvmThreadContentionMonitoring" variable.
*/
public void setJvmThreadContentionMonitoring(
EnumJvmThreadContentionMonitoring x)
throws SnmpStatusException {
ThreadMXBean mbean = getThreadMXBean();
// We can trust the received value, it has been checked in
// checkJvmThreadContentionMonitoring
if(JvmThreadContentionMonitoringEnabled.intValue() == x.intValue())
mbean.setThreadContentionMonitoringEnabled(true);
else
mbean.setThreadContentionMonitoringEnabled(false);
}
/**
* Checker for the "JvmThreadContentionMonitoring" variable.
*/
public void checkJvmThreadContentionMonitoring(
EnumJvmThreadContentionMonitoring x)
throws SnmpStatusException {
//Can't be set externaly to unsupported state.
if(JvmThreadContentionMonitoringUnsupported.intValue()==x.intValue()) {
log.debug("checkJvmThreadContentionMonitoring",
"Try to set to illegal unsupported value");
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
if ((JvmThreadContentionMonitoringEnabled.intValue()==x.intValue()) ||
(JvmThreadContentionMonitoringDisabled.intValue()==x.intValue())) {
// The value is valid, but is the feature supported ?
ThreadMXBean mbean = getThreadMXBean();
if(mbean.isThreadContentionMonitoringSupported()) return;
log.debug("checkJvmThreadContentionMonitoring",
"Unsupported operation, can't set state");
throw new
SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
}
log.debug("checkJvmThreadContentionMonitoring",
"Try to set to unknown value");
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
/**
* Getter for the "JvmThreadTotalStartedCount" variable.
*/
public Long getJvmThreadTotalStartedCount() throws SnmpStatusException {
return new Long(getThreadMXBean().getTotalStartedThreadCount());
}
/**
* Getter for the "JvmThreadPeakCount" variable.
*/
public Long getJvmThreadPeakCount() throws SnmpStatusException {
return new Long(getThreadMXBean().getPeakThreadCount());
}
/**
* Getter for the "JvmThreadDaemonCount" variable.
*/
public Long getJvmThreadDaemonCount() throws SnmpStatusException {
return new Long(getThreadMXBean().getDaemonThreadCount());
}
/**
* Getter for the "JvmThreadCount" variable.
*/
public Long getJvmThreadCount() throws SnmpStatusException {
return new Long(getThreadMXBean().getThreadCount());
}
/**
* Getter for the "JvmThreadPeakCountReset" variable.
*/
public synchronized Long getJvmThreadPeakCountReset()
throws SnmpStatusException {
return new Long(jvmThreadPeakCountReset);
}
/**
* Setter for the "JvmThreadPeakCountReset" variable.
*/
public synchronized void setJvmThreadPeakCountReset(Long x)
throws SnmpStatusException {
final long l = x.longValue();
if (l > jvmThreadPeakCountReset) {
final long stamp = System.currentTimeMillis();
getThreadMXBean().resetPeakThreadCount();
jvmThreadPeakCountReset = stamp;
log.debug("setJvmThreadPeakCountReset",
"jvmThreadPeakCountReset="+stamp);
}
}
/**
* Checker for the "JvmThreadPeakCountReset" variable.
*/
public void checkJvmThreadPeakCountReset(Long x)
throws SnmpStatusException {
}
/* Last time thread peak count was reset */
private long jvmThreadPeakCountReset=0;
static final MibLogger log = new MibLogger(JvmThreadingImpl.class);
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
// java imports
//
import java.io.Serializable;
// jmx imports
//
import javax.management.MBeanServer;
import com.sun.jmx.snmp.SnmpCounter;
import com.sun.jmx.snmp.SnmpCounter64;
import com.sun.jmx.snmp.SnmpGauge;
import com.sun.jmx.snmp.SnmpInt;
import com.sun.jmx.snmp.SnmpUnsignedInt;
import com.sun.jmx.snmp.SnmpIpAddress;
import com.sun.jmx.snmp.SnmpTimeticks;
import com.sun.jmx.snmp.SnmpOpaque;
import com.sun.jmx.snmp.SnmpString;
import com.sun.jmx.snmp.SnmpStringFixed;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpNull;
import com.sun.jmx.snmp.SnmpValue;
import com.sun.jmx.snmp.SnmpVarBind;
import com.sun.jmx.snmp.SnmpStatusException;
// jdmk imports
//
import com.sun.jmx.snmp.agent.SnmpMib;
import com.sun.jmx.snmp.agent.SnmpMibGroup;
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
import com.sun.jmx.snmp.agent.SnmpStandardMetaServer;
import com.sun.jmx.snmp.agent.SnmpMibSubRequest;
import com.sun.jmx.snmp.agent.SnmpMibTable;
import com.sun.jmx.snmp.EnumRowStatus;
import sun.management.snmp.jvmmib.JvmThreadingMeta;
import sun.management.snmp.jvmmib.JvmThreadInstanceTableMeta;
/**
* The class is used for representing SNMP metadata for the "JvmThreading"
* group.
*/
public class JvmThreadingMetaImpl extends JvmThreadingMeta {
static final long serialVersionUID = -2104788458393251457L;
/**
* Constructor for the metadata associated to "JvmThreading".
*/
public JvmThreadingMetaImpl(SnmpMib myMib,
SnmpStandardObjectServer objserv) {
super(myMib, objserv);
}
/**
* Factory method for "JvmThreadInstanceTable" table metadata class.
*
* You can redefine this method if you need to replace the default
* generated metadata class with your own customized class.
*
* @param tableName Name of the table object ("JvmThreadInstanceTable")
* @param groupName Name of the group to which this table belong
* ("JvmThreading")
* @param mib The SnmpMib object in which this table is registered
* @param server MBeanServer for this table entries (may be null)
*
* @return An instance of the metadata class generated for the
* "JvmThreadInstanceTable" table (JvmThreadInstanceTableMeta)
*
**/
protected JvmThreadInstanceTableMeta
createJvmThreadInstanceTableMetaNode(String tableName,
String groupName,
SnmpMib mib,
MBeanServer server) {
return new JvmThreadInstanceTableMetaImpl(mib, objectserver);
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
import java.net.InetAddress;
/**
* Target notification.
*/
public interface NotificationTarget {
public InetAddress getAddress();
public int getPort();
public String getCommunity();
}

View File

@@ -0,0 +1,131 @@
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management.snmp.jvminstr;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* Notification Target data.
*/
public class NotificationTargetImpl implements NotificationTarget {
private InetAddress address;
private int port;
private String community;
/**
* Target parameter is a <CODE>java.lang.String</CODE>
* target synctax is <host>:<port>:community. Eg: "localhost:163:private".
* <p>The <code><em>host</em></code> is a host name, an IPv4 numeric
* host address, or an IPv6 numeric address enclosed in square
* brackets.</p>
* @throws IllegalArgumentException In case the target is malformed
*/
public NotificationTargetImpl(String target)
throws IllegalArgumentException, UnknownHostException {
parseTarget(target);
}
public NotificationTargetImpl(String address, int port,
String community)
throws UnknownHostException {
this(InetAddress.getByName(address),port,community);
}
public NotificationTargetImpl(InetAddress address, int port,
String community) {
this.address = address;
this.port = port;
this.community = community;
}
private void parseTarget(String target)
throws IllegalArgumentException, UnknownHostException {
if(target == null ||
target.length() == 0) throw new
IllegalArgumentException("Invalid target [" + target + "]");
String addrStr;
if (target.startsWith("[")) {
final int index = target.indexOf("]");
final int index2 = target.lastIndexOf(":");
if(index == -1)
throw new IllegalArgumentException("Host starts with [ but " +
"does not end with ]");
addrStr = target.substring(1, index);
port = Integer.parseInt(target.substring(index + 2,
index2));
if (!isNumericIPv6Address(addrStr)) {
throw new IllegalArgumentException("Address inside [...] must " +
"be numeric IPv6 address");
}
if (addrStr.startsWith("["))
throw new IllegalArgumentException("More than one [[...]]");
} else {
final int index = target.indexOf(":");
final int index2 = target.lastIndexOf(":");
if(index == -1) throw new
IllegalArgumentException("Missing port separator \":\"");
addrStr = target.substring(0, index);
port = Integer.parseInt(target.substring(index + 1,
index2));
}
address = InetAddress.getByName(addrStr);
//THE CHECK SHOULD BE STRONGER!!!
final int index = target.lastIndexOf(":");
community = target.substring(index + 1, target.length());
}
/* True if this string, assumed to be a valid argument to
* InetAddress.getByName, is a numeric IPv6 address.
*/
private static boolean isNumericIPv6Address(String s) {
// address contains colon iff it's a numeric IPv6 address
return (s.indexOf(':') >= 0);
}
public String getCommunity() {
return community;
}
public InetAddress getAddress() {
return address;
}
public int getPort() {
return port;
}
public String toString() {
return "address : " + address + " port : " + port +
" community : " + community;
}
}