jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemGCTableMetaImpl.java
author mchung
Tue, 17 Jan 2012 15:55:40 -0800
changeset 11530 a9d059c15b80
parent 5506 202f599c92aa
child 14342 8435a30053c1
permissions -rw-r--r--
7117570: Warnings in sun.mangement.* and its subpackages Reviewed-by: mchung, dsamersoff Contributed-by: kurchi.subhra.hazra@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.management.snmp.jvminstr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
// java imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.TreeMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
// jmx imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.jmx.snmp.SnmpOid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.jmx.snmp.SnmpStatusException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
// jdmk imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import com.sun.jmx.snmp.agent.SnmpMib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.lang.management.MemoryManagerMXBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.lang.management.GarbageCollectorMXBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.lang.management.ManagementFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.management.snmp.jvmmib.JvmMemGCTableMeta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.management.snmp.util.SnmpCachedData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.management.snmp.util.SnmpTableCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.management.snmp.util.SnmpTableHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.management.snmp.util.MibLogger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.management.snmp.util.JvmContextFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * The class is used for implementing the "JvmMemGCTable" table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
public class JvmMemGCTableMetaImpl extends  JvmMemGCTableMeta {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    61
    static final long serialVersionUID = 8250461197108867607L;
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    62
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * This class acts as a filter over the SnmpTableHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * used for the JvmMemoryManagerTable. It filters out
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * (skip) all MemoryManagerMXBean that are not instances of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * GarbageCollectorMXBean so that only Garbage Collectors are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * seen. This is a better solution than relying on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * ManagementFactory.getGarbageCollectorMXBeans() because it makes it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * possible to guarantee the consistency betwen the MemoryManager table
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * and the GCTable since both will be sharing the same cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected static class GCTableFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
         * Returns the index that immediately follows the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
         * <var>index</var>. The returned index is strictly greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
         * than the given <var>index</var>, and is contained in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
         * <br>If the given <var>index</var> is null, returns the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
         * index in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
         * <br>If there are no index after the given <var>index</var>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
         * returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
         * This method is an optimization for the case where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         * SnmpTableHandler is in fact an instance of SnmpCachedData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        public SnmpOid getNext(SnmpCachedData datas, SnmpOid index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            final boolean dbg = log.isDebugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            // We're going to loop until we find an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            // GarbageCollectorMXBean. First we attempt to find
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            // the next element whose OID follows the given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            // If `index' is null, the insertion point is -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            // (the next is 0 = -insertion - 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            final int insertion = (index==null)?-1:datas.find(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            if (dbg) log.debug("GCTableFilter","oid="+index+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                               " at insertion="+insertion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            int next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            if (insertion > -1) next = insertion+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            else next = -insertion -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            // Now `next' points to the element that imediately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            // follows the given `index'. We're going to loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            // through the table, starting at `next' (included),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            // and return the first element which is an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            // of GarbageCollectorMXBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            for (;next<datas.indexes.length;next++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                if (dbg) log.debug("GCTableFilter","next="+next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                final Object value = datas.datas[next];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                if (dbg) log.debug("GCTableFilter","value["+next+"]=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                      ((MemoryManagerMXBean)value).getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                if (value instanceof GarbageCollectorMXBean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    // That's the next: return it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    if (dbg) log.debug("GCTableFilter",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                          ((MemoryManagerMXBean)value).getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                          " is a  GarbageCollectorMXBean.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    return datas.indexes[next];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                if (dbg) log.debug("GCTableFilter",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                      ((MemoryManagerMXBean)value).getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                      " is not a  GarbageCollectorMXBean: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                      value.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                // skip to next index...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         * Returns the index that immediately follows the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
         * <var>index</var>. The returned index is strictly greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
         * than the given <var>index</var>, and is contained in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
         * <br>If the given <var>index</var> is null, returns the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         * index in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
         * <br>If there are no index after the given <var>index</var>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
         * returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        public SnmpOid getNext(SnmpTableHandler handler, SnmpOid index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            // try to call the optimized method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if (handler instanceof SnmpCachedData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                return getNext((SnmpCachedData)handler, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            // too bad - revert to non-optimized generic algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            SnmpOid next = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                next = handler.getNext(next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                final Object value = handler.getData(next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                if (value instanceof GarbageCollectorMXBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    // That's the next! return it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    return next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                // skip to next index...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            } while (next != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         * Returns the data associated with the given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         * If the given index is not found, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         * Note that returning null does not necessarily means that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         * the index was not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        public Object  getData(SnmpTableHandler handler, SnmpOid index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            final Object value = handler.getData(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            if (value instanceof GarbageCollectorMXBean) return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            // Behaves as if there was nothing at this index...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
         * Returns true if the given <var>index</var> is present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        public boolean contains(SnmpTableHandler handler, SnmpOid index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            if (handler.getData(index) instanceof GarbageCollectorMXBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            // Behaves as if there was nothing at this index...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    private transient JvmMemManagerTableMetaImpl managers = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private static GCTableFilter filter = new GCTableFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Constructor for the table. Initialize metadata for "JvmMemGCTableMeta".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public JvmMemGCTableMetaImpl(SnmpMib myMib,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                 SnmpStandardObjectServer objserv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        super(myMib,objserv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    // Returns a pointer to the JvmMemManager meta node - we're going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    // to reuse its SnmpTableHandler by filtering out all that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    // not a GarbageCollectorMXBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private final JvmMemManagerTableMetaImpl getManagers(SnmpMib mib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (managers == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            managers = (JvmMemManagerTableMetaImpl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                mib.getRegisteredTableMeta("JvmMemManagerTable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return managers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Returns the JvmMemManagerTable SnmpTableHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    protected SnmpTableHandler getHandler(Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        JvmMemManagerTableMetaImpl managerTable= getManagers(theMib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return managerTable.getHandler(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    protected SnmpOid getNextOid(Object userData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        // null means get the first OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return getNextOid(null,userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    protected SnmpOid getNextOid(SnmpOid oid, Object userData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        final boolean dbg = log.isDebugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            if (dbg) log.debug("getNextOid", "previous=" + oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            // Get the data handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            SnmpTableHandler handler = getHandler(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                // This should never happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                // If we get here it's a bug.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                if (dbg) log.debug("getNextOid", "handler is null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            // Get the next oid, using the GC filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            final SnmpOid next = filter.getNext(handler,oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            if (dbg) log.debug("getNextOid", "next=" + next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            // if next is null: we reached the end of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            if (next == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            return next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        } catch (RuntimeException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            // debug. This should never happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            if (dbg) log.debug("getNextOid",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            throw x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    protected boolean contains(SnmpOid oid, Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // Get the handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        SnmpTableHandler handler = getHandler(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        // handler should never be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (handler == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return filter.contains(handler,oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public Object getEntry(SnmpOid oid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (oid == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        // Get the request contextual cache (userData).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        final Map<Object, Object> m = JvmContextFactory.getUserData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // First look in the request contextual cache: maybe we've already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        // created this entry...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // We know in the case of this table that the index is an integer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        // it is thus the first OID arc of the index OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        final long   index    = oid.getOidArc(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // We're going to use this name to store/retrieve the entry in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // the request contextual cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        // Revisit: Probably better programming to put all these strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        //          in some interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        final String entryTag = ((m==null)?null:("JvmMemGCTable.entry." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                                                 index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        // If the entry is in the cache, simply return it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            final Object entry = m.get(entryTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            if (entry != null) return entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        // Entry was not in request cache. Make a new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        // Get the data hanler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        SnmpTableHandler handler = getHandler(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        // handler should never be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (handler == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        // Use the filter to retrieve only GarabageCollectorMBean data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        final Object data = filter.getData(handler,oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        // data may be null if the OID we were given is not valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        // (e.g. it identifies a MemoryManager which is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        // GarbageCollector)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (data == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        // Make a new entryy (transient object that will be kept only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        // for the duration of the request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        final Object entry =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            new JvmMemGCEntryImpl((GarbageCollectorMXBean)data,(int)index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        // Put the entry in the request cache in case we need it later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        // in the processing of the request. Note that we could have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        // optimized this by making JvmMemGCEntryImpl extend
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        // JvmMemManagerEntryImpl, and then make sure that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        // JvmMemManagerTableMetaImpl creates an instance of JvmMemGCEntryImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        // instead of JvmMemManagerEntryImpl when the associated data is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        // an instance of GarbageCollectorMXBean. This would have made it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        // possible to share the transient entry object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        // As it is, we may have two transient objects that points to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        // the same underlying MemoryManagerMXBean (which is definitely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        // not a problem - but is only a small dysatisfaction)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        if (m != null && entry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            m.put(entryTag,entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    static final MibLogger log = new MibLogger(JvmMemGCTableMetaImpl.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
}