|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class JvmMemManagerTableMetaImpl extends JvmMemManagerTableMeta { |
|
|
|
static final long serialVersionUID = 36176771566817592L; |
|
|
|
|
|
|
|
|
|
**/ |
|
private static class JvmMemManagerTableCache |
|
extends SnmpNamedListTableCache { |
|
|
|
static final long serialVersionUID = 6564294074653009240L; |
|
|
|
|
|
|
|
|
|
**/ |
|
JvmMemManagerTableCache(long validity) { |
|
this.validity = validity; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**/ |
|
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; |
|
} |
|
|
|
|
|
|
|
**/ |
|
public SnmpTableHandler getTableHandler() { |
|
final Map<Object, Object> userData = JvmContextFactory.getUserData(); |
|
return getTableDatas(userData); |
|
} |
|
|
|
|
|
|
|
**/ |
|
protected String getRawDatasKey() { |
|
return "JvmMemManagerTable.getMemoryManagers"; |
|
} |
|
|
|
|
|
|
|
|
|
**/ |
|
protected List<MemoryManagerMXBean> loadRawDatas(Map<Object, Object> userData) { |
|
return ManagementFactory.getMemoryManagerMXBeans(); |
|
} |
|
|
|
} |
|
|
|
|
|
protected SnmpTableCache cache; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public JvmMemManagerTableMetaImpl(SnmpMib myMib, |
|
SnmpStandardObjectServer objserv) { |
|
super(myMib,objserv); |
|
this.cache = new |
|
JvmMemManagerTableCache(((JVM_MANAGEMENT_MIB_IMPL)myMib). |
|
validity()); |
|
} |
|
|
|
|
|
protected SnmpOid getNextOid(Object userData) |
|
throws SnmpStatusException { |
|
|
|
return getNextOid(null,userData); |
|
} |
|
|
|
|
|
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; |
|
} |
|
|
|
|
|
|
|
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); |
|
} |
|
|
|
|
|
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; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**/ |
|
protected SnmpTableHandler getHandler(Object userData) { |
|
final Map<Object, Object> m; |
|
if (userData instanceof Map) m=Util.cast(userData); |
|
else m=null; |
|
|
|
|
|
if (m != null) { |
|
final SnmpTableHandler handler = |
|
(SnmpTableHandler)m.get("JvmMemManagerTable.handler"); |
|
if (handler != null) return handler; |
|
} |
|
|
|
|
|
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); |
|
} |