0N/A/*
2362N/A * Copyright (c) 2004, 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 com.sun.jmx.mbeanserver.Util;
0N/Aimport java.util.List;
0N/Aimport java.util.Map;
0N/A
0N/A// jmx imports
0N/A//
0N/Aimport javax.management.MBeanServer;
0N/Aimport javax.management.ObjectName;
0N/Aimport com.sun.jmx.snmp.SnmpCounter;
0N/Aimport com.sun.jmx.snmp.SnmpCounter64;
0N/Aimport com.sun.jmx.snmp.SnmpGauge;
0N/Aimport com.sun.jmx.snmp.SnmpInt;
0N/Aimport com.sun.jmx.snmp.SnmpUnsignedInt;
0N/Aimport com.sun.jmx.snmp.SnmpIpAddress;
0N/Aimport com.sun.jmx.snmp.SnmpTimeticks;
0N/Aimport com.sun.jmx.snmp.SnmpOpaque;
0N/Aimport com.sun.jmx.snmp.SnmpString;
0N/Aimport com.sun.jmx.snmp.SnmpStringFixed;
0N/Aimport com.sun.jmx.snmp.SnmpOid;
0N/Aimport com.sun.jmx.snmp.SnmpNull;
0N/Aimport com.sun.jmx.snmp.SnmpValue;
0N/Aimport com.sun.jmx.snmp.SnmpVarBind;
0N/Aimport com.sun.jmx.snmp.SnmpStatusException;
0N/A
0N/A// jdmk imports
0N/A//
0N/Aimport com.sun.jmx.snmp.agent.SnmpIndex;
0N/Aimport com.sun.jmx.snmp.agent.SnmpMib;
0N/Aimport com.sun.jmx.snmp.agent.SnmpMibTable;
0N/Aimport com.sun.jmx.snmp.agent.SnmpMibSubRequest;
0N/Aimport com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
0N/A
0N/Aimport sun.management.snmp.jvmmib.JvmRTLibraryPathTableMeta;
0N/Aimport sun.management.snmp.util.SnmpCachedData;
0N/Aimport sun.management.snmp.util.SnmpTableCache;
0N/Aimport sun.management.snmp.util.SnmpTableHandler;
0N/Aimport sun.management.snmp.util.MibLogger;
0N/Aimport sun.management.snmp.util.JvmContextFactory;
0N/A
0N/A/**
0N/A * The class is used for implementing the "JvmRTLibraryPathTable".
0N/A */
0N/Apublic class JvmRTLibraryPathTableMetaImpl extends JvmRTLibraryPathTableMeta {
0N/A
0N/A private SnmpTableCache cache;
0N/A
0N/A /**
0N/A * A concrete implementation of {@link SnmpTableCache}, for the
0N/A * JvmRTLibraryPathTable.
0N/A **/
0N/A private static class JvmRTLibraryPathTableCache extends SnmpTableCache {
0N/A private JvmRTLibraryPathTableMetaImpl meta;
0N/A
0N/A JvmRTLibraryPathTableCache(JvmRTLibraryPathTableMetaImpl meta,
0N/A long validity) {
0N/A this.meta = meta;
0N/A this.validity = validity;
0N/A }
0N/A
0N/A /**
0N/A * Call <code>getTableDatas(JvmContextFactory.getUserData())</code>.
0N/A **/
0N/A public SnmpTableHandler getTableHandler() {
0N/A final Map userData = JvmContextFactory.getUserData();
0N/A return getTableDatas(userData);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Return a table handler containing the Thread indexes.
0N/A * Indexes are computed from the ThreadId.
0N/A **/
0N/A protected SnmpCachedData updateCachedDatas(Object userData) {
0N/A
0N/A
0N/A // We are getting all the input args
0N/A final String[] path =
0N/A JvmRuntimeImpl.getLibraryPath(userData);
0N/A
0N/A // Time stamp for the cache
0N/A final long time = System.currentTimeMillis();
0N/A final int len = path.length;
0N/A
0N/A SnmpOid indexes[] = new SnmpOid[len];
0N/A
0N/A for(int i = 0; i < len; i++) {
0N/A indexes[i] = new SnmpOid(i + 1);
0N/A }
0N/A
0N/A return new SnmpCachedData(time, indexes, path);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Constructor for the table. Initialize metadata for
0N/A * "JvmRTLibraryPathTableMeta".
0N/A * The reference on the MBean server is updated so the entries
0N/A * created through an SNMP SET will be AUTOMATICALLY REGISTERED
0N/A * in Java DMK.
0N/A */
0N/A public JvmRTLibraryPathTableMetaImpl(SnmpMib myMib,
0N/A SnmpStandardObjectServer objserv) {
0N/A super(myMib, objserv);
0N/A cache = new JvmRTLibraryPathTableCache(this, -1);
0N/A }
0N/A
0N/A // See com.sun.jmx.snmp.agent.SnmpMibTable
0N/A protected SnmpOid getNextOid(Object userData)
0N/A throws SnmpStatusException {
0N/A // null means get the first OID.
0N/A return getNextOid(null,userData);
0N/A }
0N/A
0N/A // See com.sun.jmx.snmp.agent.SnmpMibTable
0N/A protected SnmpOid getNextOid(SnmpOid oid, Object userData)
0N/A throws SnmpStatusException {
0N/A final boolean dbg = log.isDebugOn();
0N/A if (dbg) log.debug("getNextOid", "previous=" + oid);
0N/A
0N/A
0N/A // Get the data handler.
0N/A //
0N/A SnmpTableHandler handler = getHandler(userData);
0N/A if (handler == null) {
0N/A // This should never happen.
0N/A // If we get here it's a bug.
0N/A //
0N/A if (dbg) log.debug("getNextOid", "handler is null!");
0N/A throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
0N/A }
0N/A
0N/A // Get the next oid
0N/A //
0N/A final SnmpOid next = handler.getNext(oid);
0N/A if (dbg) log.debug("*** **** **** **** getNextOid", "next=" + next);
0N/A
0N/A // if next is null: we reached the end of the table.
0N/A //
0N/A if (next == null)
0N/A throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
0N/A
0N/A return next;
0N/A }
0N/A
0N/A
0N/A // See com.sun.jmx.snmp.agent.SnmpMibTable
0N/A protected boolean contains(SnmpOid oid, Object userData) {
0N/A
0N/A // Get the handler.
0N/A //
0N/A SnmpTableHandler handler = getHandler(userData);
0N/A
0N/A // handler should never be null.
0N/A //
0N/A if (handler == null)
0N/A return false;
0N/A
0N/A return handler.contains(oid);
0N/A }
0N/A
0N/A // See com.sun.jmx.snmp.agent.SnmpMibTable
0N/A public Object getEntry(SnmpOid oid)
0N/A throws SnmpStatusException {
0N/A final boolean dbg = log.isDebugOn();
0N/A if (dbg) log.debug("getEntry", "oid [" + oid + "]");
0N/A if (oid == null || oid.getLength() != 1) {
0N/A if (dbg) log.debug("getEntry", "Invalid oid [" + oid + "]");
0N/A throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
0N/A }
0N/A
0N/A // Get the request contextual cache (userData).
0N/A //
0N/A final Map<Object, Object> m = JvmContextFactory.getUserData();
0N/A
0N/A // We're going to use this name to store/retrieve the entry in
0N/A // the request contextual cache.
0N/A //
0N/A // Revisit: Probably better programming to put all these strings
0N/A // in some interface.
0N/A //
0N/A final String entryTag = ((m==null)?null:
0N/A ("JvmRTLibraryPathTable.entry." +
0N/A oid.toString()));
0N/A
0N/A // If the entry is in the cache, simply return it.
0N/A //
0N/A if (m != null) {
0N/A final Object entry = m.get(entryTag);
0N/A if (entry != null) {
0N/A if (dbg)
0N/A log.debug("getEntry", "Entry is already in the cache");
0N/A return entry;
0N/A } else if (dbg) log.debug("getEntry", "Entry is not in the cache");
0N/A
0N/A }
0N/A
0N/A // The entry was not in the cache, make a new one.
0N/A //
0N/A // Get the data hanler.
0N/A //
0N/A SnmpTableHandler handler = getHandler(m);
0N/A
0N/A // handler should never be null.
0N/A //
0N/A if (handler == null)
0N/A throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
0N/A
0N/A // Get the data associated with our entry.
0N/A //
0N/A final Object data = handler.getData(oid);
0N/A
0N/A // data may be null if the OID we were given is not valid.
0N/A //
0N/A if (data == null)
0N/A throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
0N/A
0N/A // make the new entry (transient object that will be kept only
0N/A // for the duration of the request.
0N/A //
0N/A if (dbg) log.debug("getEntry","data is a: "+
0N/A data.getClass().getName());
0N/A final Object entry =
0N/A new JvmRTLibraryPathEntryImpl((String) data,(int)oid.getOidArc(0));
0N/A
0N/A // Put the entry in the cache in case we need it later while processing
0N/A // the request.
0N/A //
0N/A if (m != null && entry != null) {
0N/A m.put(entryTag,entry);
0N/A }
0N/A
0N/A return entry;
0N/A }
0N/A
0N/A /**
0N/A * Get the SnmpTableHandler that holds the jvmThreadInstanceTable data.
0N/A * First look it up in the request contextual cache, and if it is
0N/A * not found, obtain it from the weak cache.
0N/A * <br>The request contextual cache will be released at the end of the
0N/A * current requests, and is used only to process this request.
0N/A * <br>The weak cache is shared by all requests, and is only
0N/A * recomputed when it is found to be obsolete.
0N/A * <br>Note that the data put in the request contextual cache is
0N/A * never considered to be obsolete, in order to preserve data
0N/A * coherency.
0N/A **/
0N/A protected SnmpTableHandler getHandler(Object userData) {
0N/A final Map<Object, Object> m;
0N/A if (userData instanceof Map) m=Util.cast(userData);
0N/A else m=null;
0N/A
0N/A // Look in the contextual cache.
0N/A if (m != null) {
0N/A final SnmpTableHandler handler =
0N/A (SnmpTableHandler)m.get("JvmRTLibraryPathTable.handler");
0N/A if (handler != null) return handler;
0N/A }
0N/A
0N/A // No handler in contextual cache, make a new one.
0N/A final SnmpTableHandler handler = cache.getTableHandler();
0N/A
0N/A if (m != null && handler != null )
0N/A m.put("JvmRTLibraryPathTable.handler",handler);
0N/A
0N/A return handler;
0N/A }
0N/A
0N/A static final MibLogger log =
0N/A new MibLogger(JvmRTLibraryPathTableMetaImpl.class);
0N/A}