/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
// java imports
//
// jmx imports
//
// jdmk imports
//
/**
* The class is used for implementing the "JvmMemGCTable" table.
*/
/**
* 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.
**/
// 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)
//
" at insertion="+insertion);
int next;
// 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.
//
if (value instanceof GarbageCollectorMXBean) {
// That's the next: return it.
" is a GarbageCollectorMXBean.");
}
" is not a GarbageCollectorMXBean: " +
// 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.
**/
// try to call the optimized method
if (handler instanceof SnmpCachedData)
// too bad - revert to non-optimized generic algorithm
do {
if (value instanceof GarbageCollectorMXBean)
// That's the next! return it
return next;
// skip to next index...
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.
**/
// Behaves as if there was nothing at this index...
//
return null;
}
/**
* Returns true if the given <var>index</var> is present.
**/
return true;
// Behaves as if there was nothing at this index...
//
return false;
}
}
/**
* Constructor for the table. Initialize metadata for "JvmMemGCTableMeta".
*/
}
// Returns a pointer to the JvmMemManager meta node - we're going
// to reuse its SnmpTableHandler by filtering out all that is
// not a GarbageCollectorMXBean.
}
return managers;
}
/**
* Returns the JvmMemManagerTable SnmpTableHandler
**/
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
throws SnmpStatusException {
// null means get the first OID.
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
throws SnmpStatusException {
try {
// Get the data handler.
//
// This should never happen.
// If we get here it's a bug.
//
throw new
}
// Get the next oid, using the GC filter.
//
// if next is null: we reached the end of the table.
//
throw new
return next;
} catch (RuntimeException x) {
// debug. This should never happen.
//
throw x;
}
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
// Get the handler.
//
// handler should never be null.
//
return false;
}
// See com.sun.jmx.snmp.agent.SnmpMibTable
throws SnmpStatusException {
// Get the request contextual cache (userData).
//
// 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.
//
// the request contextual cache.
//
// Revisit: Probably better programming to put all these strings
// in some interface.
//
index));
// If the entry is in the cache, simply return it.
//
if (m != null) {
}
// Entry was not in request cache. Make a new one.
//
// Get the data hanler.
//
// handler should never be null.
//
// Use the filter to retrieve only GarabageCollectorMBean data.
//
// data may be null if the OID we were given is not valid.
// (e.g. it identifies a MemoryManager which is not a
// GarbageCollector)
//
// Make a new entryy (transient object that will be kept only
// for the duration of the request.
//
// 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)
//
}
return entry;
}
}