jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemManagerTableMetaImpl.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 com.sun.jmx.mbeanserver.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.TreeMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
// jmx imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.jmx.snmp.SnmpOid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.jmx.snmp.SnmpStatusException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
// jdmk imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import com.sun.jmx.snmp.agent.SnmpMib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.lang.management.MemoryManagerMXBean;
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.JvmMemManagerTableMeta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.management.snmp.util.SnmpTableCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.management.snmp.util.SnmpNamedListTableCache;
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 "JvmMemManagerTable" table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * This custom implementation show how to implement an SNMP table
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * over a weak cache, recomputing the cahed data when needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class JvmMemManagerTableMetaImpl extends JvmMemManagerTableMeta {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    64
    static final long serialVersionUID = 36176771566817592L;
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    65
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * A concrete implementation of {@link SnmpNamedListTableCache}, for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * jvmMemManagerTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static class JvmMemManagerTableCache
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        extends SnmpNamedListTableCache {
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    72
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    73
        static final long serialVersionUID = 6564294074653009240L;
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    74
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
         * Create a weak cache for the jvmMemManagerTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
         * @param validity validity of the cached data, in ms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        JvmMemManagerTableCache(long validity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            this.validity = validity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         * Use the MemoryManagerMXBean name as key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
         * @param context A {@link TreeMap} as allocated by the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
         *        {@link SnmpNamedListTableCache} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         * @param rawDatas List of {@link MemoryManagerMXBean}, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         *        returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         * <code>ManagementFactory.getMemoryMBean().getMemoryManagers()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         * @param rank The <var>rank</var> of <var>item</var> in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         * @param item The <var>rank</var><super>th</super>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         *        <code>MemoryManagerMXBean</code> in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         * @return  <code>((MemoryManagerMXBean)item).getName()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         **/
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    95
        protected String getKey(Object context, List<?> rawDatas,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                int rank, Object item) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            if (item == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            final String name = ((MemoryManagerMXBean)item).getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            log.debug("getKey", "key=" + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         * Call <code>getTableHandler(JvmContextFactory.getUserData())</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        public SnmpTableHandler getTableHandler() {
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   107
            final Map<Object, Object> userData = JvmContextFactory.getUserData();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            return getTableDatas(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         * Return the key used to cache the raw data of this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        protected String getRawDatasKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            return "JvmMemManagerTable.getMemoryManagers";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         * Call ManagementFactory.getMemoryManagerMXBeans() to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         * load the raw data of this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         **/
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   122
        protected List<MemoryManagerMXBean> loadRawDatas(Map<Object, Object> userData) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            return ManagementFactory.getMemoryManagerMXBeans();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    // The weak cache for this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    protected SnmpTableCache cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Constructor for the table. Initialize metadata for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * "JvmMemManagerTableMeta".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * The reference on the MBean server is updated so the entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * created through an SNMP SET will be AUTOMATICALLY REGISTERED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * in Java DMK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public JvmMemManagerTableMetaImpl(SnmpMib myMib,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                      SnmpStandardObjectServer objserv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        super(myMib,objserv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        this.cache = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            JvmMemManagerTableCache(((JVM_MANAGEMENT_MIB_IMPL)myMib).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                    validity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    protected SnmpOid getNextOid(Object userData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        // null means get the first OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return getNextOid(null,userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    protected SnmpOid getNextOid(SnmpOid oid, Object userData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        final boolean dbg = log.isDebugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (dbg) log.debug("getNextOid", "previous=" + oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        // Get the data handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        SnmpTableHandler handler = getHandler(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            // This should never happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            // If we get here it's a bug.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            if (dbg) log.debug("getNextOid", "handler is null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        // Get the next oid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        final SnmpOid next = handler.getNext(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (dbg) log.debug("getNextOid", "next=" + next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        // if next is null: we reached the end of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (next == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return next;
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
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    protected boolean contains(SnmpOid oid, Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        // Get the handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        SnmpTableHandler handler = getHandler(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        // handler should never be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (handler == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return handler.contains(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public Object getEntry(SnmpOid oid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (oid == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        // Get the request contextual cache (userData).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        final Map<Object, Object> m = JvmContextFactory.getUserData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // We know in the case of this table that the index is an integer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // it is thus the first OID arc of the index OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        final long   index    = oid.getOidArc(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        // We're going to use this name to store/retrieve the entry in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        // the request contextual cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // Revisit: Probably better programming to put all these strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        //          in some interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        final String entryTag = ((m==null)?null:("JvmMemManagerTable.entry." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                                 index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        // If the entry is in the cache, simply return it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            final Object entry = m.get(entryTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            if (entry != null) return entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        // The entry was not in the cache, make a new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        // Get the data hanler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        SnmpTableHandler handler = getHandler(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        // handler should never be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (handler == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        // Get the data associated with our entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        final Object data = handler.getData(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // data may be null if the OID we were given is not valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (data == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        // make the new entry (transient object that will be kept only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        // for the duration of the request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        final Object entry =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            new JvmMemManagerEntryImpl((MemoryManagerMXBean)data,(int)index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        // Put the entry in the cache in case we need it later while processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        // the request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (m != null && entry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            m.put(entryTag,entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Get the SnmpTableHandler that holds the jvmMemManagerTable data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * First look it up in the request contextual cache, and if it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * not found, obtain it from the weak cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <br>The request contextual cache will be released at the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * current requests, and is used only to process this request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <br>The weak cache is shared by all requests, and is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * recomputed when it is found to be obsolete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <br>Note that the data put in the request contextual cache is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *     never considered to be obsolete, in order to preserve data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *     coherency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    protected SnmpTableHandler getHandler(Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        final Map<Object, Object> m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (userData instanceof Map) m=Util.cast(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        else m=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        // Look in the contextual cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            final SnmpTableHandler handler =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                (SnmpTableHandler)m.get("JvmMemManagerTable.handler");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            if (handler != null) return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        // No handler in contextual cache, make a new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        final SnmpTableHandler handler = cache.getTableHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (m != null && handler != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            m.put("JvmMemManagerTable.handler",handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    static final MibLogger log =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        new MibLogger(JvmMemManagerTableMetaImpl.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
}