jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemMgrPoolRelTableMetaImpl.java
author alanb
Fri, 02 Nov 2012 15:50:11 +0000
changeset 14342 8435a30053c1
parent 11530 a9d059c15b80
permissions -rw-r--r--
7197491: update copyright year to match last edit in jdk8 jdk repository Reviewed-by: chegar, ksrini
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.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.TreeMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
// jmx imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import com.sun.jmx.snmp.SnmpOid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import com.sun.jmx.snmp.SnmpStatusException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
// jdmk imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import com.sun.jmx.snmp.agent.SnmpMib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import com.sun.jmx.snmp.agent.SnmpMibTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.lang.management.MemoryManagerMXBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.lang.management.MemoryPoolMXBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.management.snmp.jvmmib.JvmMemMgrPoolRelTableMeta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.management.snmp.util.SnmpTableCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.management.snmp.util.SnmpCachedData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.management.snmp.util.SnmpTableHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.management.snmp.util.MibLogger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import sun.management.snmp.util.JvmContextFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * The class is used for implementing the "JvmMemMgrPoolRelTable" group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
public class JvmMemMgrPoolRelTableMetaImpl extends JvmMemMgrPoolRelTableMeta
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    67
    static final long serialVersionUID = 1896509775012355443L;
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    68
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * A concrete implementation of {@link SnmpTableCache}, for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * jvmMemMgrPoolRelTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     **/
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    73
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static class JvmMemMgrPoolRelTableCache
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        extends SnmpTableCache {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    77
        static final long serialVersionUID = 6059937161990659184L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        final private JvmMemMgrPoolRelTableMetaImpl meta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
         * Create a weak cache for the jvmMemMgrPoolRelTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
         * @param validity validity of the cached data, in ms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        JvmMemMgrPoolRelTableCache(JvmMemMgrPoolRelTableMetaImpl meta,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                                   long validity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            this.validity = validity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            this.meta     = meta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         * Call <code>getTableDatas(JvmContextFactory.getUserData())</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        public SnmpTableHandler getTableHandler() {
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
    94
            final Map<Object,Object> userData = JvmContextFactory.getUserData();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            return getTableDatas(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
         * Builds a map pool-name => pool-index from the SnmpTableHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
         * of the JvmMemPoolTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        private static Map<String, SnmpOid> buildPoolIndexMap(SnmpTableHandler handler) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            // optimization...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            if (handler instanceof SnmpCachedData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                return buildPoolIndexMap((SnmpCachedData)handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            // not optimizable... too bad.
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   108
            final Map<String, SnmpOid> m = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            SnmpOid index=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            while ((index = handler.getNext(index))!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                final MemoryPoolMXBean mpm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    (MemoryPoolMXBean)handler.getData(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                if (mpm == null) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                final String name = mpm.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                if (name == null) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                m.put(name,index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            return m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         * Builds a map pool-name => pool-index from the SnmpTableHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
         * of the JvmMemPoolTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         * Optimized algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        private static Map<String, SnmpOid> buildPoolIndexMap(SnmpCachedData cached) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            if (cached == null) return Collections.emptyMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            final SnmpOid[] indexes = cached.indexes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            final Object[]  datas   = cached.datas;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            final int len = indexes.length;
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   131
            final Map<String, SnmpOid> m = new HashMap<>(len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            for (int i=0; i<len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                final SnmpOid index = indexes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                if (index == null) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                final MemoryPoolMXBean mpm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    (MemoryPoolMXBean)datas[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                if (mpm == null) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                final String name = mpm.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                if (name == null) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                m.put(name,index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            return m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * Return a table handler that holds the jvmMemManagerTable table data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         * This method return the cached table data if it is still
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         * valid, recompute it and cache the new value if it's not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         * If it needs to recompute the cached data, it first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         * try to obtain the list of memory managers from the request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         * contextual cache, and if it is not found, it calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
         * <code>ManagementFactory.getMemoryMBean().getMemoryManagers()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         * and caches the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         * This ensures that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
         * <code>ManagementFactory.getMemoryMBean().getMemoryManagers()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         * is not called more than once per request, thus ensuring a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         * consistent view of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        protected SnmpCachedData updateCachedDatas(Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            // Get the MemoryManager     table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            final SnmpTableHandler mmHandler =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                meta.getManagerHandler(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            // Get the MemoryPool        table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            final SnmpTableHandler mpHandler =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                meta.getPoolHandler(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            // Time stamp for the cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            final long time = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            //     Build a Map poolname -> index
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   172
            final Map<String,SnmpOid> poolIndexMap = buildPoolIndexMap(mpHandler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            // For each memory manager, get the list of memory pools
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            // For each memory pool, find its index in the memory pool table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            // Create a row in the relation table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            final TreeMap<SnmpOid, Object> table =
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   178
                    new TreeMap<>(SnmpCachedData.oidComparator);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            updateTreeMap(table,userData,mmHandler,mpHandler,poolIndexMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return new SnmpCachedData(time,table);
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
         * Get the list of memory pool associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         * given MemoryManagerMXBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        protected String[] getMemoryPools(Object userData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                      MemoryManagerMXBean mmm, long mmarc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            final String listTag =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                "JvmMemManager." + mmarc + ".getMemoryPools";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            String[] result=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            if (userData instanceof Map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                result = (String[])((Map)userData).get(listTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                if (result != null) return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            if (mmm!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                result = mmm.getMemoryPoolNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            if ((result!=null)&&(userData instanceof Map)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                Map<Object, Object> map = Util.cast(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                map.put(listTag,result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                     MemoryManagerMXBean mmm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                     SnmpOid mmIndex,
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   214
                                     Map<String, SnmpOid> poolIndexMap) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            // The MemoryManager index is an int, so it's the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            // and only subidentifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            final long mmarc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                mmarc = mmIndex.getOidArc(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            } catch (SnmpStatusException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                log.debug("updateTreeMap",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                          "Bad MemoryManager OID index: "+mmIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                log.debug("updateTreeMap",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            // Cache this in userData + get it from cache?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            final String[] mpList = getMemoryPools(userData,mmm,mmarc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if (mpList == null || mpList.length < 1) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            final String mmmName = mmm.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            for (int i = 0; i < mpList.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                final String mpmName = mpList[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                if (mpmName == null) continue;
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   237
                final SnmpOid mpIndex = poolIndexMap.get(mpmName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                if (mpIndex == null) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                // The MemoryPool index is an int, so it's the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                // and only subidentifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                final long mparc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    mparc  = mpIndex.getOidArc(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                } catch (SnmpStatusException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    log.debug("updateTreeMap","Bad MemoryPool OID index: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                          mpIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    log.debug("updateTreeMap",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                // The MemoryMgrPoolRel table indexed is composed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                // of the MemoryManager index, to which the MemoryPool
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                // index is appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                final long[] arcs = { mmarc, mparc };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                final SnmpOid index = new SnmpOid(arcs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                table.put(index, new JvmMemMgrPoolRelEntryImpl(mmmName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                                               mpmName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                                               (int)mmarc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                                               (int)mparc));
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
        protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                     SnmpTableHandler mmHandler,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                     SnmpTableHandler mpHandler,
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   268
                                     Map<String, SnmpOid> poolIndexMap) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            if (mmHandler instanceof SnmpCachedData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                updateTreeMap(table,userData,(SnmpCachedData)mmHandler,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                              mpHandler,poolIndexMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            SnmpOid mmIndex=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            while ((mmIndex = mmHandler.getNext(mmIndex))!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                final MemoryManagerMXBean mmm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    (MemoryManagerMXBean)mmHandler.getData(mmIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                if (mmm == null) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                updateTreeMap(table,userData,mmm,mmIndex,poolIndexMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                                     SnmpCachedData mmHandler,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                                     SnmpTableHandler mpHandler,
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   287
                                     Map<String, SnmpOid> poolIndexMap) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            final SnmpOid[] indexes = mmHandler.indexes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            final Object[]  datas   = mmHandler.datas;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            final int size = indexes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            for (int i=size-1; i>-1; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                final MemoryManagerMXBean mmm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    (MemoryManagerMXBean)datas[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                if (mmm == null) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                updateTreeMap(table,userData,mmm,indexes[i],poolIndexMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    // The weak cache for this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    protected SnmpTableCache cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    private transient JvmMemManagerTableMetaImpl managers = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    private transient JvmMemPoolTableMetaImpl    pools    = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Constructor for the table. Initialize metadata for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * "JvmMemMgrPoolRelTableMeta".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * The reference on the MBean server is updated so the entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * created through an SNMP SET will be AUTOMATICALLY REGISTERED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * in Java DMK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public JvmMemMgrPoolRelTableMetaImpl(SnmpMib myMib,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                      SnmpStandardObjectServer objserv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        super(myMib,objserv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        this.cache = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            JvmMemMgrPoolRelTableCache(this,((JVM_MANAGEMENT_MIB_IMPL)myMib).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                       validity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    // Returns a pointer to the JvmMemManager meta node - we're going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    // to reuse its SnmpTableHandler in order to implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    // relation table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    private final JvmMemManagerTableMetaImpl getManagers(SnmpMib mib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (managers == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            managers = (JvmMemManagerTableMetaImpl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                mib.getRegisteredTableMeta("JvmMemManagerTable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return managers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    // Returns a pointer to the JvmMemPool meta node - we're going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    // to reuse its SnmpTableHandler in order to implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    // relation table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    private final JvmMemPoolTableMetaImpl getPools(SnmpMib mib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (pools == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            pools = (JvmMemPoolTableMetaImpl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                mib.getRegisteredTableMeta("JvmMemPoolTable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        return pools;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Returns the JvmMemManagerTable SnmpTableHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    protected SnmpTableHandler getManagerHandler(Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        final JvmMemManagerTableMetaImpl managerTable = getManagers(theMib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return managerTable.getHandler(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Returns the JvmMemPoolTable SnmpTableHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    protected SnmpTableHandler getPoolHandler(Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        final JvmMemPoolTableMetaImpl poolTable = getPools(theMib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        return poolTable.getHandler(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    protected SnmpOid getNextOid(Object userData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        // null means get the first OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return getNextOid(null,userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    protected SnmpOid getNextOid(SnmpOid oid, Object userData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        final boolean dbg = log.isDebugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if (dbg) log.debug("getNextOid", "previous=" + oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        // Get the data handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        SnmpTableHandler handler = getHandler(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            // This should never happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            // If we get here it's a bug.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (dbg) log.debug("getNextOid", "handler is null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        // Get the next oid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        final SnmpOid next = handler.getNext(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        if (dbg) log.debug("getNextOid", "next=" + next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        // if next is null: we reached the end of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (next == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        return next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    protected boolean contains(SnmpOid oid, Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        // Get the handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        SnmpTableHandler handler = getHandler(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        // handler should never be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (handler == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        return handler.contains(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    // See com.sun.jmx.snmp.agent.SnmpMibTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    public Object getEntry(SnmpOid oid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        if (oid == null || oid.getLength() < 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        // Get the request contextual cache (userData).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        final Map<Object, Object> m = JvmContextFactory.getUserData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        // We know in the case of this table that the index is composed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        // of two integers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        //  o The MemoryManager is the first  OID arc of the index OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        //  o The MemoryPool    is the second OID arc of the index OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        final long   mgrIndex     = oid.getOidArc(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        final long   poolIndex    = oid.getOidArc(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        // We're going to use this name to store/retrieve the entry in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        // the request contextual cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        // Revisit: Probably better programming to put all these strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        //          in some interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        final String entryTag = ((m==null)?null:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                                 ("JvmMemMgrPoolRelTable.entry." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                                  mgrIndex + "." + poolIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        // If the entry is in the cache, simply return it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            final Object entry = m.get(entryTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            if (entry != null) return entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        // The entry was not in the cache, make a new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        // Get the data hanler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        SnmpTableHandler handler = getHandler(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        // handler should never be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (handler == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        // Get the data associated with our entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        final Object data = handler.getData(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        // data may be null if the OID we were given is not valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (!(data instanceof JvmMemMgrPoolRelEntryImpl))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // make the new entry (transient object that will be kept only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        // for the duration of the request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        final Object entry = (JvmMemMgrPoolRelEntryImpl)data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        // XXXXX Revisit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        // new JvmMemMgrPoolRelEntryImpl((MemoryManagerMXBean)data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        //                                (int)mgrIndex,(int)poolIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        // Put the entry in the cache in case we need it later while processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        // the request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        if (m != null && entry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            m.put(entryTag,entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        return entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * Get the SnmpTableHandler that holds the jvmMemManagerTable data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * First look it up in the request contextual cache, and if it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * not found, obtain it from the weak cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * <br>The request contextual cache will be released at the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * current requests, and is used only to process this request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * <br>The weak cache is shared by all requests, and is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * recomputed when it is found to be obsolete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * <br>Note that the data put in the request contextual cache is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *     never considered to be obsolete, in order to preserve data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *     coherency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    protected SnmpTableHandler getHandler(Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        final Map<Object, Object> m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        if (userData instanceof Map) m=Util.cast(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        else m=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        // Look in the contextual cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            final SnmpTableHandler handler =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                (SnmpTableHandler)m.get("JvmMemMgrPoolRelTable.handler");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            if (handler != null) return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        // No handler in contextual cache, make a new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        final SnmpTableHandler handler = cache.getTableHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        if (m != null && handler != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            m.put("JvmMemMgrPoolRelTable.handler",handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    static final MibLogger log =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        new MibLogger(JvmMemMgrPoolRelTableMetaImpl.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
}