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