jdk/src/jdk.snmp/share/classes/sun/management/snmp/jvminstr/JvmMemPoolTableMetaImpl.java
author sundar
Mon, 15 Sep 2014 15:18:13 +0530
changeset 26647 a6acc63c2a31
parent 25859 3317bb8137f4
permissions -rw-r--r--
8058422: Users should be able to overwrite "context" and "engine" variables Reviewed-by: lagergren, attila
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 11530
diff changeset
     2
 * Copyright (c) 2003, 2012, 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
// java imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jmx.mbeanserver.Util;
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
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 javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import com.sun.jmx.snmp.SnmpOid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import com.sun.jmx.snmp.SnmpStatusException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
// jdmk imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import com.sun.jmx.snmp.agent.SnmpMib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import com.sun.jmx.snmp.agent.SnmpMibSubRequest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.lang.management.MemoryPoolMXBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.lang.management.ManagementFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.management.snmp.jvmmib.JvmMemPoolTableMeta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.management.snmp.util.SnmpTableCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.management.snmp.util.SnmpNamedListTableCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.management.snmp.util.SnmpTableHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.management.snmp.util.MibLogger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.management.snmp.util.JvmContextFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * The class is used for implementing the "JvmMemPoolTable" group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class JvmMemPoolTableMetaImpl extends JvmMemPoolTableMeta {
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 = -2525820976094284957L;
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
     * jvmMemPoolTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static class JvmMemPoolTableCache extends SnmpNamedListTableCache {
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    71
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    72
        static final long serialVersionUID = -1755520683086760574L;
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    73
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
         * Create a weak cache for the jvmMemPoolTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
         * @param validity validity of the cached data, in ms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        JvmMemPoolTableCache(long validity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            this.validity = validity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
         * Use the MemoryPoolMXBean name as key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         * @param context A {@link TreeMap} as allocated by the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
         *        {@link SnmpNamedListTableCache} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
         * @param rawDatas List of {@link MemoryPoolMXBean}, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         *        returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         * <code>ManagementFactory.getMemoryPoolMXBeans()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         * @param rank The <var>rank</var> of <var>item</var> in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         * @param item The <var>rank</var><super>th</super>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         *        <code>MemoryPoolMXBean</code> in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         * @return  <code>((MemoryPoolMXBean)item).getName()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         **/
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    94
        protected String getKey(Object context, List<?> rawDatas,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                int rank, Object item) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            if (item == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            final String name = ((MemoryPoolMXBean)item).getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            log.debug("getKey", "key=" + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
         * Call <code>getTableDatas(JvmContextFactory.getUserData())</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        public SnmpTableHandler getTableHandler() {
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   106
            final Map<Object, Object> userData = JvmContextFactory.getUserData();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            return getTableDatas(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         * Return the key used to cache the raw data of this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        protected String getRawDatasKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            return "JvmMemManagerTable.getMemoryPools";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         * Call ManagementFactory.getMemoryPoolMXBeans() to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         * load the raw data of this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         **/
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   121
        protected List<MemoryPoolMXBean> loadRawDatas(Map<Object, Object> userData) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            return ManagementFactory.getMemoryPoolMXBeans();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    // The weak cache for this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    protected SnmpTableCache cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Constructor for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Initialize metadata for "JvmMemPoolTableMeta".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public JvmMemPoolTableMetaImpl(SnmpMib myMib,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                   SnmpStandardObjectServer objserv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        super(myMib,objserv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        this.cache = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            JvmMemPoolTableCache(((JVM_MANAGEMENT_MIB_IMPL)myMib).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                    validity()*30);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    protected SnmpOid getNextOid(Object userData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        // null means get the first OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return getNextOid(null,userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    protected SnmpOid getNextOid(SnmpOid oid, Object userData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        final boolean dbg = log.isDebugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            if (dbg) log.debug("getNextOid", "previous=" + oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            // Get the data handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            SnmpTableHandler handler = getHandler(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                // This should never happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                // If we get here it's a bug.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                if (dbg) log.debug("getNextOid", "handler is null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            // Get the next oid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            final SnmpOid next = handler.getNext(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (dbg) log.debug("getNextOid", "next=" + next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            // if next is null: we reached the end of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            if (next == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            return next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        } catch (SnmpStatusException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            if (dbg) log.debug("getNextOid", "End of MIB View: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            throw x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        } catch (RuntimeException r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            if (dbg) log.debug("getNextOid", "Unexpected exception: " + r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            if (dbg) log.debug("getNextOid",r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            throw r;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    protected boolean contains(SnmpOid oid, Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        // Get the handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        SnmpTableHandler handler = getHandler(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        // handler should never be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (handler == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return handler.contains(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public Object getEntry(SnmpOid oid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (oid == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // Get the request contextual cache (userData).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        final Map<Object, Object> m = Util.cast(JvmContextFactory.getUserData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        // We know in the case of this table that the index is an integer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // it is thus the first OID arc of the index OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        final long   index    = oid.getOidArc(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        // We're going to use this name to store/retrieve the entry in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // the request contextual cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        // Revisit: Probably better programming to put all these strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        //          in some interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        final String entryTag = ((m==null)?null:("JvmMemPoolTable.entry." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                                                 index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        // If the entry is in the cache, simply return it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            final Object entry = m.get(entryTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (entry != null) return entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // The entry was not in the cache, make a new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        // Get the data hanler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        SnmpTableHandler handler = getHandler(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        // handler should never be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (handler == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        // Get the data associated with our entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        final Object data = handler.getData(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        // data may be null if the OID we were given is not valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (data == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        // make the new entry (transient object that will be kept only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        // for the duration of the request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (log.isDebugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            log.debug("getEntry","data is a: " + data.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        final Object entry =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            new JvmMemPoolEntryImpl((MemoryPoolMXBean)data,(int)index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // Put the entry in the cache in case we need it later while processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        // the request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (m != null && entry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            m.put(entryTag,entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Get the SnmpTableHandler that holds the jvmMemPoolTable data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * First look it up in the request contextual cache, and if it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * not found, obtain it from the weak cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * <br>The request contextual cache will be released at the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * current requests, and is used only to process this request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * <br>The weak cache is shared by all requests, and is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * recomputed when it is found to be obsolete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * <br>Note that the data put in the request contextual cache is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *     never considered to be obsolete, in order to preserve data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *     coherency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    protected SnmpTableHandler getHandler(Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        final Map<Object, Object> m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (userData instanceof Map) m = Util.cast(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        else m = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        // Look in the contextual cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            final SnmpTableHandler handler =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                (SnmpTableHandler)m.get("JvmMemPoolTable.handler");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            if (handler != null) 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
        // No handler in contextual cache, make a new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        final SnmpTableHandler handler = cache.getTableHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (m != null && handler != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            m.put("JvmMemPoolTable.handler",handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    static final MibLogger log = new MibLogger(JvmMemPoolTableMetaImpl.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
}