author | dfuchs |
Wed, 28 Nov 2012 15:14:47 +0100 | |
changeset 14677 | 1607f4cfc506 |
parent 14342 | 8435a30053c1 |
child 21291 | 64a9ea14762c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
14335
diff
changeset
|
2 |
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.jmx.snmp.agent; |
|
27 |
||
28 |
import java.io.Serializable; |
|
29 |
import java.util.Enumeration; |
|
30 |
import java.util.logging.Level; |
|
31 |
import java.util.Vector; |
|
32 |
||
33 |
import javax.management.ObjectName; |
|
34 |
import javax.management.MBeanServer; |
|
35 |
import javax.management.MalformedObjectNameException; |
|
36 |
import javax.management.InstanceAlreadyExistsException; |
|
37 |
import javax.management.MBeanRegistrationException; |
|
38 |
import javax.management.NotCompliantMBeanException; |
|
39 |
||
40 |
import static com.sun.jmx.defaults.JmxProperties.SNMP_ADAPTOR_LOGGER; |
|
41 |
import com.sun.jmx.snmp.SnmpOid; |
|
42 |
import com.sun.jmx.snmp.SnmpVarBind; |
|
43 |
import com.sun.jmx.snmp.SnmpDefinitions; |
|
44 |
import com.sun.jmx.snmp.SnmpStatusException; |
|
45 |
||
46 |
/** |
|
47 |
* Abstract class for representing an SNMP MIB. |
|
48 |
* <P> |
|
49 |
* When compiling a SNMP MIB, among all the classes generated by |
|
50 |
* <CODE>mibgen</CODE>, there is one which extends <CODE>SnmpMib</CODE> |
|
51 |
* for representing a whole MIB. |
|
52 |
* <BR>The class is used by the SNMP protocol adaptor as the entry point in |
|
53 |
* the MIB. |
|
54 |
* |
|
55 |
* <p>This generated class can be subclassed in your code in order to |
|
56 |
* plug in your own specific behaviour. |
|
57 |
* </p> |
|
58 |
* |
|
59 |
* <p><b>This API is a Sun Microsystems internal API and is subject |
|
60 |
* to change without notice.</b></p> |
|
61 |
*/ |
|
62 |
public abstract class SnmpMib extends SnmpMibAgent implements Serializable { |
|
63 |
||
64 |
/** |
|
65 |
* Default constructor. |
|
66 |
* Initializes the OID tree. |
|
67 |
*/ |
|
68 |
public SnmpMib() { |
|
69 |
root= new SnmpMibOid(); |
|
70 |
} |
|
71 |
||
72 |
||
73 |
// -------------------------------------------------------------------- |
|
74 |
// POLYMORHIC METHODS |
|
75 |
// -------------------------------------------------------------------- |
|
76 |
||
77 |
/** |
|
78 |
* <p> |
|
79 |
* This callback should return the OID associated to the group |
|
80 |
* identified by the given <code>groupName</code>. |
|
81 |
* </p> |
|
82 |
* |
|
83 |
* <p> |
|
84 |
* This method is provided as a hook to plug-in some custom |
|
85 |
* specific behavior. Although doing so is discouraged you might |
|
86 |
* want to subclass this method in order to store & provide more metadata |
|
87 |
* information (mapping OID <-> symbolic name) within the agent, |
|
88 |
* or to "change" the root of the MIB OID by prefixing the |
|
89 |
* defaultOid by an application dependant OID string, for instance. |
|
90 |
* </p> |
|
91 |
* |
|
92 |
* <p> |
|
93 |
* The default implementation of this method is to return the given |
|
94 |
* <code>defaultOid</code> |
|
95 |
* </p> |
|
96 |
* |
|
97 |
* @param groupName The java-ized name of the SNMP group. |
|
98 |
* @param defaultOid The OID defined in the MIB for that group |
|
99 |
* (in dot notation). |
|
100 |
* |
|
101 |
* @return The OID of the group identified by <code>groupName</code>, |
|
102 |
* in dot-notation. |
|
103 |
*/ |
|
104 |
protected String getGroupOid(String groupName, String defaultOid) { |
|
105 |
return defaultOid; |
|
106 |
} |
|
107 |
||
108 |
/** |
|
109 |
* <p> |
|
110 |
* This callback should return the ObjectName associated to the |
|
111 |
* group identified by the given <code>groupName</code>. |
|
112 |
* </p> |
|
113 |
* |
|
114 |
* <p> |
|
115 |
* This method is provided as a hook to plug-in some custom |
|
116 |
* specific behavior. You might want to override this method |
|
117 |
* in order to provide a different object naming scheme than |
|
118 |
* that proposed by default by <code>mibgen</code>. |
|
119 |
* </p> |
|
120 |
* |
|
121 |
* <p> |
|
122 |
* This method is only meaningful if the MIB is registered |
|
123 |
* in the MBeanServer, otherwise, it will not be called. |
|
124 |
* </p> |
|
125 |
* |
|
126 |
* <p> |
|
127 |
* The default implementation of this method is to return an ObjectName |
|
128 |
* built from the given <code>defaultName</code>. |
|
129 |
* </p> |
|
130 |
* |
|
131 |
* @param name The java-ized name of the SNMP group. |
|
132 |
* @param oid The OID returned by getGroupOid() - in dot notation. |
|
133 |
* @param defaultName The name by default generated by <code> |
|
134 |
* mibgen</code> |
|
135 |
* |
|
136 |
* @return The ObjectName of the group identified by <code>name</code> |
|
137 |
*/ |
|
138 |
protected ObjectName getGroupObjectName(String name, String oid, |
|
139 |
String defaultName) |
|
140 |
throws MalformedObjectNameException { |
|
141 |
return new ObjectName(defaultName); |
|
142 |
} |
|
143 |
||
144 |
/** |
|
145 |
* <p> |
|
146 |
* Register an SNMP group and its metadata node in the MIB. |
|
147 |
* </p> |
|
148 |
* |
|
149 |
* <p> |
|
150 |
* This method is provided as a hook to plug-in some custom |
|
151 |
* specific behavior. You might want to override this method |
|
152 |
* if you want to set special links between the MBean, its metadata |
|
153 |
* node, its OID or ObjectName etc.. |
|
154 |
* </p> |
|
155 |
* |
|
156 |
* <p> |
|
157 |
* If the MIB is not registered in the MBeanServer, the <code> |
|
158 |
* server</code> and <code>groupObjName</code> parameters will be |
|
159 |
* <code>null</code>.<br> |
|
160 |
* If the given group MBean is not <code>null</code>, and if the |
|
161 |
* <code>server</code> and <code>groupObjName</code> parameters are |
|
162 |
* not null, then this method will also automatically register the |
|
163 |
* group MBean with the given MBeanServer <code>server</code>. |
|
164 |
* </p> |
|
165 |
* |
|
166 |
* @param groupName The java-ized name of the SNMP group. |
|
167 |
* @param groupOid The OID as returned by getGroupOid() - in dot |
|
168 |
* notation. |
|
169 |
* @param groupObjName The ObjectName as returned by getGroupObjectName(). |
|
170 |
* This parameter may be <code>null</code> if the |
|
171 |
* MIB is not registered in the MBeanServer. |
|
172 |
* @param node The metadata node, as returned by the metadata |
|
173 |
* factory method for this group. |
|
174 |
* @param group The MBean for this group, as returned by the |
|
175 |
* MBean factory method for this group. |
|
176 |
* @param server The MBeanServer in which the groups are to be |
|
177 |
* registered. This parameter will be <code>null</code> |
|
178 |
* if the MIB is not registered, otherwise it is a |
|
179 |
* reference to the MBeanServer in which the MIB is |
|
180 |
* registered. |
|
181 |
* |
|
182 |
*/ |
|
183 |
protected void registerGroupNode(String groupName, String groupOid, |
|
184 |
ObjectName groupObjName, SnmpMibNode node, |
|
185 |
Object group, MBeanServer server) |
|
186 |
throws NotCompliantMBeanException, MBeanRegistrationException, |
|
187 |
InstanceAlreadyExistsException, IllegalAccessException { |
|
188 |
root.registerNode(groupOid,node); |
|
189 |
if (server != null && groupObjName != null && group != null) |
|
190 |
server.registerMBean(group,groupObjName); |
|
191 |
} |
|
192 |
||
193 |
/** |
|
194 |
* <p> |
|
195 |
* Register an SNMP Table metadata node in the MIB. |
|
196 |
* </p> |
|
197 |
* |
|
198 |
* <p> |
|
199 |
* <b><i> |
|
200 |
* This method is used internally and you should never need to |
|
201 |
* call it directly.</i></b><br> It is used to establish the link |
|
202 |
* between an SNMP table metadata node and its bean-like counterpart. |
|
203 |
* <br> |
|
204 |
* The group metadata nodes will create and register their |
|
205 |
* underlying table metadata nodes in the MIB using this |
|
206 |
* method. <br> |
|
207 |
* The metadata nodes will be later retrieved from the MIB by the |
|
208 |
* bean-like table objects using the getRegisterTableMeta() method. |
|
209 |
* </p> |
|
210 |
* |
|
211 |
* @param name The java-ized name of the SNMP table. |
|
212 |
* @param table The SNMP table metadata node - usually this |
|
213 |
* corresponds to a <code>mibgen</code> generated |
|
214 |
* object. |
|
215 |
*/ |
|
216 |
public abstract void registerTableMeta(String name, SnmpMibTable table); |
|
217 |
||
218 |
/** |
|
219 |
* Returns a registered SNMP Table metadata node. |
|
220 |
* |
|
221 |
* <p><b><i> |
|
222 |
* This method is used internally and you should never need to |
|
223 |
* call it directly. |
|
224 |
* </i></b></p> |
|
225 |
* |
|
226 |
*/ |
|
227 |
public abstract SnmpMibTable getRegisteredTableMeta(String name); |
|
228 |
||
229 |
// -------------------------------------------------------------------- |
|
230 |
// PUBLIC METHODS |
|
231 |
// -------------------------------------------------------------------- |
|
232 |
||
233 |
/** |
|
234 |
* Processes a <CODE>get</CODE> operation. |
|
235 |
* |
|
236 |
**/ |
|
237 |
// Implements the method defined in SnmpMibAgent. See SnmpMibAgent |
|
238 |
// for java-doc |
|
239 |
// |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
240 |
@Override |
2 | 241 |
public void get(SnmpMibRequest req) throws SnmpStatusException { |
242 |
||
243 |
// Builds the request tree: creation is not allowed, operation |
|
244 |
// is not atomic. |
|
245 |
||
246 |
final int reqType = SnmpDefinitions.pduGetRequestPdu; |
|
247 |
SnmpRequestTree handlers = getHandlers(req,false,false,reqType); |
|
248 |
||
249 |
SnmpRequestTree.Handler h = null; |
|
250 |
SnmpMibNode meta = null; |
|
251 |
||
252 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
253 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), |
|
254 |
"get", "Processing handlers for GET... "); |
|
255 |
} |
|
256 |
||
257 |
// For each sub-request stored in the request-tree, invoke the |
|
258 |
// get() method. |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
259 |
for (Enumeration<SnmpRequestTree.Handler> eh=handlers.getHandlers();eh.hasMoreElements();) { |
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
260 |
h = eh.nextElement(); |
2 | 261 |
|
262 |
// Gets the Meta node. It can be either a Group Meta or a |
|
263 |
// Table Meta. |
|
264 |
// |
|
265 |
meta = handlers.getMetaNode(h); |
|
266 |
||
267 |
// Gets the depth of the Meta node in the OID tree |
|
268 |
final int depth = handlers.getOidDepth(h); |
|
269 |
||
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
270 |
for (Enumeration<SnmpMibSubRequest> rqs=handlers.getSubRequests(h); |
2 | 271 |
rqs.hasMoreElements();) { |
272 |
||
273 |
// Invoke the get() operation. |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
274 |
meta.get(rqs.nextElement(),depth); |
2 | 275 |
} |
276 |
} |
|
277 |
} |
|
278 |
||
279 |
/** |
|
280 |
* Processes a <CODE>set</CODE> operation. |
|
281 |
* |
|
282 |
*/ |
|
283 |
// Implements the method defined in SnmpMibAgent. See SnmpMibAgent |
|
284 |
// for java-doc |
|
285 |
// |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
286 |
@Override |
2 | 287 |
public void set(SnmpMibRequest req) throws SnmpStatusException { |
288 |
||
289 |
SnmpRequestTree handlers = null; |
|
290 |
||
291 |
// Optimization: we're going to get the whole SnmpRequestTree |
|
292 |
// built in the "check" method, so that we don't have to rebuild |
|
293 |
// it here. |
|
294 |
// |
|
295 |
if (req instanceof SnmpMibRequestImpl) |
|
296 |
handlers = ((SnmpMibRequestImpl)req).getRequestTree(); |
|
297 |
||
298 |
// Optimization didn't work: we have to rebuild the tree. |
|
299 |
// |
|
300 |
// Builds the request tree: creation is not allowed, operation |
|
301 |
// is atomic. |
|
302 |
// |
|
303 |
final int reqType = SnmpDefinitions.pduSetRequestPdu; |
|
304 |
if (handlers == null) handlers = getHandlers(req,false,true,reqType); |
|
305 |
handlers.switchCreationFlag(false); |
|
306 |
handlers.setPduType(reqType); |
|
307 |
||
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
308 |
SnmpRequestTree.Handler h; |
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
309 |
SnmpMibNode meta; |
2 | 310 |
|
311 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
312 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), |
|
313 |
"set", "Processing handlers for SET... "); |
|
314 |
} |
|
315 |
||
316 |
// For each sub-request stored in the request-tree, invoke the |
|
317 |
// get() method. |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
318 |
for (Enumeration<SnmpRequestTree.Handler> eh=handlers.getHandlers();eh.hasMoreElements();) { |
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
319 |
h = eh.nextElement(); |
2 | 320 |
|
321 |
// Gets the Meta node. It can be either a Group Meta or a |
|
322 |
// Table Meta. |
|
323 |
// |
|
324 |
meta = handlers.getMetaNode(h); |
|
325 |
||
326 |
// Gets the depth of the Meta node in the OID tree |
|
327 |
final int depth = handlers.getOidDepth(h); |
|
328 |
||
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
329 |
for (Enumeration<SnmpMibSubRequest> rqs=handlers.getSubRequests(h); |
2 | 330 |
rqs.hasMoreElements();) { |
331 |
||
332 |
// Invoke the set() operation |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
333 |
meta.set(rqs.nextElement(),depth); |
2 | 334 |
} |
335 |
} |
|
336 |
} |
|
337 |
||
338 |
/** |
|
339 |
* Checks if a <CODE>set</CODE> operation can be performed. |
|
340 |
* If the operation cannot be performed, the method will raise a |
|
341 |
* <CODE>SnmpStatusException</CODE>. |
|
342 |
* |
|
343 |
*/ |
|
344 |
// Implements the method defined in SnmpMibAgent. See SnmpMibAgent |
|
345 |
// for java-doc |
|
346 |
// |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
347 |
@Override |
2 | 348 |
public void check(SnmpMibRequest req) throws SnmpStatusException { |
349 |
||
350 |
final int reqType = SnmpDefinitions.pduWalkRequest; |
|
351 |
// Builds the request tree: creation is allowed, operation |
|
352 |
// is atomic. |
|
353 |
SnmpRequestTree handlers = getHandlers(req,true,true,reqType); |
|
354 |
||
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
355 |
SnmpRequestTree.Handler h; |
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
356 |
SnmpMibNode meta; |
2 | 357 |
|
358 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
359 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), |
|
360 |
"check", "Processing handlers for CHECK... "); |
|
361 |
} |
|
362 |
||
363 |
// For each sub-request stored in the request-tree, invoke the |
|
364 |
// check() method. |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
365 |
for (Enumeration<SnmpRequestTree.Handler> eh=handlers.getHandlers();eh.hasMoreElements();) { |
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
366 |
h = eh.nextElement(); |
2 | 367 |
|
368 |
// Gets the Meta node. It can be either a Group Meta or a |
|
369 |
// Table Meta. |
|
370 |
// |
|
371 |
meta = handlers.getMetaNode(h); |
|
372 |
||
373 |
// Gets the depth of the Meta node in the OID tree |
|
374 |
final int depth = handlers.getOidDepth(h); |
|
375 |
||
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
376 |
for (Enumeration<SnmpMibSubRequest> rqs=handlers.getSubRequests(h); |
2 | 377 |
rqs.hasMoreElements();) { |
378 |
||
379 |
// Invoke the check() operation |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
380 |
meta.check(rqs.nextElement(),depth); |
2 | 381 |
} |
382 |
} |
|
383 |
||
384 |
// Optimization: we're going to pass the whole SnmpRequestTree |
|
385 |
// to the "set" method, so that we don't have to rebuild it there. |
|
386 |
// |
|
387 |
if (req instanceof SnmpMibRequestImpl) { |
|
388 |
((SnmpMibRequestImpl)req).setRequestTree(handlers); |
|
389 |
} |
|
390 |
||
391 |
} |
|
392 |
||
393 |
/** |
|
394 |
* Processes a <CODE>getNext</CODE> operation. |
|
395 |
* |
|
396 |
*/ |
|
397 |
// Implements the method defined in SnmpMibAgent. See SnmpMibAgent |
|
398 |
// for java-doc |
|
399 |
// |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
400 |
@Override |
2 | 401 |
public void getNext(SnmpMibRequest req) throws SnmpStatusException { |
402 |
// Build the request tree for the operation |
|
403 |
// The subrequest stored in the request tree are valid GET requests |
|
404 |
SnmpRequestTree handlers = getGetNextHandlers(req); |
|
405 |
||
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
406 |
SnmpRequestTree.Handler h; |
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
407 |
SnmpMibNode meta; |
2 | 408 |
|
409 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
410 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), |
|
411 |
"getNext", "Processing handlers for GET-NEXT... "); |
|
412 |
} |
|
413 |
||
414 |
// Now invoke get() for each subrequest of the request tree. |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
415 |
for (Enumeration<SnmpRequestTree.Handler> eh=handlers.getHandlers();eh.hasMoreElements();) { |
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
416 |
h = eh.nextElement(); |
2 | 417 |
|
418 |
// Gets the Meta node. It can be either a Group Meta or a |
|
419 |
// Table Meta. |
|
420 |
// |
|
421 |
meta = handlers.getMetaNode(h); |
|
422 |
||
423 |
// Gets the depth of the Meta node in the OID tree |
|
424 |
int depth = handlers.getOidDepth(h); |
|
425 |
||
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
426 |
for (Enumeration<SnmpMibSubRequest> rqs=handlers.getSubRequests(h); |
2 | 427 |
rqs.hasMoreElements();) { |
428 |
||
429 |
// Invoke the get() operation |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
430 |
meta.get(rqs.nextElement(),depth); |
2 | 431 |
} |
432 |
} |
|
433 |
} |
|
434 |
||
435 |
||
436 |
/** |
|
437 |
* Processes a <CODE>getBulk</CODE> operation. |
|
438 |
* The method implements the <CODE>getBulk</CODE> operation by calling |
|
439 |
* appropriately the <CODE>getNext</CODE> method. |
|
440 |
* |
|
441 |
*/ |
|
442 |
// Implements the method defined in SnmpMibAgent. See SnmpMibAgent |
|
443 |
// for java-doc |
|
444 |
// |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
445 |
@Override |
2 | 446 |
public void getBulk(SnmpMibRequest req, int nonRepeat, int maxRepeat) |
447 |
throws SnmpStatusException { |
|
448 |
||
449 |
getBulkWithGetNext(req, nonRepeat, maxRepeat); |
|
450 |
} |
|
451 |
||
452 |
/** |
|
453 |
* Gets the root object identifier of the MIB. |
|
454 |
* <P>In order to be accurate, the method should be called once the |
|
455 |
* MIB is fully initialized (that is, after a call to <CODE>init</CODE> |
|
456 |
* or <CODE>preRegister</CODE>). |
|
457 |
* |
|
458 |
* @return The root object identifier. |
|
459 |
*/ |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
460 |
@Override |
2 | 461 |
public long[] getRootOid() { |
462 |
||
463 |
if( rootOid == null) { |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
464 |
Vector<Integer> list= new Vector<>(10); |
2 | 465 |
|
466 |
// Ask the tree to do the job ! |
|
467 |
// |
|
468 |
root.getRootOid(list); |
|
469 |
||
470 |
// Now format the result |
|
471 |
// |
|
472 |
rootOid= new long[list.size()]; |
|
473 |
int i=0; |
|
474 |
for(Enumeration<Integer> e= list.elements(); e.hasMoreElements(); ) { |
|
475 |
Integer val= e.nextElement(); |
|
476 |
rootOid[i++]= val.longValue(); |
|
477 |
} |
|
478 |
} |
|
479 |
return rootOid; |
|
480 |
||
481 |
} |
|
482 |
||
483 |
// -------------------------------------------------------------------- |
|
484 |
// PRIVATE METHODS |
|
485 |
//--------------------------------------------------------------------- |
|
486 |
||
487 |
/** |
|
488 |
* This method builds the temporary request-tree that will be used to |
|
489 |
* perform the SNMP request associated with the given vector of varbinds |
|
490 |
* `list'. |
|
491 |
* |
|
492 |
* @param req The SnmpMibRequest object holding the varbind list |
|
493 |
* concerning this MIB. |
|
494 |
* @param createflag Indicates whether the operation allow for creation |
|
495 |
* of new instances (ie: it is a SET). |
|
496 |
* @param atomic Indicates whether the operation is atomic or not. |
|
497 |
* @param type Request type (from SnmpDefinitions). |
|
498 |
* |
|
499 |
* @return The request-tree where the original varbind list has been |
|
500 |
* dispatched to the appropriate nodes. |
|
501 |
*/ |
|
502 |
private SnmpRequestTree getHandlers(SnmpMibRequest req, |
|
503 |
boolean createflag, boolean atomic, |
|
504 |
int type) |
|
505 |
throws SnmpStatusException { |
|
506 |
||
507 |
// Build an empty request tree |
|
508 |
SnmpRequestTree handlers = |
|
509 |
new SnmpRequestTree(req,createflag,type); |
|
510 |
||
511 |
int index=0; |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
512 |
SnmpVarBind var; |
2 | 513 |
final int ver= req.getVersion(); |
514 |
||
515 |
// For each varbind in the list finds its handling node. |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
516 |
for (Enumeration<SnmpVarBind> e= req.getElements(); e.hasMoreElements(); index++) { |
2 | 517 |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
518 |
var= e.nextElement(); |
2 | 519 |
|
520 |
try { |
|
521 |
// Find the handling node for this varbind. |
|
522 |
root.findHandlingNode(var,var.oid.longValue(false), |
|
523 |
0,handlers); |
|
524 |
} catch(SnmpStatusException x) { |
|
525 |
||
526 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
527 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, |
|
528 |
SnmpMib.class.getName(), |
|
529 |
"getHandlers", |
|
530 |
"Couldn't find a handling node for " + |
|
531 |
var.oid.toString()); |
|
532 |
} |
|
533 |
||
534 |
// If the operation is atomic (Check/Set) or the version |
|
535 |
// is V1 we must generate an exception. |
|
536 |
// |
|
537 |
if (ver == SnmpDefinitions.snmpVersionOne) { |
|
538 |
||
539 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
540 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, |
|
541 |
SnmpMib.class.getName(), |
|
542 |
"getHandlers", "\tV1: Throwing exception"); |
|
543 |
} |
|
544 |
||
545 |
// The index in the exception must correspond to the |
|
546 |
// SNMP index ... |
|
547 |
// |
|
548 |
final SnmpStatusException sse = |
|
549 |
new SnmpStatusException(x, index + 1); |
|
550 |
sse.initCause(x); |
|
551 |
throw sse; |
|
552 |
} else if ((type == SnmpDefinitions.pduWalkRequest) || |
|
553 |
(type == SnmpDefinitions.pduSetRequestPdu)) { |
|
554 |
final int status = |
|
555 |
SnmpRequestTree.mapSetException(x.getStatus(),ver); |
|
556 |
||
557 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
558 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, |
|
559 |
SnmpMib.class.getName(), |
|
560 |
"getHandlers", "\tSET: Throwing exception"); |
|
561 |
} |
|
562 |
||
563 |
final SnmpStatusException sse = |
|
564 |
new SnmpStatusException(status, index + 1); |
|
565 |
sse.initCause(x); |
|
566 |
throw sse; |
|
567 |
} else if (atomic) { |
|
568 |
||
569 |
// Should never come here... |
|
570 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
571 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, |
|
572 |
SnmpMib.class.getName(), |
|
573 |
"getHandlers", "\tATOMIC: Throwing exception"); |
|
574 |
} |
|
575 |
||
576 |
final SnmpStatusException sse = |
|
577 |
new SnmpStatusException(x, index + 1); |
|
578 |
sse.initCause(x); |
|
579 |
throw sse; |
|
580 |
} |
|
581 |
||
582 |
final int status = |
|
583 |
SnmpRequestTree.mapGetException(x.getStatus(),ver); |
|
584 |
||
585 |
if (status == SnmpStatusException.noSuchInstance) { |
|
586 |
||
587 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
588 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, |
|
589 |
SnmpMib.class.getName(), |
|
590 |
"getHandlers", |
|
591 |
"\tGET: Registering noSuchInstance"); |
|
592 |
} |
|
593 |
||
594 |
var.value= SnmpVarBind.noSuchInstance; |
|
595 |
||
596 |
} else if (status == SnmpStatusException.noSuchObject) { |
|
597 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
598 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, |
|
599 |
SnmpMib.class.getName(), |
|
600 |
"getHandlers", |
|
601 |
"\tGET: Registering noSuchObject"); |
|
602 |
} |
|
603 |
||
604 |
var.value= SnmpVarBind.noSuchObject; |
|
605 |
||
606 |
} else { |
|
607 |
||
608 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
609 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, |
|
610 |
SnmpMib.class.getName(), |
|
611 |
"getHandlers", |
|
612 |
"\tGET: Registering global error: " + status); |
|
613 |
} |
|
614 |
||
615 |
final SnmpStatusException sse = |
|
616 |
new SnmpStatusException(status, index + 1); |
|
617 |
sse.initCause(x); |
|
618 |
throw sse; |
|
619 |
} |
|
620 |
} |
|
621 |
} |
|
622 |
return handlers; |
|
623 |
} |
|
624 |
||
625 |
/** |
|
626 |
* This method builds the temporary request-tree that will be used to |
|
627 |
* perform the SNMP GET-NEXT request associated with the given vector |
|
628 |
* of varbinds `list'. |
|
629 |
* |
|
630 |
* @param req The SnmpMibRequest object holding the varbind list |
|
631 |
* concerning this MIB. |
|
632 |
* |
|
633 |
* @return The request-tree where the original varbind list has been |
|
634 |
* dispatched to the appropriate nodes, and where the original |
|
635 |
* OIDs have been replaced with the correct "next" OID. |
|
636 |
*/ |
|
637 |
private SnmpRequestTree getGetNextHandlers(SnmpMibRequest req) |
|
638 |
throws SnmpStatusException { |
|
639 |
||
640 |
// Creates an empty request tree, no entry creation is allowed (false) |
|
641 |
SnmpRequestTree handlers = new |
|
642 |
SnmpRequestTree(req,false,SnmpDefinitions.pduGetNextRequestPdu); |
|
643 |
||
644 |
// Sets the getNext flag: if version=V2, status exception are |
|
645 |
// transformed in endOfMibView |
|
646 |
handlers.setGetNextFlag(); |
|
647 |
||
648 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
649 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), |
|
650 |
"getGetNextHandlers", "Received MIB request : " + req); |
|
651 |
} |
|
652 |
AcmChecker checker = new AcmChecker(req); |
|
653 |
int index=0; |
|
654 |
SnmpVarBind var = null; |
|
655 |
final int ver= req.getVersion(); |
|
656 |
SnmpOid original = null; |
|
657 |
// For each varbind, finds the handling node. |
|
658 |
// This function has the side effect of transforming a GET-NEXT |
|
659 |
// request into a valid GET request, replacing the OIDs in the |
|
660 |
// original GET-NEXT request with the OID of the first leaf that |
|
661 |
// follows. |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
662 |
for (Enumeration<SnmpVarBind> e= req.getElements(); e.hasMoreElements(); index++) { |
2 | 663 |
|
14677
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
664 |
var = e.nextElement(); |
1607f4cfc506
8003476: Cleanup warnings in com.sun.jmx.snmp code
dfuchs
parents:
14342
diff
changeset
|
665 |
SnmpOid result; |
2 | 666 |
try { |
667 |
// Find the node handling the OID that follows the varbind |
|
668 |
// OID. `result' contains this next leaf OID. |
|
669 |
//ACM loop. |
|
670 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
671 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, |
|
672 |
SnmpMib.class.getName(), |
|
673 |
"getGetNextHandlers", " Next OID of : " + var.oid); |
|
674 |
} |
|
675 |
result = new SnmpOid(root.findNextHandlingNode |
|
676 |
(var,var.oid.longValue(false),0, |
|
677 |
0,handlers, checker)); |
|
678 |
||
679 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
680 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, |
|
681 |
SnmpMib.class.getName(), |
|
682 |
"getGetNextHandlers", " is : " + result); |
|
683 |
} |
|
684 |
// We replace the varbind original OID with the OID of the |
|
685 |
// leaf object we have to return. |
|
686 |
var.oid = result; |
|
687 |
} catch(SnmpStatusException x) { |
|
688 |
||
689 |
// if (isDebugOn()) |
|
690 |
// debug("getGetNextHandlers", |
|
691 |
// "Couldn't find a handling node for " |
|
692 |
// + var.oid.toString()); |
|
693 |
||
694 |
if (ver == SnmpDefinitions.snmpVersionOne) { |
|
695 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
696 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, |
|
697 |
SnmpMib.class.getName(), |
|
698 |
"getGetNextHandlers", |
|
699 |
"\tThrowing exception " + x.toString()); |
|
700 |
} |
|
701 |
// The index in the exception must correspond to the |
|
702 |
// SNMP index ... |
|
703 |
// |
|
704 |
throw new SnmpStatusException(x, index + 1); |
|
705 |
} |
|
706 |
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { |
|
707 |
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, |
|
708 |
SnmpMib.class.getName(), |
|
709 |
"getGetNextHandlers", |
|
710 |
"Exception : " + x.getStatus()); |
|
711 |
} |
|
712 |
||
713 |
var.setSnmpValue(SnmpVarBind.endOfMibView); |
|
714 |
} |
|
715 |
} |
|
716 |
return handlers; |
|
717 |
} |
|
718 |
||
719 |
// -------------------------------------------------------------------- |
|
720 |
// PROTECTED VARIABLES |
|
721 |
// -------------------------------------------------------------------- |
|
722 |
||
723 |
/** |
|
724 |
* The top element in the Mib tree. |
|
725 |
* @serial |
|
726 |
*/ |
|
727 |
protected SnmpMibOid root; |
|
728 |
||
729 |
||
730 |
// -------------------------------------------------------------------- |
|
731 |
// PRIVATE VARIABLES |
|
732 |
// -------------------------------------------------------------------- |
|
733 |
||
734 |
/** |
|
735 |
* The root object identifier of the MIB. |
|
736 |
*/ |
|
737 |
private transient long[] rootOid= null; |
|
738 |
} |