History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/management/snmp/jvminstr/JvmRTBootClassPathTableMetaImpl.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/management/snmp/jvminstr/JvmRTBootClassPathTableMetaImpl.java+300−0
@@ -0,0 +1,300 @@
1+/*
2+ * Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+package sun.management.snmp.jvminstr;
26+
27+// java imports
28+//
29+import com.sun.jmx.mbeanserver.Util;
30+import java.util.List;
31+import java.util.Map;
32+
33+// jmx imports
34+//
35+import javax.management.MBeanServer;
36+import javax.management.ObjectName;
37+import com.sun.jmx.snmp.SnmpCounter;
38+import com.sun.jmx.snmp.SnmpCounter64;
39+import com.sun.jmx.snmp.SnmpGauge;
40+import com.sun.jmx.snmp.SnmpInt;
41+import com.sun.jmx.snmp.SnmpUnsignedInt;
42+import com.sun.jmx.snmp.SnmpIpAddress;
43+import com.sun.jmx.snmp.SnmpTimeticks;
44+import com.sun.jmx.snmp.SnmpOpaque;
45+import com.sun.jmx.snmp.SnmpString;
46+import com.sun.jmx.snmp.SnmpStringFixed;
47+import com.sun.jmx.snmp.SnmpOid;
48+import com.sun.jmx.snmp.SnmpNull;
49+import com.sun.jmx.snmp.SnmpValue;
50+import com.sun.jmx.snmp.SnmpVarBind;
51+import com.sun.jmx.snmp.SnmpStatusException;
52+
53+// jdmk imports
54+//
55+import com.sun.jmx.snmp.agent.SnmpIndex;
56+import com.sun.jmx.snmp.agent.SnmpMib;
57+import com.sun.jmx.snmp.agent.SnmpMibTable;
58+import com.sun.jmx.snmp.agent.SnmpMibSubRequest;
59+import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
60+
61+import sun.management.snmp.jvmmib.JvmRTBootClassPathTableMeta;
62+import sun.management.snmp.util.SnmpCachedData;
63+import sun.management.snmp.util.SnmpTableCache;
64+import sun.management.snmp.util.SnmpTableHandler;
65+import sun.management.snmp.util.MibLogger;
66+import sun.management.snmp.util.JvmContextFactory;
67+
68+/**
69+ * The class is used for implementing the "JvmRTBootClassPathTable".
70+ */
71+public class JvmRTBootClassPathTableMetaImpl
72+ extends JvmRTBootClassPathTableMeta {
73+
74+ private SnmpTableCache cache;
75+
76+ /**
77+ * A concrete implementation of {@link SnmpTableCache}, for the
78+ * JvmRTBootClassPathTable.
79+ **/
80+ private static class JvmRTBootClassPathTableCache extends SnmpTableCache {
81+ private JvmRTBootClassPathTableMetaImpl meta;
82+
83+ JvmRTBootClassPathTableCache(JvmRTBootClassPathTableMetaImpl meta,
84+ long validity) {
85+ this.meta = meta;
86+ this.validity = validity;
87+ }
88+
89+ /**
90+ * Call <code>getTableDatas(JvmContextFactory.getUserData())</code>.
91+ **/
92+ public SnmpTableHandler getTableHandler() {
93+ final Map userData = JvmContextFactory.getUserData();
94+ return getTableDatas(userData);
95+ }
96+
97+
98+ /**
99+ * Return a table handler containing the Thread indexes.
100+ * Indexes are computed from the ThreadId.
101+ **/
102+ protected SnmpCachedData updateCachedDatas(Object userData) {
103+
104+
105+ // We are getting all the input args
106+ final String[] path =
107+ JvmRuntimeImpl.getBootClassPath(userData);
108+
109+ // Time stamp for the cache
110+ final long time = System.currentTimeMillis();
111+ final int len = path.length;
112+
113+ SnmpOid indexes[] = new SnmpOid[len];
114+
115+ for(int i = 0; i < len; i++) {
116+ indexes[i] = new SnmpOid(i + 1);
117+ }
118+
119+ return new SnmpCachedData(time, indexes, path);
120+ }
121+ }
122+
123+ /**
124+ * Constructor for the table. Initialize metadata for
125+ * "JvmRTBootClassPathTableMeta".
126+ * The reference on the MBean server is updated so the entries
127+ * created through an SNMP SET will be AUTOMATICALLY REGISTERED
128+ * in Java DMK.
129+ */
130+ public JvmRTBootClassPathTableMetaImpl(SnmpMib myMib,
131+ SnmpStandardObjectServer objserv) {
132+ super(myMib, objserv);
133+ cache = new JvmRTBootClassPathTableCache(this, -1);
134+ }
135+
136+ // See com.sun.jmx.snmp.agent.SnmpMibTable
137+ protected SnmpOid getNextOid(Object userData)
138+ throws SnmpStatusException {
139+ // null means get the first OID.
140+ return getNextOid(null,userData);
141+ }
142+
143+ // See com.sun.jmx.snmp.agent.SnmpMibTable
144+ protected SnmpOid getNextOid(SnmpOid oid, Object userData)
145+ throws SnmpStatusException {
146+ final boolean dbg = log.isDebugOn();
147+ if (dbg) log.debug("getNextOid", "previous=" + oid);
148+
149+
150+ // Get the data handler.
151+ //
152+ SnmpTableHandler handler = getHandler(userData);
153+ if (handler == null) {
154+ // This should never happen.
155+ // If we get here it's a bug.
156+ //
157+ if (dbg) log.debug("getNextOid", "handler is null!");
158+ throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
159+ }
160+
161+ // Get the next oid
162+ //
163+ final SnmpOid next = handler.getNext(oid);
164+ if (dbg) log.debug("*** **** **** **** getNextOid", "next=" + next);
165+
166+ // if next is null: we reached the end of the table.
167+ //
168+ if (next == null)
169+ throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
170+
171+ return next;
172+ }
173+
174+
175+ // See com.sun.jmx.snmp.agent.SnmpMibTable
176+ protected boolean contains(SnmpOid oid, Object userData) {
177+
178+ // Get the handler.
179+ //
180+ SnmpTableHandler handler = getHandler(userData);
181+
182+ // handler should never be null.
183+ //
184+ if (handler == null)
185+ return false;
186+
187+ return handler.contains(oid);
188+ }
189+
190+ // See com.sun.jmx.snmp.agent.SnmpMibTable
191+ public Object getEntry(SnmpOid oid)
192+ throws SnmpStatusException {
193+ final boolean dbg = log.isDebugOn();
194+ if (dbg) log.debug("getEntry", "oid [" + oid + "]");
195+ if (oid == null || oid.getLength() != 1) {
196+ if (dbg) log.debug("getEntry", "Invalid oid [" + oid + "]");
197+ throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
198+ }
199+
200+ // Get the request contextual cache (userData).
201+ //
202+ final Map<Object, Object> m = JvmContextFactory.getUserData();
203+
204+ // We're going to use this name to store/retrieve the entry in
205+ // the request contextual cache.
206+ //
207+ // Revisit: Probably better programming to put all these strings
208+ // in some interface.
209+ //
210+ final String entryTag = ((m==null)?null:
211+ ("JvmRTBootClassPathTable.entry." +
212+ oid.toString()));
213+
214+ // If the entry is in the cache, simply return it.
215+ //
216+ if (m != null) {
217+ final Object entry = m.get(entryTag);
218+ if (entry != null) {
219+ if (dbg)
220+ log.debug("getEntry", "Entry is already in the cache");
221+ return entry;
222+ } else
223+ if (dbg) log.debug("getEntry", "Entry is not in the cache");
224+ }
225+
226+ // The entry was not in the cache, make a new one.
227+ //
228+ // Get the data hanler.
229+ //
230+ SnmpTableHandler handler = getHandler(m);
231+
232+ // handler should never be null.
233+ //
234+ if (handler == null)
235+ throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
236+
237+ // Get the data associated with our entry.
238+ //
239+ final Object data = handler.getData(oid);
240+
241+ // data may be null if the OID we were given is not valid.
242+ //
243+ if (data == null)
244+ throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
245+
246+ // make the new entry (transient object that will be kept only
247+ // for the duration of the request.
248+ //
249+ if (dbg)
250+ log.debug("getEntry","data is a: " + data.getClass().getName());
251+ final Object entry =
252+ new JvmRTBootClassPathEntryImpl((String) data,
253+ (int) oid.getOidArc(0));
254+
255+ // Put the entry in the cache in case we need it later while processing
256+ // the request.
257+ //
258+ if (m != null && entry != null) {
259+ m.put(entryTag,entry);
260+ }
261+
262+ return entry;
263+ }
264+
265+ /**
266+ * Get the SnmpTableHandler that holds the jvmThreadInstanceTable data.
267+ * First look it up in the request contextual cache, and if it is
268+ * not found, obtain it from the weak cache.
269+ * <br>The request contextual cache will be released at the end of the
270+ * current requests, and is used only to process this request.
271+ * <br>The weak cache is shared by all requests, and is only
272+ * recomputed when it is found to be obsolete.
273+ * <br>Note that the data put in the request contextual cache is
274+ * never considered to be obsolete, in order to preserve data
275+ * coherency.
276+ **/
277+ protected SnmpTableHandler getHandler(Object userData) {
278+ final Map<Object, Object> m;
279+ if (userData instanceof Map) m=Util.cast(userData);
280+ else m=null;
281+
282+ // Look in the contextual cache.
283+ if (m != null) {
284+ final SnmpTableHandler handler =
285+ (SnmpTableHandler)m.get("JvmRTBootClassPathTable.handler");
286+ if (handler != null) return handler;
287+ }
288+
289+ // No handler in contextual cache, make a new one.
290+ final SnmpTableHandler handler = cache.getTableHandler();
291+
292+ if (m != null && handler != null )
293+ m.put("JvmRTBootClassPathTable.handler",handler);
294+
295+ return handler;
296+ }
297+
298+ static final MibLogger log =
299+ new MibLogger(JvmRTBootClassPathTableMetaImpl.class);
300+}