Produced by Araxis Merge on 9/25/2018 2:13:03 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\jmx\snmp\agent | SnmpMibTable.java | Mon Jan 22 14:46:50 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\jmx\snmp\agent | SnmpMibTable.java | Wed Sep 12 16:27:00 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 5120 |
Changed | 1 | 2 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /* | |
2 | * Copyrig ht (c) 199 7, 2013, O racle and/ or its aff iliates. A ll rights reserved. | |
3 | * DO NOT ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER. | |
4 | * | |
5 | * This co de is free software; you can r edistribut e it and/o r modify i t | |
6 | * under t he terms o f the GNU General Pu blic Licen se version 2 only, a s | |
7 | * publish ed by the Free Softw are Founda tion. Ora cle design ates this | |
8 | * particu lar file a s subject to the "Cl asspath" e xception a s provided | |
9 | * by Orac le in the LICENSE fi le that ac companied this code. | |
10 | * | |
11 | * This co de is dist ributed in the hope that it wi ll be usef ul, but WI THOUT | |
12 | * ANY WAR RANTY; wit hout even the implie d warranty of MERCHA NTABILITY or | |
13 | * FITNESS FOR A PAR TICULAR PU RPOSE. Se e the GNU General Pu blic Licen se | |
14 | * version 2 for mor e details (a copy is included in the LIC ENSE file that | |
15 | * accompa nied this code). | |
16 | * | |
17 | * You sho uld have r eceived a copy of th e GNU Gene ral Public License v ersion | |
18 | * 2 along with this work; if not, write to the Fr ee Softwar e Foundati on, | |
19 | * Inc., 5 1 Franklin St, Fifth Floor, Bo ston, MA 0 2110-1301 USA. | |
20 | * | |
21 | * Please contact Or acle, 500 Oracle Par kway, Redw ood Shores , CA 94065 USA | |
22 | * or visi t www.orac le.com if you need a dditional informatio n or have any | |
23 | * questio ns. | |
24 | */ | |
25 | ||
26 | package co m.sun.jmx. snmp.agent ; | |
27 | ||
28 | import jav a.io.Seria lizable; | |
29 | import jav a.util.Dat e; | |
30 | import jav a.util.Enu meration; | |
31 | import jav a.util.Has htable; | |
32 | import jav a.util.Vec tor; | |
33 | import jav a.util.log ging.Level ; | |
34 | ||
35 | import jav ax.managem ent.Listen erNotFound Exception; | |
36 | import jav ax.managem ent.MBeanN otificatio nInfo; | |
37 | import jav ax.managem ent.Notifi cation; | |
38 | import jav ax.managem ent.Notifi cationBroa dcaster; | |
39 | import jav ax.managem ent.Notifi cationFilt er; | |
40 | import jav ax.managem ent.Notifi cationList ener; | |
41 | import jav ax.managem ent.Object Name; | |
42 | ||
43 | import sta tic com.su n.jmx.defa ults.JmxPr operties.S NMP_ADAPTO R_LOGGER; | |
44 | import com .sun.jmx.s nmp.EnumRo wStatus; | |
45 | import com .sun.jmx.s nmp.SnmpIn t; | |
46 | import com .sun.jmx.s nmp.SnmpOi d; | |
47 | import com .sun.jmx.s nmp.SnmpSt atusExcept ion; | |
48 | import com .sun.jmx.s nmp.SnmpVa lue; | |
49 | import com .sun.jmx.s nmp.SnmpVa rBind; | |
50 | ||
51 | /** | |
52 | * This cl ass is the base clas s for SNMP table met adata. | |
53 | * <p> | |
54 | * Its res ponsibilit y is to ma nage a sor ted array of OID ind exes | |
55 | * accordi ng to the SNMP index ing scheme over the "real" tab le. | |
56 | * Each ob ject of th is class c an be boun d to an | |
57 | * {@link com.sun.jm x.snmp.age nt.SnmpTab leEntryFac tory} to w hich it wi ll | |
58 | * forward remote en try creati on request s, and inv oke callba cks | |
59 | * when an entry has been succ essfully a dded to / removed fr om | |
60 | * the OID index arr ay. | |
61 | * </p> | |
62 | * | |
63 | * <p> | |
64 | * For eac h table de fined in t he MIB, mi bgen will generate a specific | |
65 | * class c alled Tabl e<i>TableN ame</i> th at will im plement th e | |
66 | * SnmpTab leEntryFac tory inter face, and a correspo nding | |
67 | * <i>Tabl eName</i>M eta class that will extend thi s class. < br> | |
68 | * The Tab le<i>Table Name</i> c lass corre sponds to the MBean view of th e | |
69 | * table w hile the < i>TableNam e</i>Meta class corr esponds to the | |
70 | * MIB met adata view of the sa me table. | |
71 | * </p> | |
72 | * | |
73 | * <p> | |
74 | * Objects of this c lass are i nstantiate d by the g enerated | |
75 | * whole M IB class e xtending { @link com. sun.jmx.sn mp.agent.S nmpMib} | |
76 | * You sho uld never need to in stantiate this class directly. | |
77 | * </p> | |
78 | * | |
79 | * <p><b>T his API is a Sun Mic rosystems internal A PI and is subject | |
80 | * to chan ge without notice.</ b></p> | |
81 | * @see co m.sun.jmx. snmp.agent .SnmpMib | |
82 | * @see co m.sun.jmx. snmp.agent .SnmpMibEn try | |
83 | * @see co m.sun.jmx. snmp.agent .SnmpTable EntryFacto ry | |
84 | * @see co m.sun.jmx. snmp.agent .SnmpTable Support | |
85 | * | |
86 | */ | |
87 | ||
88 | public abs tract clas s SnmpMibT able exten ds SnmpMib Node | |
89 | implem ents Notif icationBro adcaster, Serializab le { | |
90 | ||
91 | /** | |
92 | * Cre ate a new <CODE>Snmp MibTable</ CODE> meta data node. | |
93 | * | |
94 | * <p> | |
95 | * @pa ram mib Th e SNMP MIB to which the metada ta will be linked. | |
96 | */ | |
97 | public SnmpMibTa ble(SnmpMi b mib) { | |
98 | th is.theMib= mib; | |
99 | se tCreationE nabled(fal se); | |
100 | } | |
101 | ||
102 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ---- | |
103 | // PUB LIC METHOD S | |
104 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ---- | |
105 | ||
106 | /** | |
107 | * Thi s method i s invoked when the c reation of a new ent ry is requ ested | |
108 | * by a remote S NMP manage r. | |
109 | * <br >By defaul t, remote entry crea tion is di sabled - a nd this me thod | |
110 | * wil l not be c alled. You can dynam ically swi tch the en try creati on | |
111 | * pol icy by cal ling <code >setCreati onEnabled( true)</cod e> and <co de> | |
112 | * set CreationEn abled(fals e)</code> on this ob ject. | |
113 | * <p> <b><i> | |
114 | * Thi s method i s called i nternally by the SNM P runtime and you | |
115 | * sho uld never need to ca ll it dire ctly. </b> </i>Howeve r you migh t want | |
116 | * to extend it in order t o implemen t your own specific applicatio n | |
117 | * beh aviour, sh ould the d efault beh aviour not be at you r convenie nce. | |
118 | * </p > | |
119 | * <p> | |
120 | * @pa ram req The SNMP subrequest requestin g this cre ation | |
121 | * @pa ram rowOid The OID indexing t he concept ual row (e ntry) for which | |
122 | * the crea tion was r equested. | |
123 | * @pa ram depth The positi on of the columnar o bject arc in the OID s | |
124 | * from the v arbind lis t. | |
125 | * | |
126 | * @ex ception Sn mpStatusEx ception if the entry cannot be created. | |
127 | */ | |
128 | public abstract void creat eNewEntry( SnmpMibSub Request re q, SnmpOid rowOid, | |
129 | int depth) | |
130 | th rows SnmpS tatusExcep tion; | |
131 | ||
132 | /** | |
133 | * Tel l whether the specif ic version of this m etadata ge nerated | |
134 | * by <code>mibg en</code> requires e ntries to be registe red with | |
135 | * the MBeanServ er. In thi s case an ObjectName will have to be | |
136 | * pas sed to add Entry() in order for the table to behave correctly | |
137 | * (ca se of the generic me tadata). | |
138 | * <p> | |
139 | * If that versi on of the metadata d oes not re quire entr y to be | |
140 | * reg istered, t hen passin g an Objec tName beco mes option al (null | |
141 | * can be passed instead). | |
142 | * | |
143 | * @re turn <code >true</cod e> if regi stration i s required by this | |
144 | * versi on of the metadata. | |
145 | */ | |
146 | public abstract boolean is Registrati onRequired (); | |
147 | ||
148 | /** | |
149 | * Tel l whether a new entr y should b e created when a SET operation | |
150 | * is received f or an entr y that doe s not exis t yet. | |
151 | * | |
152 | * @re turn true if a new e ntry must be created , false ot herwise.<b r> | |
153 | * [defa ult: retur ns <CODE>f alse</CODE >] | |
154 | **/ | |
155 | public boolean i sCreationE nabled() { | |
156 | re turn creat ionEnabled ; | |
157 | } | |
158 | ||
159 | /** | |
160 | * Thi s method l ets you dy namically switch the creation policy. | |
161 | * | |
162 | * <p> | |
163 | * @pa ram remote CreationFl ag Tells w hether rem ote entry creation m ust | |
164 | * be ena bled or di sabled. | |
165 | * <ul ><li> | |
166 | * <CO DE>setCrea tionEnable d(true)</C ODE> will enable rem ote entry | |
167 | * creation via SET o perations. </li> | |
168 | * <li > | |
169 | * <CO DE>setCrea tionEnable d(false)</ CODE> will disable r emote entr y | |
170 | * creation via SET o perations. </li> | |
171 | * <p> By defaul t remote e ntry creat ion via SE T operatio n is disab led. | |
172 | * </p > | |
173 | * </u l> | |
174 | **/ | |
175 | public void setC reationEna bled(boole an remoteC reationFla g) { | |
176 | cr eationEnab led = remo teCreation Flag; | |
177 | } | |
178 | ||
179 | /** | |
180 | * Ret urn <code> true</code > if the c onceptual row contai ns a colum nar | |
181 | * obj ect used t o control creation/d eletion of rows in t his table. | |
182 | * <p> | |
183 | * Thi s columna r object c an be eith er a varia ble with R owStatus | |
184 | * syn tax as def ined by RF C 2579, or a plain v ariable wh ose | |
185 | * sem antics is table spec ific. | |
186 | * <p> | |
187 | * By default, t his functi on returns <code>fal se</code>, and it is | |
188 | * ass umed that the table has no suc h control variable.< br> | |
189 | * Whe n <code>mi bgen</code > is used over SMIv2 MIBs, it will gener ate | |
190 | * an <code>hasR owStatus() </code> me thod retur ning <code >true</cod e> | |
191 | * for each tabl e containi ng an obje ct with Ro wStatus sy ntax. | |
192 | * <p> | |
193 | * Whe n this met hod return s <code>fa lse</code> the defau lt mechani sm | |
194 | * for remote en try creati on is used . | |
195 | * Oth erwise, cr eation/del etion is p erformed a s specifie d | |
196 | * by the contro l variable (see getR owAction() for more details). | |
197 | * <p> | |
198 | * Thi s method i s called i nternally when a SET request i nvolving | |
199 | * thi s table is processed . | |
200 | * <p> | |
201 | * If you need t o implemen t a contro l variable which do not use | |
202 | * the RowStatus conventio n as defin ed by RFC 2579, you should | |
203 | * sub class the generated table meta data class in order to redefin e | |
204 | * thi s method a nd make it returns < code>true< /code>.<br > | |
205 | * You will then have to r edefine th e isRowSta tus(), map RowStatus( ), | |
206 | * isR owReady(), and setRo wStatus() methods to suit your specific | |
207 | * imp lementatio n. | |
208 | * <p> | |
209 | * @re turn <li>< code>true< /code> if this table contains a control | |
210 | * varia ble (eg: a variable with RFC 2 579 RowSta tus syntax ), | |
211 | * </li> | |
212 | * <li>< code>false </code> if this tabl e does not contain | |
213 | * any c ontrol var iable.</li > | |
214 | * | |
215 | **/ | |
216 | public boolean h asRowStatu s() { | |
217 | re turn false ; | |
218 | } | |
219 | ||
220 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
221 | // | |
222 | // Imp lements th e method d efined in SnmpMibNod e. | |
223 | // | |
224 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
225 | /** | |
226 | * Gen eric handl ing of the <CODE>get </CODE> op eration. | |
227 | * <p> The defau lt impleme ntation of this meth od is to | |
228 | * <ul > | |
229 | * <li > check wh ether the entry exis ts, and if not regis ter an | |
230 | * exceptio n for each varbind i n the list . | |
231 | * <li > call the generated | |
232 | * <CODE>ge t(req,oid, depth+1)</ CODE> meth od. </li> | |
233 | * </u l> | |
234 | * <p> | |
235 | * <pr e> | |
236 | * pub lic void g et(SnmpMib SubRequest req, int depth) | |
237 | * throws Snm pStatusExc eption { | |
238 | * boolean isne w = req.i sNewEntry( ); | |
239 | * | |
240 | * // if the entry does not exist s, then re gisters an error for | |
241 | * // each va rbind invo lved (nb: this shoul d not happ en, since | |
242 | * // the err or should already ha ve been de tected ear lier) | |
243 | * // | |
244 | * if (isnew) { | |
245 | * SnmpVa rBind var = null ; | |
246 | * for (E numeration e= req.ge tElements( ); e.hasMo reElements ();) { | |
247 | * va r = (SnmpV arBind) e. nextElemen t(); | |
248 | * re q.register GetExcepti on(var,noS uchNameExc eption); | |
249 | * } | |
250 | * } | |
251 | * | |
252 | * final Snmp Oid oid = req.getEnt ryOid(); | |
253 | * get(req,oi d,depth+1) ; | |
254 | * } | |
255 | * </p re> | |
256 | * <p> You shoul d not need to overri de this me thod in an y cases, b ecause | |
257 | * it will event ually call | |
258 | * <CO DE>get(Snm pMibSubReq uest req, int depth) </CODE> on the gener ated | |
259 | * der ivative of <CODE>Snm pMibEntry< /CODE>. If you need to impleme nt | |
260 | * spe cific poli cies for m inimizing the access es made to some remo te | |
261 | * und erlying re sources, o r if you n eed to imp lement som e consiste ncy | |
262 | * che cks betwee n the diff erent valu es provide d in the v arbind lis t, | |
263 | * you should th en rather override | |
264 | * <CO DE>get(Snm pMibSubReq uest req, int depth) </CODE> on the gener ated | |
265 | * der ivative of <CODE>Snm pMibEntry< /CODE>. | |
266 | * <p> | |
267 | * | |
268 | */ | |
269 | @Overr ide | |
270 | public void get( SnmpMibSub Request re q, int dep th) | |
271 | th rows SnmpS tatusExcep tion { | |
272 | ||
273 | fi nal boolea n isnew = r eq.isNewEn try(); | |
274 | fi nal SnmpMi bSubReques t r = req; | |
275 | ||
276 | // if the en try does n ot exists, then regi sters an e rror for | |
277 | // each varb ind involv ed (nb: sh ould not h appen, the error | |
278 | // should ha ve been re gistered e arlier) | |
279 | if (isnew) { | |
280 | SnmpVarB ind var; | |
281 | for (Enu meration<S nmpVarBind > e= r.get Elements() ; e.hasMor eElements( );) { | |
282 | var = e.nextEl ement(); | |
283 | r.re gisterGetE xception(v ar,new Snm pStatusExc eption(Snm pStatusExc eption.noS uchInstanc e)); | |
284 | } | |
285 | } | |
286 | ||
287 | fi nal SnmpOi d oid = r.get EntryOid() ; | |
288 | ||
289 | // SnmpIndex index = buildSnm pIndex(oid .longValue (false), 0 ); | |
290 | // get(req,i ndex,depth +1); | |
291 | // | |
292 | ge t(req,oid, depth+1); | |
293 | } | |
294 | ||
295 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
296 | // | |
297 | // Imp lements th e method d efined in SnmpMibNod e. | |
298 | // | |
299 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
300 | /** | |
301 | * Gen eric handl ing of the <CODE>che ck</CODE> operation. | |
302 | * <p> The defau lt impleme ntation of this meth od is to | |
303 | * <ul > | |
304 | * <li > check wh ether a ne w entry mu st be crea ted, and i f remote | |
305 | * creation of entrie s is enabl ed, create it. </li> | |
306 | * <li > call the generated | |
307 | * <CODE>ch eck(req,oi d,depth+1) </CODE> me thod. </li > | |
308 | * </u l> | |
309 | * <p> | |
310 | * <pr e> | |
311 | * pub lic void c heck(SnmpM ibSubReque st req, in t depth) | |
312 | * throws Snm pStatusExc eption { | |
313 | * final Snmp Oid oi d = req .getEntryO id(); | |
314 | * final int ac tion = get RowAction( req,oid,de pth+1); | |
315 | * | |
316 | * beginRowAc tion(req,o id,depth+1 ,action); | |
317 | * check(req, oid,depth+ 1); | |
318 | * } | |
319 | * </p re> | |
320 | * <p> You shoul d not need to overri de this me thod in an y cases, b ecause | |
321 | * it will event ually call | |
322 | * <CO DE>check(S nmpMibSubR equest req , int dept h)</CODE> on the gen erated | |
323 | * der ivative of <CODE>Snm pMibEntry< /CODE>. If you need to impleme nt | |
324 | * spe cific poli cies for m inimizing the access es made to some remo te | |
325 | * und erlying re sources, o r if you n eed to imp lement som e consiste ncy | |
326 | * che cks betwee n the diff erent valu es provide d in the v arbind lis t, | |
327 | * you should th en rather override | |
328 | * <CO DE>check(S nmpMibSubR equest req , int dept h)</CODE> on the gen erated | |
329 | * der ivative of <CODE>Snm pMibEntry< /CODE>. | |
330 | * <p> | |
331 | * | |
332 | */ | |
333 | @Overr ide | |
334 | public void chec k(SnmpMibS ubRequest req, int d epth) | |
335 | th rows SnmpS tatusExcep tion { | |
336 | fi nal SnmpOi d oid = req.g etEntryOid (); | |
337 | fi nal int acti on = getRo wAction(re q,oid,dept h+1); | |
338 | ||
339 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INEST)) { | |
340 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINEST, SnmpMibTa ble.class. getName(), | |
341 | "check", " Calling be ginRowActi on"); | |
342 | } | |
343 | ||
344 | be ginRowActi on(req,oid ,depth+1,a ction); | |
345 | ||
346 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INEST)) { | |
347 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINEST, SnmpMibTa ble.class. getName(), | |
348 | "check", | |
349 | "Calling c heck for " + req.get Size() + " varbinds" ); | |
350 | } | |
351 | ||
352 | ch eck(req,oi d,depth+1) ; | |
353 | ||
354 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INEST)) { | |
355 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINEST, SnmpMibTa ble.class. getName(), | |
356 | "check", " check fini shed"); | |
357 | } | |
358 | } | |
359 | ||
360 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
361 | // | |
362 | // Imp lements th e method d efined in SnmpMibNod e. | |
363 | // | |
364 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
365 | /** | |
366 | * Gen eric handl ing of the <CODE>set </CODE> op eration. | |
367 | * <p> The defau lt impleme ntation of this meth od is to | |
368 | * cal l the gene rated | |
369 | * <CO DE>set(req ,oid,depth +1)</CODE> method. | |
370 | * <p> | |
371 | * <pr e> | |
372 | * pub lic void s et(SnmpMib SubRequest req, int depth) | |
373 | * throws Snm pStatusExc eption { | |
374 | * final Snmp Oid oid = req.getEnt ryOid(); | |
375 | * final int action = getRowActi on(req,oid ,depth+1); | |
376 | * | |
377 | * set(req,oi d,depth+1) ; | |
378 | * endRowActi on(req,oid ,depth+1,a ction); | |
379 | * } | |
380 | * </p re> | |
381 | * <p> You shoul d not need to overri de this me thod in an y cases, b ecause | |
382 | * it will event ually call | |
383 | * <CO DE>set(Snm pMibSubReq uest req, int depth) </CODE> on the gener ated | |
384 | * der ivative of <CODE>Snm pMibEntry< /CODE>. If you need to impleme nt | |
385 | * spe cific poli cies for m inimizing the access es made to some remo te | |
386 | * und erlying re sources, o r if you n eed to imp lement som e consiste ncy | |
387 | * che cks betwee n the diff erent valu es provide d in the v arbind lis t, | |
388 | * you should th en rather override | |
389 | * <CO DE>set(Snm pMibSubReq uest req, int depth) </CODE> on the gener ated | |
390 | * der ivative of <CODE>Snm pMibEntry< /CODE>. | |
391 | * <p> | |
392 | * | |
393 | */ | |
394 | @Overr ide | |
395 | public void set( SnmpMibSub Request re q, int dep th) | |
396 | th rows SnmpS tatusExcep tion { | |
397 | ||
398 | ||
399 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INEST)) { | |
400 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINEST, SnmpMibTa ble.class. getName(), | |
401 | "set", "En tering set "); | |
402 | } | |
403 | ||
404 | fi nal SnmpOi d oid = req.g etEntryOid (); | |
405 | fi nal int acti on = getRo wAction(re q,oid,dept h+1); | |
406 | ||
407 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INEST)) { | |
408 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINEST, SnmpMibTa ble.class. getName(), | |
409 | "set", "Ca lling set for " + re q.getSize( ) + " varb inds"); | |
410 | } | |
411 | ||
412 | se t(req,oid, depth+1); | |
413 | ||
414 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INEST)) { | |
415 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINEST, SnmpMibTa ble.class. getName(), | |
416 | "set", "Ca lling endR owAction") ; | |
417 | } | |
418 | ||
419 | en dRowAction (req,oid,d epth+1,act ion); | |
420 | ||
421 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INEST)) { | |
422 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINEST, SnmpMibTa ble.class. getName(), | |
423 | "set", "Ro wAction fi nished"); | |
424 | } | |
425 | ||
426 | } | |
427 | ||
428 | /** | |
429 | * Add a new ent ry in this <CODE>Snm pMibTable< /CODE>. | |
430 | * Als o triggers the addEn tryCB() ca llback of the | |
431 | * {@l ink com.su n.jmx.snmp .agent.Snm pTableEntr yFactory} interface | |
432 | * if this node is bound t o a factor y. | |
433 | * | |
434 | * Thi s method a ssumes tha t the give n entry wi ll not be registered . | |
435 | * If the entry is going t o be regis tered, or if ObjectN ame's are | |
436 | * req uired, the n | |
437 | * {@l ink com.su n.jmx.snmp .agent.Snm pMibTable# addEntry(S nmpOid, | |
438 | * Obj ectName, O bject)} sh ould be pr eferred. | |
439 | * <br > This fun ction is m ainly prov ided for b ackward co mpatibilit y. | |
440 | * | |
441 | * <p> | |
442 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
443 | * row to be added. | |
444 | * @pa ram entry The entry to add. | |
445 | * | |
446 | * @ex ception Sn mpStatusEx ception Th e entry co uldn't be added | |
447 | * at the posit ion identi fied by th e given | |
448 | * <c ode>rowOid </code>, o r this ver sion of th e metadata | |
449 | * re quires Obj ectName's. | |
450 | */ | |
451 | // pu blic void addEntry(S nmpIndex i ndex, Obje ct entry) | |
452 | publi c void add Entry(Snmp Oid rowOid , Object e ntry) | |
453 | th rows SnmpS tatusExcep tion { | |
454 | ||
455 | a ddEntry(ro wOid, null , entry); | |
456 | } | |
457 | ||
458 | /** | |
459 | * Add a new ent ry in this <CODE>Snm pMibTable< /CODE>. | |
460 | * Als o triggers the addEn tryCB() ca llback of the | |
461 | * {@l ink com.su n.jmx.snmp .agent.Snm pTableEntr yFactory} interface | |
462 | * if this node is bound t o a factor y. | |
463 | * | |
464 | * <p> | |
465 | * @pa ram oid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
466 | * row to be added. | |
467 | * | |
468 | * @pa ram name The Object Name with which this entry is registered . | |
469 | * This param eter can b e omitted if isRegis trationReq uired() | |
470 | * return fal se. | |
471 | * | |
472 | * @pa ram entry The entry to add. | |
473 | * | |
474 | * @ex ception Sn mpStatusEx ception Th e entry co uldn't be added | |
475 | * at the posit ion identi fied by th e given | |
476 | * <c ode>rowOid </code>, o r if this version of the metad ata | |
477 | * re quires Obj ectName's, and the g iven name is null. | |
478 | */ | |
479 | // pro tected syn chronized void addEn try(SnmpIn dex index, ObjectNam e name, | |
480 | // Object entry) | |
481 | public synchroni zed void a ddEntry(Sn mpOid oid, ObjectNam e name, | |
482 | Ob ject entry ) | |
483 | th rows SnmpS tatusExcep tion { | |
484 | ||
485 | if (isRegist rationRequ ired() == true && na me == null ) | |
486 | throw ne w SnmpStat usExceptio n(SnmpStat usExceptio n.badValue ); | |
487 | ||
488 | if (size == 0) { | |
489 | // inde xes.addEle ment(index ); | |
490 | // XX oi ds.addElem ent(oid); | |
491 | insertOi d(0,oid); | |
492 | if (entr ies != nul l) | |
493 | entr ies.addEle ment(entry ); | |
494 | if (entr ynames != null) | |
495 | entr ynames.add Element(na me); | |
496 | size++; | |
497 | ||
498 | // trigg ers callba cks on the entry fac tory | |
499 | // | |
500 | if (fact ory != nul l) { | |
501 | try { | |
502 | factory.ad dEntryCb(0 ,oid,name, entry,this ); | |
503 | } ca tch (SnmpS tatusExcep tion x) { | |
504 | removeOid( 0); | |
505 | if (entrie s != null) | |
506 | entrie s.removeEl ementAt(0) ; | |
507 | if (entryn ames != nu ll) | |
508 | entryn ames.remov eElementAt (0); | |
509 | throw x; | |
510 | } | |
511 | } | |
512 | ||
513 | // sends the notif ications | |
514 | // | |
515 | sendNoti fication(S nmpTableEn tryNotific ation.SNMP _ENTRY_ADD ED, | |
516 | ( new Date() ).getTime( ), entry, name); | |
517 | return; | |
518 | } | |
519 | ||
520 | // Get the i nsertion p osition .. . | |
521 | // | |
522 | in t pos= 0; | |
523 | // bug jaw.0 0356.B : u se oid rat her than i ndex to ge t the | |
524 | // insertion point. | |
525 | // | |
526 | po s= getInse rtionPoint (oid,true) ; | |
527 | if (pos == s ize) { | |
528 | // Add a new eleme nt in the vectors .. . | |
529 | // | |
530 | // inde xes.addEle ment(index ); | |
531 | // XX oi ds.addElem ent(oid); | |
532 | insertOi d(tablecou nt,oid); | |
533 | if (entr ies != nul l) | |
534 | entr ies.addEle ment(entry ); | |
535 | if (entr ynames != null) | |
536 | entr ynames.add Element(na me); | |
537 | size++; | |
538 | } else { | |
539 | // Inser t new elem ent ... | |
540 | // | |
541 | try { | |
542 | // indexe s.insertEl ementAt(in dex, pos); | |
543 | // X X oids.ins ertElement At(oid, po s); | |
544 | inse rtOid(pos, oid); | |
545 | if ( entries != null) | |
546 | entries.in sertElemen tAt(entry, pos); | |
547 | if ( entrynames != null) | |
548 | entrynames .insertEle mentAt(nam e,pos); | |
549 | size ++; | |
550 | } catch( ArrayIndex OutOfBound sException e) { | |
551 | } | |
552 | } | |
553 | ||
554 | // triggers callbacks on the ent ry factory | |
555 | // | |
556 | if (factory != null) { | |
557 | try { | |
558 | fact ory.addEnt ryCb(pos,o id,name,en try,this); | |
559 | } catch (SnmpStatu sException x) { | |
560 | remo veOid(pos) ; | |
561 | if ( entries != null) | |
562 | entries.re moveElemen tAt(pos); | |
563 | if ( entrynames != null) | |
564 | entrynames .removeEle mentAt(pos ); | |
565 | thro w x; | |
566 | } | |
567 | } | |
568 | ||
569 | // sends the notificat ions | |
570 | // | |
571 | se ndNotifica tion(SnmpT ableEntryN otificatio n.SNMP_ENT RY_ADDED, | |
572 | (new Date()).ge tTime(), e ntry, name ); | |
573 | } | |
574 | ||
575 | /** | |
576 | * Rem ove the sp ecified en try from t he table. | |
577 | * Als o triggers the remov eEntryCB() callback of the | |
578 | * {@l ink com.su n.jmx.snmp .agent.Snm pTableEntr yFactory} interface | |
579 | * if this node is bound t o a factor y. | |
580 | * | |
581 | * <p> | |
582 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
583 | * row to re move. | |
584 | * | |
585 | * @pa ram entry The entry to be remo ved. This parameter is not use d | |
586 | * internally , it is si mply passe d along to the | |
587 | * removeEntr yCB() call back. | |
588 | * | |
589 | * @ex ception Sn mpStatusEx ception if the speci fied entry couldn't | |
590 | * be removed ( if the giv en <code>r owOid</cod e> is not | |
591 | * va lid for in stance). | |
592 | */ | |
593 | public synchroni zed void r emoveEntry (SnmpOid r owOid, Obj ect entry) | |
594 | th rows SnmpS tatusExcep tion { | |
595 | in t pos = fi ndObject(r owOid); | |
596 | if (pos == - 1) | |
597 | return; | |
598 | re moveEntry( pos,entry) ; | |
599 | } | |
600 | ||
601 | /** | |
602 | * Rem ove the sp ecified en try from t he table. | |
603 | * Als o triggers the remov eEntryCB() callback of the | |
604 | * {@l ink com.su n.jmx.snmp .agent.Snm pTableEntr yFactory} interface | |
605 | * if this node is bound t o a factor y. | |
606 | * | |
607 | * <p> | |
608 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
609 | * row to re move. | |
610 | * | |
611 | * @ex ception Sn mpStatusEx ception if the speci fied entry couldn't | |
612 | * be removed ( if the giv en <code>r owOid</cod e> is not | |
613 | * va lid for in stance). | |
614 | */ | |
615 | public void remo veEntry(Sn mpOid rowO id) | |
616 | th rows SnmpS tatusExcep tion { | |
617 | in t pos = fi ndObject(r owOid); | |
618 | if (pos == - 1) | |
619 | return; | |
620 | re moveEntry( pos,null); | |
621 | } | |
622 | ||
623 | /** | |
624 | * Rem ove the sp ecified en try from t he table. | |
625 | * Als o triggers the remov eEntryCB() callback of the | |
626 | * {@l ink com.su n.jmx.snmp .agent.Snm pTableEntr yFactory} interface | |
627 | * if this node is bound t o a factor y. | |
628 | * | |
629 | * <p> | |
630 | * @pa ram pos Th e position of the en try in the table. | |
631 | * | |
632 | * @pa ram entry The entry to be remo ved. This parameter is not use d | |
633 | * internally , it is si mply passe d along to the | |
634 | * removeEntr yCB() call back. | |
635 | * | |
636 | * @ex ception Sn mpStatusEx ception if the speci fied entry couldn't | |
637 | * be removed. | |
638 | */ | |
639 | public synchroni zed void r emoveEntry (int pos, Object ent ry) | |
640 | th rows SnmpS tatusExcep tion { | |
641 | if (pos == - 1) | |
642 | return; | |
643 | if (pos >= s ize) retur n; | |
644 | ||
645 | Ob ject obj = entry; | |
646 | if (entries != null && entries.s ize() > po s) { | |
647 | obj = en tries.elem entAt(pos) ; | |
648 | entries. removeElem entAt(pos) ; | |
649 | } | |
650 | ||
651 | Ob jectName n ame = null ; | |
652 | if (entrynam es != null && entryn ames.size( ) > pos) { | |
653 | name = e ntrynames. elementAt( pos); | |
654 | entrynam es.removeE lementAt(p os); | |
655 | } | |
656 | ||
657 | fi nal SnmpOi d rowOid = tableoids [pos]; | |
658 | re moveOid(po s); | |
659 | si ze --; | |
660 | ||
661 | if (obj == n ull) obj = entry; | |
662 | ||
663 | if (factory != null) | |
664 | factory. removeEntr yCb(pos,ro wOid,name, obj,this); | |
665 | ||
666 | se ndNotifica tion(SnmpT ableEntryN otificatio n.SNMP_ENT RY_REMOVED , | |
667 | (new Date()).ge tTime(), o bj, name); | |
668 | } | |
669 | ||
670 | /** | |
671 | * Get the entry correspon ding to th e specifie d rowOid. | |
672 | * | |
673 | * <p> | |
674 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e | |
675 | * row to be retrie ved. | |
676 | * | |
677 | * @re turn The e ntry. | |
678 | * | |
679 | * @ex ception Sn mpStatusEx ception Th ere is no entry with the speci fied | |
680 | * <code>ro wOid</code > in the t able. | |
681 | */ | |
682 | public synchroni zed Object getEntry( SnmpOid ro wOid) | |
683 | th rows SnmpS tatusExcep tion { | |
684 | in t pos= fin dObject(ro wOid); | |
685 | if (pos == - 1) | |
686 | throw ne w SnmpStat usExceptio n(SnmpStat usExceptio n.noSuchIn stance); | |
687 | re turn entri es.element At(pos); | |
688 | } | |
689 | ||
690 | /** | |
691 | * Get the Objec tName of t he entry c orrespondi ng to the | |
692 | * spe cified row Oid. | |
693 | * The result of this meth od is only meaningfu l if | |
694 | * isR egistratio nRequired( ) yields t rue. | |
695 | * | |
696 | * <p> | |
697 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
698 | * row wh ose Object Name we wa nt to retr ieve. | |
699 | * | |
700 | * @re turn The o bject name of the en try. | |
701 | * | |
702 | * @ex ception Sn mpStatusEx ception Th ere is no entry with the speci fied | |
703 | * <code>ro wOid</code > in the t able. | |
704 | */ | |
705 | public synchroni zed Object Name getEn tryName(Sn mpOid rowO id) | |
706 | th rows SnmpS tatusExcep tion { | |
707 | in t pos = fi ndObject(r owOid); | |
708 | if (entrynam es == null ) return n ull; | |
709 | if (pos == - 1 || pos > = entrynam es.size()) | |
710 | throw ne w SnmpStat usExceptio n(SnmpStat usExceptio n.noSuchIn stance); | |
711 | re turn entry names.elem entAt(pos) ; | |
712 | } | |
713 | ||
714 | /** | |
715 | * Ret urn the en tries stor ed in this table <CO DE>SnmpMib Table</COD E>. | |
716 | * <p> | |
717 | * If the subcla ss generat ed by mibg en uses th e generic way to acc ess | |
718 | * the entries ( i.e. if it goes thro ugh the MB eanServer) then some of | |
719 | * the entries m ay be <cod e>null</co de>. It al l depends whether a non | |
720 | * <co de>null</c ode> entry was passe d to addEn try().<br> | |
721 | * Oth erwise, if it uses t he standar d way (acc ess the en try direct ly | |
722 | * thr ough their standard MBean inte rface) thi s array wi ll contain all | |
723 | * the entries. | |
724 | * <p> | |
725 | * @re turn The e ntries arr ay. | |
726 | */ | |
727 | public Object[] getBasicEn tries() { | |
728 | Ob ject[] arr ay= new Ob ject[size] ; | |
729 | en tries.copy Into(array ); | |
730 | re turn array ; | |
731 | } | |
732 | ||
733 | /** | |
734 | * Get the size of the tab le. | |
735 | * | |
736 | * @re turn The n umber of e ntries cur rently reg istered in this tabl e. | |
737 | */ | |
738 | public int getSi ze() { | |
739 | re turn size; | |
740 | } | |
741 | ||
742 | // EVE NT STUFF | |
743 | //---- -------- | |
744 | ||
745 | /** | |
746 | * Ena ble to add an SNMP e ntry liste ner to thi s | |
747 | * <CO DE>SnmpMib Table</COD E>. | |
748 | * | |
749 | * <p> | |
750 | * @pa ram listen er The lis tener obje ct which w ill handle the | |
751 | * notificati ons emitte d by the r egistered MBean. | |
752 | * | |
753 | * @pa ram filter The filte r object. If filter is null, n o filterin g | |
754 | * will be pe rformed be fore handl ing notifi cations. | |
755 | * | |
756 | * @pa ram handba ck The con text to be sent to t he listene r when a | |
757 | * notificati on is emit ted. | |
758 | * | |
759 | * @ex ception Il legalArgum entExcepti on Listene r paramete r is null. | |
760 | */ | |
761 | @Overr ide | |
762 | public synchroni zed void | |
763 | ad dNotificat ionListene r(Notifica tionListen er listene r, | |
764 | Notifica tionFilter filter, O bject hand back) { | |
765 | ||
766 | // Check lis tener | |
767 | // | |
768 | if (listener == null) { | |
769 | throw ne w java.lan g.IllegalA rgumentExc eption | |
770 | ("Li stener can 't be null ") ; | |
771 | } | |
772 | ||
773 | // looking f or listene r in handb ackTable | |
774 | // | |
775 | Ve ctor<Objec t> handbac kList = ha ndbackTabl e.get(list ener) ; | |
776 | Ve ctor<Notif icationFil ter> filte rList = fi lterTable. get(listen er) ; | |
777 | if ( handbac kList == n ull ) { | |
778 | handback List = new Vector<>( ) ; | |
779 | filterLi st = new V ector<>() ; | |
780 | handback Table.put( listener, handbackLi st) ; | |
781 | filterTa ble.put(li stener, fi lterList) ; | |
782 | } | |
783 | ||
784 | // Add the h andback an d the filt er | |
785 | // | |
786 | ha ndbackList .addElemen t(handback ) ; | |
787 | fi lterList.a ddElement( filter) ; | |
788 | } | |
789 | ||
790 | /** | |
791 | * Ena ble to rem ove an SNM P entry li stener fro m this | |
792 | * <CO DE>SnmpMib Table</COD E>. | |
793 | * | |
794 | * @pa ram listen er The lis tener obje ct which w ill handle the | |
795 | * notificati ons emitte d by the r egistered MBean. | |
796 | * This metho d will rem ove all th e informat ion relate d to this | |
797 | * listener. | |
798 | * | |
799 | * @ex ception Li stenerNotF oundExcept ion The li stener is not regist ered | |
800 | * in the MBe an. | |
801 | */ | |
802 | @Overr ide | |
803 | public synchroni zed void | |
804 | re moveNotifi cationList ener(Notif icationLis tener list ener) | |
805 | th rows Liste nerNotFoun dException { | |
806 | ||
807 | // looking f or listene r in handb ackTable | |
808 | // | |
809 | ja va.util.Ve ctor<?> ha ndbackList = handbac kTable.get (listener) ; | |
810 | if ( handbac kList == n ull ) { | |
811 | throw ne w Listener NotFoundEx ception("l istener"); | |
812 | } | |
813 | ||
814 | // If handba ck is null , remove t he listene r entry | |
815 | // | |
816 | ha ndbackTabl e.remove(l istener) ; | |
817 | fi lterTable. remove(lis tener) ; | |
818 | } | |
819 | ||
820 | /** | |
821 | * Ret urn a <COD E>Notifica tionInfo</ CODE> obje ct contain ing the | |
822 | * not ification class and the notifi cation typ e sent by the | |
823 | * <CO DE>SnmpMib Table</COD E>. | |
824 | */ | |
825 | @Overr ide | |
826 | public MBeanNoti ficationIn fo[] getNo tification Info() { | |
827 | ||
828 | St ring[] typ es = {Snmp TableEntry Notificati on.SNMP_EN TRY_ADDED, | |
829 | Snmp TableEntry Notificati on.SNMP_EN TRY_REMOVE D}; | |
830 | ||
831 | MB eanNotific ationInfo[ ] notifsIn fo = { | |
832 | new MBea nNotificat ionInfo | |
833 | (types, "com.sun.j mx.snmp.ag ent.SnmpTa bleEntryNo tification ", | |
834 | "Notifi cations se nt by the SnmpMibTab le") | |
835 | }; | |
836 | ||
837 | re turn notif sInfo; | |
838 | } | |
839 | ||
840 | ||
841 | /** | |
842 | * Reg ister the factory th rough whic h table en tries shou ld | |
843 | * be created wh en remote entry crea tion is en abled. | |
844 | * | |
845 | * <p> | |
846 | * @pa ram factor y The | |
847 | * {@link com.sun.j mx.snmp.ag ent.SnmpTa bleEntryFa ctory} thr ough | |
848 | * which entries wi ll be crea ted when a remote SN MP manager | |
849 | * reques t the crea tion of a new entry via an SNM P SET requ est. | |
850 | */ | |
851 | public void regi sterEntryF actory(Snm pTableEntr yFactory f actory) { | |
852 | th is.factory = factory ; | |
853 | } | |
854 | ||
855 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------- | |
856 | // PRO TECTED MET HODS - Row Status | |
857 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------- | |
858 | ||
859 | /** | |
860 | * Ret urn true i f the colu mnar objec t identifi ed by <cod e>var</cod e> | |
861 | * is used to co ntrol the addition/d eletion of rows in t his table. | |
862 | * | |
863 | * <p> | |
864 | * By default, t his method assumes t hat there is no cont rol variab le | |
865 | * and always re turn <code >false</co de> | |
866 | * <p> | |
867 | * If this table was defin ed using S MIv2, and if it cont ains a | |
868 | * con trol varia ble with R owStatus s yntax, <co de>mibgen< /code> | |
869 | * wil l generate a non def ault imple mentation for this m ethod | |
870 | * tha t will ide ntify the RowStatus control va riable. | |
871 | * <p> | |
872 | * You will have to redefi ne this me thod if yo u need to implement | |
873 | * con trol varia bles that do not con form to RF C 2579 Row Status | |
874 | * TEX TUAL-CONVE NTION. | |
875 | * <p> | |
876 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
877 | * row invol ved in the operation . | |
878 | * | |
879 | * @pa ram var Th e OID arc identifyin g the invo lved colum nar object . | |
880 | * | |
881 | * @pa ram userDa ta A conte xtual obje ct contain ing user-d ata. | |
882 | * This o bject is a llocated t hrough the <code> | |
883 | * {@link com.sun.j mx.snmp.ag ent.SnmpUs erDataFact ory}</code > | |
884 | * for ea ch incomin g SNMP req uest. | |
885 | * | |
886 | **/ | |
887 | protec ted boolea n isRowSta tus(SnmpOi d rowOid, long var, | |
888 | Obje ct userDa ta) { | |
889 | re turn false ; | |
890 | } | |
891 | ||
892 | ||
893 | /** | |
894 | * Ret urn the Ro wStatus co de value s pecified i n this req uest. | |
895 | * <p> | |
896 | * The RowStatus code valu e should b e one of t he values defined | |
897 | * by {@link com .sun.jmx.s nmp.EnumRo wStatus}. These code s correspo nd | |
898 | * to RowStatus codes as d efined in RFC 2579, plus the < i>unspecif ied</i> | |
899 | * val ue which i s SNMP Run time speci fic. | |
900 | * <p> | |
901 | * | |
902 | * @pa ram req The sub-r equest tha t must be handled by this node . | |
903 | * | |
904 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
905 | * row invol ved in the operation . | |
906 | * | |
907 | * @pa ram depth The depth reached i n the OID tree. | |
908 | * | |
909 | * @re turn The R owStatus c ode specif ied in thi s request, if any: | |
910 | * <ul > | |
911 | * <li >If the sp ecified ro w does not exist and this tabl e do | |
912 | * not use a ny variabl e to contr ol creatio n/deletion of | |
913 | * rows, the n default creation m echanism i s assumed and | |
914 | * <i>create AndGo</i> is returne d</li> | |
915 | * <li >Otherwise , if the r ow exists and this t able do no t use any | |
916 | * variable to control creation/ deletion o f rows, | |
917 | * <i>unspec ified</i> is returne d.</li> | |
918 | * <li >Otherwise , if the r equest doe s not cont ain the co ntrol vari able, | |
919 | * <i>unspec ified</i> is returne d.</li> | |
920 | * <li >Otherwise , mapRowSt atus() is called to extract th e RowStatu s | |
921 | * code from the SnmpV arBind tha t contains the contr ol variabl e.</li> | |
922 | * </u l> | |
923 | * | |
924 | * @ex ception Sn mpStatusEx ception if the value of the co ntrol vari able | |
925 | * co uld not be mapped to a RowStat us code. | |
926 | * | |
927 | * @se e com.sun. jmx.snmp.E numRowStat us | |
928 | **/ | |
929 | protec ted int ge tRowAction (SnmpMibSu bRequest r eq, SnmpOi d rowOid, | |
930 | int depth ) | |
931 | th rows SnmpS tatusExcep tion { | |
932 | fi nal boolea n isne w = req.i sNewEntry( ); | |
933 | fi nal SnmpVa rBind vb = req.getRo wStatusVar Bind(); | |
934 | if (vb == nu ll) { | |
935 | if (isne w && ! has RowStatus( )) | |
936 | retu rn EnumRow Status.cre ateAndGo; | |
937 | else ret urn EnumRo wStatus.un specified; | |
938 | } | |
939 | ||
940 | tr y { | |
941 | return m apRowStatu s(rowOid, vb, req.ge tUserData( )); | |
942 | } catch( Snm pStatusExc eption x) { | |
943 | checkRow StatusFail (req, x.ge tStatus()) ; | |
944 | } | |
945 | re turn EnumR owStatus.u nspecified ; | |
946 | } | |
947 | ||
948 | /** | |
949 | * Map the value of the <c ode>vbstat us</code> varbind to the | |
950 | * cor responding RowStatus code defi ned in | |
951 | * {@l ink com.su n.jmx.snmp .EnumRowSt atus}. | |
952 | * The se codes c orrespond to RowStat us codes a s defined in RFC 257 9, | |
953 | * plu s the <i>u nspecified </i> value which is SNMP Runti me specifi c. | |
954 | * <p> | |
955 | * By default, t his method assumes t hat the co ntrol vari able is | |
956 | * an Integer, a nd it simp ly returns its value without f urther | |
957 | * ana lysis. | |
958 | * <p> | |
959 | * If this table was defin ed using S MIv2, and if it cont ains a | |
960 | * con trol varia ble with R owStatus s yntax, <co de>mibgen< /code> | |
961 | * wil l generate a non def ault imple mentation for this m ethod. | |
962 | * <p> | |
963 | * You will have to redefi ne this me thod if yo u need to implement | |
964 | * con trol varia bles that do not con form to RF C 2579 Row Status | |
965 | * TEX TUAL-CONVE NTION. | |
966 | * | |
967 | * <p> | |
968 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
969 | * row invol ved in the operation . | |
970 | * | |
971 | * @pa ram vbstat us The Snm pVarBind c ontaining the value of the con trol | |
972 | * var iable, as identified by the is RowStatus( ) method. | |
973 | * | |
974 | * @pa ram userDa ta A conte xtual obje ct contain ing user-d ata. | |
975 | * This o bject is a llocated t hrough the <code> | |
976 | * {@link com.sun.j mx.snmp.ag ent.SnmpUs erDataFact ory}</code > | |
977 | * for ea ch incomin g SNMP req uest. | |
978 | * | |
979 | * @re turn The R owStatus c ode mapped from the value cont ained | |
980 | * in <code> vbstatus</ code>. | |
981 | * | |
982 | * @ex ception Sn mpStatusEx ception if the value of the co ntrol vari able | |
983 | * co uld not be mapped to a RowStat us code. | |
984 | * | |
985 | * @se e com.sun. jmx.snmp.E numRowStat us | |
986 | **/ | |
987 | protec ted int ma pRowStatus (SnmpOid r owOid, Snm pVarBind v bstatus, | |
988 | Object us erData) | |
989 | th rows SnmpS tatusExcep tion { | |
990 | fi nal SnmpVa lue rsvalu e = vbstat us.value; | |
991 | ||
992 | if (rsvalue instanceof SnmpInt) | |
993 | return ( (SnmpInt)r svalue).in tValue(); | |
994 | el se | |
995 | throw ne w SnmpStat usExceptio n( | |
996 | SnmpSta tusExcepti on.snmpRsp Inconsiste ntValue); | |
997 | } | |
998 | ||
999 | /** | |
1000 | * Set the contr ol variabl e to the s pecified < code>newSt atus</code > | |
1001 | * val ue. | |
1002 | * | |
1003 | * <p> | |
1004 | * Thi s method m aps the gi ven <code> newStatus< /code> to the approp riate | |
1005 | * val ue for the control v ariable, t hen sets t he control variable in | |
1006 | * the entry ide ntified by <code>row Oid</code> . It retur ns the new | |
1007 | * val ue of the control va riable. | |
1008 | * <p> | |
1009 | * By default, i t is assum ed that th ere is no control va riable so this | |
1010 | * met hod does n othing and simply re turns <cod e>null</co de>. | |
1011 | * <p> | |
1012 | * If this table was defin ed using S MIv2, and if it cont ains a | |
1013 | * con trol varia ble with R owStatus s yntax, <co de>mibgen< /code> | |
1014 | * wil l generate a non def ault imple mentation for this m ethod. | |
1015 | * <p> | |
1016 | * You will have to redefi ne this me thod if yo u need to implement | |
1017 | * con trol varia bles that do not con form to RF C 2579 Row Status | |
1018 | * TEX TUAL-CONVE NTION. | |
1019 | * | |
1020 | * <p> | |
1021 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
1022 | * row invol ved in the operation . | |
1023 | * | |
1024 | * @pa ram newSta tus The ne w status f or the row : one of t he | |
1025 | * RowSta tus code d efined in | |
1026 | * {@link com.sun.j mx.snmp.En umRowStatu s}. These codes | |
1027 | * corres pond to Ro wStatus co des as def ined in RF C 2579, | |
1028 | * plus t he <i>unsp ecified</i > value wh ich is SNM P Runtime specific. | |
1029 | * | |
1030 | * @pa ram userDa ta A conte xtual obje ct contain ing user-d ata. | |
1031 | * This o bject is a llocated t hrough the <code> | |
1032 | * {@link com.sun.j mx.snmp.ag ent.SnmpUs erDataFact ory}</code > | |
1033 | * for ea ch incomin g SNMP req uest. | |
1034 | * | |
1035 | * @re turn The n ew value o f the cont rol variab le (usuall y | |
1036 | * <code >new SnmpI nt(newStat us)</code> ) or <code >null</cod e> | |
1037 | * if th e table do not have any contro l variable . | |
1038 | * | |
1039 | * @ex ception Sn mpStatusEx ception If the given <code>new Status</co de> | |
1040 | * co uld not be set on th e specifie d entry, o r if the | |
1041 | * gi ven <code> newStatus< /code> is not valid. | |
1042 | * | |
1043 | * @se e com.sun. jmx.snmp.E numRowStat us | |
1044 | **/ | |
1045 | protec ted SnmpVa lue setRow Status(Snm pOid rowOi d, int new Status, | |
1046 | Obj ect userDa ta) | |
1047 | th rows SnmpS tatusExcep tion { | |
1048 | re turn null; | |
1049 | } | |
1050 | ||
1051 | /** | |
1052 | * Tel l whether the specif ied row is ready and can be pu t in the | |
1053 | * <i> notInServi ce</i> sta te. | |
1054 | * <p> | |
1055 | * Thi s method i s called o nly once, after all the varbin d have bee n | |
1056 | * set on a new entry for which <i>c reateAndWa it</i> was specified . | |
1057 | * <p> | |
1058 | * If the entry is not yet ready, th is method should ret urn false. | |
1059 | * It will then be the res ponsibilit y of the e ntry to sw itch its | |
1060 | * own state to <i>notInSe rvice</i> when it be comes read y. | |
1061 | * No further ca ll to <cod e>isRowRea dy()</code > will be made. | |
1062 | * <p> | |
1063 | * By default, t his method always re turn true. <br> | |
1064 | * <co de>mibgen< /code> wil l not gene rate any s pecific im plementati on | |
1065 | * for this meth od - meani ng that by default, a row crea ted using | |
1066 | * <i> createAndW ait</i> wi ll always be placed in <i>notI nService</ i> | |
1067 | * sta te at the end of the request. | |
1068 | * <p> | |
1069 | * If this table was defin ed using S MIv2, and if it cont ains a | |
1070 | * con trol varia ble with R owStatus s yntax, <co de>mibgen< /code> | |
1071 | * wil l generate an implem entation f or this me thod that will | |
1072 | * del egate the work to th e metadata class mod elling the conceptua l | |
1073 | * row , so that you can ov erride the default b ehaviour b y subclass ing | |
1074 | * tha t metadata class. | |
1075 | * <p> | |
1076 | * You will have to redefi ne this me thod if th is default mechanism | |
1077 | * doe s not suit your need s. | |
1078 | * | |
1079 | * <p> | |
1080 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
1081 | * row invol ved in the operation . | |
1082 | * | |
1083 | * @pa ram userDa ta A conte xtual obje ct contain ing user-d ata. | |
1084 | * This o bject is a llocated t hrough the <code> | |
1085 | * {@link com.sun.j mx.snmp.ag ent.SnmpUs erDataFact ory}</code > | |
1086 | * for ea ch incomin g SNMP req uest. | |
1087 | * | |
1088 | * @re turn <code >true</cod e> if the row can be placed in | |
1089 | * <i>no tInService </i> state . | |
1090 | * | |
1091 | * @ex ception Sn mpStatusEx ception An error occ urred whil e trying | |
1092 | * to retrieve the row st atus, and the operat ion should | |
1093 | * be aborted. | |
1094 | * | |
1095 | * @se e com.sun. jmx.snmp.E numRowStat us | |
1096 | **/ | |
1097 | protec ted boolea n isRowRea dy(SnmpOid rowOid, O bject user Data) | |
1098 | th rows SnmpS tatusExcep tion { | |
1099 | re turn true; | |
1100 | } | |
1101 | ||
1102 | /** | |
1103 | * Che ck whether the contr ol variabl e of the g iven row c an be | |
1104 | * swi tched to t he new spe cified <co de>newStat us</code>. | |
1105 | * <p> | |
1106 | * Thi s method i s called d uring the <i>check</ i> phase o f a SET | |
1107 | * req uest when the contro l variable specifies <i>active </i> or | |
1108 | * <i> notInServi ce</i>. | |
1109 | * <p> | |
1110 | * By default it is assume d that not hing preve nts puttin g the | |
1111 | * row in the re quested st ate, and t his method does noth ing. | |
1112 | * It is simply provided a s a hook s o that spe cific chec ks can | |
1113 | * be implemente d. | |
1114 | * <p> | |
1115 | * Not e that if the actual row delet ion fails afterward, the | |
1116 | * ato micity of the reques t is no lo nger guara nteed. | |
1117 | * | |
1118 | * <p> | |
1119 | * @pa ram req The sub-r equest tha t must be handled by this node . | |
1120 | * | |
1121 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
1122 | * row invol ved in the operation . | |
1123 | * | |
1124 | * @pa ram depth The depth reached i n the OID tree. | |
1125 | * | |
1126 | * @pa ram newSta tus The ne w status f or the row : one of t he | |
1127 | * RowSta tus code d efined in | |
1128 | * {@link com.sun.j mx.snmp.En umRowStatu s}. These codes | |
1129 | * corres pond to Ro wStatus co des as def ined in RF C 2579, | |
1130 | * plus t he <i>unsp ecified</i > value wh ich is SNM P Runtime specific. | |
1131 | * | |
1132 | * @ex ception Sn mpStatusEx ception if switching to this n ew state | |
1133 | * wo uld fail. | |
1134 | * | |
1135 | **/ | |
1136 | protec ted void c heckRowSta tusChange( SnmpMibSub Request re q, | |
1137 | SnmpOid ro wOid, int depth, | |
1138 | int newSta tus) | |
1139 | th rows SnmpS tatusExcep tion { | |
1140 | ||
1141 | } | |
1142 | ||
1143 | /** | |
1144 | * Che ck whether the speci fied row c an be remo ved from t he table. | |
1145 | * <p> | |
1146 | * Thi s method i s called d uring the <i>check</ i> phase o f a SET | |
1147 | * req uest when the contro l variable specifies <i>destro y</i> | |
1148 | * <p> | |
1149 | * By default it is assume d that not hing preve nts row de letion | |
1150 | * and this meth od does no thing. It is simply provided a s a hook | |
1151 | * so that speci fic checks can be im plemented. | |
1152 | * <p> | |
1153 | * Not e that if the actual row delet ion fails afterward, the | |
1154 | * ato micity of the reques t is no lo nger guara nteed. | |
1155 | * | |
1156 | * <p> | |
1157 | * @pa ram req The sub-r equest tha t must be handled by this node . | |
1158 | * | |
1159 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
1160 | * row invol ved in the operation . | |
1161 | * | |
1162 | * @pa ram depth The depth reached i n the OID tree. | |
1163 | * | |
1164 | * @ex ception Sn mpStatusEx ception if the row d eletion mu st be | |
1165 | * re jected. | |
1166 | **/ | |
1167 | protec ted void c heckRemove TableRow(S nmpMibSubR equest req , SnmpOid rowOid, | |
1168 | i nt depth) | |
1169 | th rows SnmpS tatusExcep tion { | |
1170 | ||
1171 | } | |
1172 | ||
1173 | /** | |
1174 | * Rem ove a tabl e row upon a remote manager re quest. | |
1175 | * | |
1176 | * Thi s method i s called i nternally when <code >getRowAct ion()</cod e> | |
1177 | * yie lds <i>des troy</i> - i.e.: it is only ca lled when a remote | |
1178 | * man ager reque sts the re moval of a table row .<br> | |
1179 | * You should ne ver need t o call thi s function directly. | |
1180 | * <p> | |
1181 | * By default, t his method simply ca lls <code> removeEntr y(rowOid) | |
1182 | * </c ode>. | |
1183 | * <p> | |
1184 | * You can redef ine this m ethod if y ou need to implement some | |
1185 | * spe cific beha viour when a remote row deleti on is invo ked. | |
1186 | * <p> | |
1187 | * Not e that spe cific chec ks should not be imp lemented i n this | |
1188 | * met hod, but r ather in < code>check RemoveTabl eRow()</co de>. | |
1189 | * If <code>chec kRemoveTab leRow()</c ode> succe eds and th is method | |
1190 | * fai ls afterwa rd, the at omicity of the origi nal SET re quest can no | |
1191 | * lon ger be gua ranteed. | |
1192 | * <p> | |
1193 | * | |
1194 | * @pa ram req The sub-r equest tha t must be handled by this node . | |
1195 | * | |
1196 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
1197 | * row invol ved in the operation . | |
1198 | * | |
1199 | * @pa ram depth The depth reached i n the OID tree. | |
1200 | * | |
1201 | * @ex ception Sn mpStatusEx ception if the actua l row dele tion fails . | |
1202 | * Th is should not happen since it would brea k the | |
1203 | * at omicity of the SET r equest. Sp ecific che cks should | |
1204 | * be implement ed in <cod e>checkRem oveTableRo w()</code> | |
1205 | * if needed. I f the entr y does not exists, n o exceptio n | |
1206 | * is generated and the m ethod simp ly returns . | |
1207 | * | |
1208 | **/ | |
1209 | protec ted void r emoveTable Row(SnmpMi bSubReques t req, Snm pOid rowOi d, | |
1210 | int de pth) | |
1211 | th rows SnmpS tatusExcep tion { | |
1212 | ||
1213 | re moveEntry( rowOid); | |
1214 | } | |
1215 | ||
1216 | /** | |
1217 | * Thi s method t akes care of initial RowStatus handling during the | |
1218 | * che ck() phase of a SET request. | |
1219 | * | |
1220 | * In particular it will: | |
1221 | * <ul ><li>check that the given <cod e>rowActio n</code> r eturned by | |
1222 | * <code >getRowAct ion()</cod e> is vali d.</li> | |
1223 | * <li >Then depe nding on t he <code>r owAction</ code> spec ified it w ill: | |
1224 | * <ul><li>e ither call <code>cre ateNewEntr y()</code> (<code> | |
1225 | * rowAc tion = <i> createAndG o</i> or < i>createAn dWait</i> | |
1226 | * </cod e>),</li> | |
1227 | * <li>or ca ll <code>c heckRemove TableRow() </code> (< code> | |
1228 | * rowAc tion = <i> destroy</i ></code>), </li> | |
1229 | * <li>or ca ll <code>c heckRowSta tusChange( )</code> ( <code> | |
1230 | * rowAc tion = <i> active</i> or <i>not InService< /i></code> ),</li> | |
1231 | * <li>or ge nerate a S nmpStatusE xception i f the pass ed <code> | |
1232 | * rowAc tion</code > is not c orrect.</l i> | |
1233 | * </u l></li></u l> | |
1234 | * <p> | |
1235 | * In principle, you shoul d not need to redefi ne this me thod. | |
1236 | * <p> | |
1237 | * <co de>beginRo wAction()< /code> is called dur ing the ch eck phase | |
1238 | * of a SET requ est, befor e actual c hecking on the varbi nd list | |
1239 | * is performed. | |
1240 | * | |
1241 | * <p> | |
1242 | * @pa ram req The sub-r equest tha t must be handled by this node . | |
1243 | * | |
1244 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
1245 | * row invol ved in the operation . | |
1246 | * | |
1247 | * @pa ram depth The depth reached i n the OID tree. | |
1248 | * | |
1249 | * @pa ram rowAct ion The re quested ac tion as re turned by <code> | |
1250 | * getRow Action()</ code>: one of the Ro wStatus co des define d in | |
1251 | * {@link com.sun.j mx.snmp.En umRowStatu s}. These codes | |
1252 | * corres pond to Ro wStatus co des as def ined in RF C 2579, | |
1253 | * plus t he <i>unsp ecified</i > value wh ich is SNM P Runtime specific. | |
1254 | * | |
1255 | * @ex ception Sn mpStatusEx ception if the speci fied <code >rowAction </code> | |
1256 | * is not valid or cannot be execut ed. | |
1257 | * Th is should not happen since it would brea k the | |
1258 | * at omicity of the SET r equest. Sp ecific che cks should | |
1259 | * be implement ed in <cod e>beginRow Action()</ code> if n eeded. | |
1260 | * | |
1261 | * @se e com.sun. jmx.snmp.E numRowStat us | |
1262 | **/ | |
1263 | protec ted synchr onized voi d beginRow Action(Snm pMibSubReq uest req, | |
1264 | SnmpOid ro wOid, int depth, int rowAction ) | |
1265 | th rows SnmpS tatusExcep tion { | |
1266 | fi nal boolea n isne w = req.i sNewEntry( ); | |
1267 | fi nal SnmpOi d oid = rowOi d; | |
1268 | fi nal int acti on = rowAc tion; | |
1269 | ||
1270 | sw itch (acti on) { | |
1271 | ca se EnumRow Status.uns pecified: | |
1272 | if (isne w) { | |
1273 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
1274 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, | |
1275 | Sn mpMibTable .class.get Name(), | |
1276 | "b eginRowAct ion", "Fai led to cre ate row[" + | |
1277 | ro wOid + "] : RowStatu s = unspec ified"); | |
1278 | } | |
1279 | chec kRowStatus Fail(req,S nmpStatusE xception.s nmpRspNoAc cess); | |
1280 | } | |
1281 | break; | |
1282 | ca se EnumRow Status.cre ateAndGo: | |
1283 | ca se EnumRow Status.cre ateAndWait : | |
1284 | if (isne w) { | |
1285 | if ( isCreation Enabled()) { | |
1286 | if (SNMP_A DAPTOR_LOG GER.isLogg able(Level .FINEST)) { | |
1287 | SNMP_A DAPTOR_LOG GER.logp(L evel.FINES T, | |
1288 | SnmpMibT able.class .getName() , | |
1289 | "beginRo wAction", "Creating row[" + ro wOid + | |
1290 | "] : Row Status = c reateAndGo | createA ndWait"); | |
1291 | } | |
1292 | createNewE ntry(req,o id,depth); | |
1293 | } el se { | |
1294 | if (SNMP_A DAPTOR_LOG GER.isLogg able(Level .FINEST)) { | |
1295 | SNMP_A DAPTOR_LOG GER.logp(L evel.FINES T, | |
1296 | SnmpMibT able.class .getName() , | |
1297 | "beginRo wAction", "Can't cre ate row[" + rowOid + | |
1298 | "] : Row Status = c reateAndGo | createA ndWait " + | |
1299 | "but cre ation is d isabled"); | |
1300 | } | |
1301 | checkRowSt atusFail(r eq, | |
1302 | SnmpSta tusExcepti on.snmpRsp NoAccess); | |
1303 | } | |
1304 | } else { | |
1305 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
1306 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, | |
1307 | Sn mpMibTable .class.get Name(), | |
1308 | "b eginRowAct ion", "Can 't create row[" + ro wOid + | |
1309 | "] : RowStat us = creat eAndGo | c reateAndWa it " + | |
1310 | "b ut row alr eady exist s"); | |
1311 | } | |
1312 | chec kRowStatus Fail(req, | |
1313 | SnmpSta tusExcepti on.snmpRsp Inconsiste ntValue); | |
1314 | } | |
1315 | break; | |
1316 | ca se EnumRow Status.des troy: | |
1317 | if (isne w) { | |
1318 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
1319 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, | |
1320 | Sn mpMibTable .class.get Name(), | |
1321 | "b eginRowAct ion", | |
1322 | "W arning: ca n't destro y row[" + rowOid + | |
1323 | "] : RowStat us = destr oy but row does not exist"); | |
1324 | } | |
1325 | } else i f (!isCrea tionEnable d()) { | |
1326 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
1327 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, | |
1328 | Sn mpMibTable .class.get Name(), | |
1329 | "b eginRowAct ion", | |
1330 | "C an't destr oy row[" + rowOid + "] : " + | |
1331 | "R owStatus = destroy b ut creatio n is disab led"); | |
1332 | } | |
1333 | chec kRowStatus Fail(req,S nmpStatusE xception.s nmpRspNoAc cess); | |
1334 | } | |
1335 | checkRem oveTableRo w(req,rowO id,depth); | |
1336 | break; | |
1337 | ca se EnumRow Status.act ive: | |
1338 | ca se EnumRow Status.not InService: | |
1339 | if (isne w) { | |
1340 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
1341 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, | |
1342 | Sn mpMibTable .class.get Name(), | |
1343 | "b eginRowAct ion", "Can 't switch state of r ow[" + | |
1344 | ro wOid + "] : specifie d RowStatu s = active | " + | |
1345 | "n otInServic e but row does not e xist"); | |
1346 | } | |
1347 | chec kRowStatus Fail(req, | |
1348 | SnmpSt atusExcept ion.snmpRs pInconsist entValue); | |
1349 | } | |
1350 | checkRow StatusChan ge(req,row Oid,depth, action); | |
1351 | break; | |
1352 | ca se EnumRow Status.not Ready: | |
1353 | de fault: | |
1354 | if (SNMP _ADAPTOR_L OGGER.isLo ggable(Lev el.FINEST) ) { | |
1355 | SNMP _ADAPTOR_L OGGER.logp (Level.FIN EST, | |
1356 | SnmpMi bTable.cla ss.getName (), | |
1357 | "begin RowAction" , "Invalid RowStatus value for row[" + | |
1358 | rowOid + "] : sp ecified Ro wStatus = " + action ); | |
1359 | } | |
1360 | checkRow StatusFail (req, | |
1361 | SnmpStatus Exception. snmpRspInc onsistentV alue); | |
1362 | } | |
1363 | } | |
1364 | ||
1365 | /** | |
1366 | * Thi s method t akes care of final R owStatus h andling du ring the | |
1367 | * set () phase o f a SET re quest. | |
1368 | * | |
1369 | * In particular it will: | |
1370 | * <ul><li>e ither call <code>set RowStatus( <i>active< /i>)</code > | |
1371 | * (<cod e> rowActi on = <i>cr eateAndGo< /i> or <i> active</i> | |
1372 | * </cod e>),</li> | |
1373 | * <li>or ca ll <code>s etRowStatu s(<i>notIn Service</i > or <i> | |
1374 | * notRe ady</i>)</ code> depe nding on t he result of <code> | |
1375 | * isRow Ready()</c ode> (<cod e>rowActio n = <i>cre ateAndWait </i> | |
1376 | * </cod e>),</li> | |
1377 | * <li>or ca ll <code>s etRowStatu s(<i>notIn Service</i >)</code> | |
1378 | * (<cod e> rowActi on = <i>no tInService </i></code >), | |
1379 | * <li>or ca ll <code>r emoveTable Row()</cod e> (<code> | |
1380 | * rowAc tion = <i> destroy</i ></code>), </li> | |
1381 | * <li>or ge nerate a S nmpStatusE xception i f the pass ed <code> | |
1382 | * rowAc tion</code > is not c orrect. Th is should be avoided | |
1383 | * since it would break SET request at omicity</l i> | |
1384 | * </ul> | |
1385 | * <p> | |
1386 | * In principle, you shoul d not need to redefi ne this me thod. | |
1387 | * <p> | |
1388 | * <co de>endRowA ction()</c ode> is ca lled durin g the set( ) phase | |
1389 | * of a SET requ est, after the actua l set() on the varbi nd list | |
1390 | * has been perf ormed. The varbind c ontaining the contro l variable | |
1391 | * is updated wi th the val ue returne d by setRo wStatus() (if it is | |
1392 | * not <code>nul l</code>). | |
1393 | * | |
1394 | * <p> | |
1395 | * @pa ram req The sub-r equest tha t must be handled by this node . | |
1396 | * | |
1397 | * @pa ram rowOid The <CODE >SnmpOid</ CODE> iden tifying th e table | |
1398 | * row invol ved in the operation . | |
1399 | * | |
1400 | * @pa ram depth The depth reached i n the OID tree. | |
1401 | * | |
1402 | * @pa ram rowAct ion The re quested ac tion as re turned by <code> | |
1403 | * getRow Action()</ code>: one of the Ro wStatus co des define d in | |
1404 | * {@link com.sun.j mx.snmp.En umRowStatu s}. These codes | |
1405 | * corres pond to Ro wStatus co des as def ined in RF C 2579, | |
1406 | * plus t he <i>unsp ecified</i > value wh ich is SNM P Runtime specific. | |
1407 | * | |
1408 | * @ex ception Sn mpStatusEx ception if the speci fied <code >rowAction </code> | |
1409 | * is not valid . | |
1410 | * | |
1411 | * @se e com.sun. jmx.snmp.E numRowStat us | |
1412 | **/ | |
1413 | protec ted void e ndRowActio n(SnmpMibS ubRequest req, SnmpO id rowOid, | |
1414 | int depth , int rowA ction) | |
1415 | th rows SnmpS tatusExcep tion { | |
1416 | fi nal boolea n isne w = req.i sNewEntry( ); | |
1417 | fi nal SnmpOi d oid = rowOi d; | |
1418 | fi nal int acti on = rowAc tion; | |
1419 | fi nal Object data = req.g etUserData (); | |
1420 | Sn mpValue valu e = null; | |
1421 | ||
1422 | sw itch (acti on) { | |
1423 | ca se EnumRow Status.uns pecified: | |
1424 | break; | |
1425 | ca se EnumRow Status.cre ateAndGo: | |
1426 | if (SNMP _ADAPTOR_L OGGER.isLo ggable(Lev el.FINEST) ) { | |
1427 | SNMP _ADAPTOR_L OGGER.logp (Level.FIN EST, | |
1428 | SnmpMi bTable.cla ss.getName (), | |
1429 | "endRo wAction", "Setting R owStatus t o 'active' " + | |
1430 | "for r ow[" + row Oid + "] : requested RowStatus = " + | |
1431 | "creat eAndGo"); | |
1432 | } | |
1433 | value = setRowStat us(oid,Enu mRowStatus .active,da ta); | |
1434 | break; | |
1435 | ca se EnumRow Status.cre ateAndWait : | |
1436 | if (isRo wReady(oid ,data)) { | |
1437 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
1438 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, | |
1439 | Sn mpMibTable .class.get Name(), | |
1440 | "e ndRowActio n", | |
1441 | "S etting Row Status to 'notInServ ice' for r ow[" + | |
1442 | ro wOid + "] : requeste d RowStatu s = create AndWait"); | |
1443 | } | |
1444 | valu e = setRow Status(oid ,EnumRowSt atus.notIn Service,da ta); | |
1445 | } else { | |
1446 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
1447 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, | |
1448 | Sn mpMibTable .class.get Name(), | |
1449 | "e ndRowActio n", "Setti ng RowStat us to 'not Ready' " + | |
1450 | "f or row[" + rowOid + "] : reque sted RowSt atus = " + | |
1451 | "c reateAndWa it"); | |
1452 | } | |
1453 | valu e = setRow Status(oid ,EnumRowSt atus.notRe ady,data); | |
1454 | } | |
1455 | break; | |
1456 | ca se EnumRow Status.des troy: | |
1457 | if (isne w) { | |
1458 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
1459 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, | |
1460 | Sn mpMibTable .class.get Name(), | |
1461 | "e ndRowActio n", | |
1462 | "W arning: re quested Ro wStatus = destroy, " + | |
1463 | "b ut row[" + rowOid + "] does no t exist"); | |
1464 | } | |
1465 | } else { | |
1466 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
1467 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, | |
1468 | Sn mpMibTable .class.get Name(), | |
1469 | "e ndRowActio n", "Destr oying row[ " + rowOid + | |
1470 | "] : request ed RowStat us = destr oy"); | |
1471 | } | |
1472 | } | |
1473 | removeTa bleRow(req ,oid,depth ); | |
1474 | break; | |
1475 | ca se EnumRow Status.act ive: | |
1476 | if (SNMP _ADAPTOR_L OGGER.isLo ggable(Lev el.FINEST) ) { | |
1477 | SNMP _ADAPTOR_L OGGER.logp (Level.FIN EST, | |
1478 | SnmpMi bTable.cla ss.getName (), | |
1479 | "endRo wAction", | |
1480 | "Setti ng RowStat us to 'act ive' for r ow[" + | |
1481 | rowOid + "] : re quested Ro wStatus = active"); | |
1482 | } | |
1483 | value = setRowStat us(oid,Enu mRowStatus .active,da ta); | |
1484 | break; | |
1485 | ca se EnumRow Status.not InService: | |
1486 | if (SNMP _ADAPTOR_L OGGER.isLo ggable(Lev el.FINEST) ) { | |
1487 | SNMP _ADAPTOR_L OGGER.logp (Level.FIN EST, | |
1488 | SnmpMi bTable.cla ss.getName (), | |
1489 | "endRo wAction", | |
1490 | "Setti ng RowStat us to 'not InService' for row[" + | |
1491 | rowOid + "] : re quested Ro wStatus = notInServi ce"); | |
1492 | } | |
1493 | value = setRowStat us(oid,Enu mRowStatus .notInServ ice,data); | |
1494 | break; | |
1495 | ca se EnumRow Status.not Ready: | |
1496 | de fault: | |
1497 | if (SNMP _ADAPTOR_L OGGER.isLo ggable(Lev el.FINEST) ) { | |
1498 | SNMP _ADAPTOR_L OGGER.logp (Level.FIN EST, | |
1499 | SnmpMi bTable.cla ss.getName (), | |
1500 | "endRo wAction", "Invalid R owStatus v alue for r ow[" + | |
1501 | rowOid + "] : sp ecified Ro wStatus = " + action ); | |
1502 | } | |
1503 | setRowSt atusFail(r eq, | |
1504 | Snmp StatusExce ption.snmp RspInconsi stentValue ); | |
1505 | } | |
1506 | if (value != null) { | |
1507 | final Sn mpVarBind vb = req.g etRowStatu sVarBind() ; | |
1508 | if (vb ! = null) vb .value = v alue; | |
1509 | } | |
1510 | } | |
1511 | ||
1512 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ---- | |
1513 | // PRO TECTED MET HODS - get next | |
1514 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ---- | |
1515 | ||
1516 | /** | |
1517 | * Ret urn the ne xt OID arc correspon ding to a readable c olumnar | |
1518 | * obj ect in the underlyin g entry OB JECT-TYPE, possibly skipping o ver | |
1519 | * tho se objects that must not or ca nnot be re turned. | |
1520 | * Cal ls {@link | |
1521 | * #ge tNextVarEn tryId(com. sun.jmx.sn mp.SnmpOid ,long,java .lang.Obje ct)}, | |
1522 | * unt il | |
1523 | * {@l ink #skipE ntryVariab le(com.sun .jmx.snmp. SnmpOid,lo ng, | |
1524 | * jav a.lang.Obj ect,int)} returns fa lse. | |
1525 | * | |
1526 | * | |
1527 | * @pa ram rowOid The OID i ndex of th e row invo lved in th e operatio n. | |
1528 | * | |
1529 | * @pa ram var Id of the va riable we start from , looking for the ne xt. | |
1530 | * | |
1531 | * @pa ram userDa ta A conte xtual obje ct contain ing user-d ata. | |
1532 | * This o bject is a llocated t hrough the <code> | |
1533 | * {@link com.sun.j mx.snmp.ag ent.SnmpUs erDataFact ory}</code > | |
1534 | * for ea ch incomin g SNMP req uest. | |
1535 | * | |
1536 | * @pa ram pduVer sion Proto col versio n of the o riginal re quest PDU. | |
1537 | * | |
1538 | * @re turn The n ext column ar object id which c an be retu rned using | |
1539 | * the g iven PDU's protocol version. | |
1540 | * | |
1541 | * @ex ception Sn mpStatusEx ception If no id is found afte r the give n id. | |
1542 | * | |
1543 | **/ | |
1544 | protec ted long g etNextVarE ntryId(Snm pOid rowOi d, | |
1545 | lon g var, | |
1546 | Obj ect userDa ta, | |
1547 | int pduVersio n) | |
1548 | th rows SnmpS tatusExcep tion { | |
1549 | ||
1550 | lo ng varid=v ar; | |
1551 | do { | |
1552 | varid = getNextVar EntryId(ro wOid,varid ,userData) ; | |
1553 | } while (ski pEntryVari able(rowOi d,varid,us erData,pdu Version)); | |
1554 | ||
1555 | re turn varid ; | |
1556 | } | |
1557 | ||
1558 | /** | |
1559 | * Hoo k for subc lasses. | |
1560 | * The default i mplementat ion of thi s method i s to alway s return | |
1561 | * fal se. Subcla sses shoul d redefine this meth od so that it return s | |
1562 | * tru e when: | |
1563 | * <ul ><li>the v ariable is a leaf th at is not instantiat ed,</li> | |
1564 | * <li >or the va riable is a leaf who se type ca nnot be re turned by that | |
1565 | * version o f the prot ocol (e.g. an Counte r64 with S NMPv1).</l i> | |
1566 | * </u l> | |
1567 | * | |
1568 | * @pa ram rowOid The OID i ndex of th e row invo lved in th e operatio n. | |
1569 | * | |
1570 | * @pa ram var Id of the va riable we start from , looking for the ne xt. | |
1571 | * | |
1572 | * @pa ram userDa ta A conte xtual obje ct contain ing user-d ata. | |
1573 | * This o bject is a llocated t hrough the <code> | |
1574 | * {@link com.sun.j mx.snmp.ag ent.SnmpUs erDataFact ory}</code > | |
1575 | * for ea ch incomin g SNMP req uest. | |
1576 | * | |
1577 | * @pa ram pduVer sion Proto col versio n of the o riginal re quest PDU. | |
1578 | * | |
1579 | * @re turn true if the var iable must be skippe d by the g et-next | |
1580 | * algor ithm. | |
1581 | */ | |
1582 | protec ted boolea n skipEntr yVariable( SnmpOid ro wOid, | |
1583 | long var, | |
1584 | Object use rData, | |
1585 | int pduVer sion) { | |
1586 | re turn false ; | |
1587 | } | |
1588 | ||
1589 | /** | |
1590 | * Get the <CODE >SnmpOid</ CODE> inde x of the r ow that fo llows | |
1591 | * the given <CO DE>oid</CO DE> in the table. Th e given <C ODE> | |
1592 | * oid </CODE> do es not nee d to be a valid row OID index. | |
1593 | * | |
1594 | * <p> | |
1595 | * @pa ram oid Th e OID from which the search wi ll begin. | |
1596 | * | |
1597 | * @pa ram userDa ta A conte xtual obje ct contain ing user-d ata. | |
1598 | * This o bject is a llocated t hrough the <code> | |
1599 | * {@link com.sun.j mx.snmp.ag ent.SnmpUs erDataFact ory}</code > | |
1600 | * for ea ch incomin g SNMP req uest. | |
1601 | * | |
1602 | * @re turn The n ext <CODE> SnmpOid</C ODE> index . | |
1603 | * | |
1604 | * @ex ception Sn mpStatusEx ception Th ere is no index foll owing the | |
1605 | * specified <CODE>oid </CODE> in the table . | |
1606 | */ | |
1607 | protec ted SnmpOi d getNextO id(SnmpOid oid, Obje ct userDat a) | |
1608 | th rows SnmpS tatusExcep tion { | |
1609 | ||
1610 | if (size == 0) { | |
1611 | throw ne w SnmpStat usExceptio n(SnmpStat usExceptio n.noSuchIn stance); | |
1612 | } | |
1613 | ||
1614 | fi nal SnmpOi d resOid = oid; | |
1615 | ||
1616 | // Just a si mple check to speed up retriev al of last element . .. | |
1617 | // | |
1618 | // XX SnmpOi d last= (S nmpOid) oi ds.lastEle ment(); | |
1619 | Sn mpOid last = tableoid s[tablecou nt-1]; | |
1620 | if (last.equ als(resOid )) { | |
1621 | // Last element of the table ... | |
1622 | // | |
1623 | throw ne w SnmpStat usExceptio n(SnmpStat usExceptio n.noSuchIn stance); | |
1624 | } | |
1625 | ||
1626 | // First fin d the oid. This will allow to speed up r etrieval p rocess | |
1627 | // during sm art discov ery of tab le (using the getNex t) as the | |
1628 | // managemen t station will use t he valid i ndex retur ned during a | |
1629 | // previous getNext .. . | |
1630 | // | |
1631 | ||
1632 | // Returns t he positio n followin g the posi tion at wh ich resOid | |
1633 | // is found, or the po sition at which resO id should be inserte d. | |
1634 | // | |
1635 | fi nal int ne wPos = get InsertionP oint(resOi d,false); | |
1636 | ||
1637 | // If the po sition ret urned is n ot out of bound, we will find | |
1638 | // the next element in the array . | |
1639 | // | |
1640 | if (newPos > -1 && new Pos < size ) { | |
1641 | try { | |
1642 | // X X last = ( SnmpOid) o ids.elemen tAt(newPos ); | |
1643 | last = tableoi ds[newPos] ; | |
1644 | } catch( ArrayIndex OutOfBound sException e) { | |
1645 | thro w new Snmp StatusExce ption(Snmp StatusExce ption.noSu chInstance ); | |
1646 | } | |
1647 | } else { | |
1648 | // We ar e dealing with the l ast elemen t of the t able .. | |
1649 | // | |
1650 | throw ne w SnmpStat usExceptio n(SnmpStat usExceptio n.noSuchIn stance); | |
1651 | } | |
1652 | ||
1653 | ||
1654 | re turn last; | |
1655 | } | |
1656 | ||
1657 | /** | |
1658 | * Ret urn the fi rst entry OID regist ered in th e table. | |
1659 | * | |
1660 | * <p> | |
1661 | * @pa ram userDa ta A conte xtual obje ct contain ing user-d ata. | |
1662 | * This o bject is a llocated t hrough the <code> | |
1663 | * {@link com.sun.j mx.snmp.ag ent.SnmpUs erDataFact ory}</code > | |
1664 | * for ea ch incomin g SNMP req uest. | |
1665 | * | |
1666 | * @re turn The < CODE>SnmpO id</CODE> of the fir st entry i n the tabl e. | |
1667 | * | |
1668 | * @ex ception Sn mpStatusEx ception If the table is empty. | |
1669 | */ | |
1670 | protec ted SnmpOi d getNextO id(Object userData) | |
1671 | th rows SnmpS tatusExcep tion { | |
1672 | if (size == 0) { | |
1673 | throw ne w SnmpStat usExceptio n(SnmpStat usExceptio n.noSuchIn stance); | |
1674 | } | |
1675 | // XX return (SnmpOid) oids.firs tElement() ; | |
1676 | re turn table oids[0]; | |
1677 | } | |
1678 | ||
1679 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ---- | |
1680 | // Abs tract Prot ected Meth ods | |
1681 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ---- | |
1682 | ||
1683 | /** | |
1684 | * Thi s method i s used int ernally an d is imple mented by the | |
1685 | * <CO DE>SnmpMib Table</COD E> subclas ses genera ted by <CO DE>mibgen< /CODE>. | |
1686 | * | |
1687 | * <p> Return th e next OID arc corre sponding t o a readab le columna r | |
1688 | * object in the under lying entr y OBJECT-T YPE.</p> | |
1689 | * | |
1690 | * <p> | |
1691 | * @pa ram rowOid The OID i ndex of th e row invo lved in th e operatio n. | |
1692 | * | |
1693 | * @pa ram var Id of the va riable we start from , looking for the ne xt. | |
1694 | * | |
1695 | * @pa ram userDa ta A conte xtual obje ct contain ing user-d ata. | |
1696 | * This o bject is a llocated t hrough the <code> | |
1697 | * {@link com.sun.j mx.snmp.ag ent.SnmpUs erDataFact ory}</code > | |
1698 | * for ea ch incomin g SNMP req uest. | |
1699 | * | |
1700 | * @re turn The n ext column ar object id. | |
1701 | * | |
1702 | * @ex ception Sn mpStatusEx ception If no id is found afte r the give n id. | |
1703 | * | |
1704 | **/ | |
1705 | abstra ct protect ed long ge tNextVarEn tryId(Snmp Oid rowOid , long var , | |
1706 | Obje ct userDat a) | |
1707 | th rows SnmpS tatusExcep tion; | |
1708 | ||
1709 | /** | |
1710 | * Thi s method i s used int ernally an d is imple mented by the | |
1711 | * <CO DE>SnmpMib Table</COD E> subclas ses genera ted by <CO DE>mibgen< /CODE>. | |
1712 | * | |
1713 | * <p> | |
1714 | * @pa ram rowOid The OID i ndex of th e row invo lved in th e operatio n. | |
1715 | * | |
1716 | * @pa ram var Th e var we w ant to val idate. | |
1717 | * | |
1718 | * @pa ram userDa ta A conte xtual obje ct contain ing user-d ata. | |
1719 | * This o bject is a llocated t hrough the <code> | |
1720 | * {@link com.sun.j mx.snmp.ag ent.SnmpUs erDataFact ory}</code > | |
1721 | * for ea ch incomin g SNMP req uest. | |
1722 | * | |
1723 | * @ex ception Sn mpStatusEx ception If this id i s not vali d. | |
1724 | * | |
1725 | */ | |
1726 | abstra ct protect ed void va lidateVarE ntryId(Snm pOid rowOi d, long va r, | |
1727 | Obj ect userDa ta) | |
1728 | th rows SnmpS tatusExcep tion; | |
1729 | ||
1730 | /** | |
1731 | * | |
1732 | * Thi s method i s used int ernally an d is imple mented by the | |
1733 | * <CO DE>SnmpMib Table</COD E> subclas ses genera ted by <CO DE>mibgen< /CODE>. | |
1734 | * | |
1735 | * <p> | |
1736 | * @pa ram rowOid The OID i ndex of th e row invo lved in th e operatio n. | |
1737 | * | |
1738 | * @pa ram var Th e OID arc. | |
1739 | * | |
1740 | * @pa ram userDa ta A conte xtual obje ct contain ing user-d ata. | |
1741 | * This o bject is a llocated t hrough the <code> | |
1742 | * {@link com.sun.j mx.snmp.ag ent.SnmpUs erDataFact ory}</code > | |
1743 | * for ea ch incomin g SNMP req uest. | |
1744 | * | |
1745 | * @ex ception Sn mpStatusEx ception If this id i s not vali d. | |
1746 | * | |
1747 | */ | |
1748 | abstra ct protect ed boolean isReadabl eEntryId(S nmpOid row Oid, long var, | |
1749 | O bject user Data) | |
1750 | th rows SnmpS tatusExcep tion; | |
1751 | ||
1752 | /** | |
1753 | * Thi s method i s used int ernally an d is imple mented by the | |
1754 | * <CO DE>SnmpMib Table</COD E> subclas ses genera ted by <CO DE>mibgen< /CODE>. | |
1755 | */ | |
1756 | abstra ct protect ed void ge t(SnmpMibS ubRequest req, | |
1757 | SnmpOid rowOid, in t depth) | |
1758 | th rows SnmpS tatusExcep tion; | |
1759 | ||
1760 | /** | |
1761 | * Thi s method i s used int ernally an d is imple mented by the | |
1762 | * <CO DE>SnmpMib Table</COD E> subclas ses genera ted by <CO DE>mibgen< /CODE>. | |
1763 | */ | |
1764 | abstra ct protect ed void ch eck(SnmpMi bSubReques t req, | |
1765 | SnmpOi d rowOid, int depth) | |
1766 | th rows SnmpS tatusExcep tion; | |
1767 | ||
1768 | /** | |
1769 | * Thi s method i s used int ernally an d is imple mented by the | |
1770 | * <CO DE>SnmpMib Table</COD E> subclas ses genera ted by <CO DE>mibgen< /CODE>. | |
1771 | */ | |
1772 | abstra ct protect ed void se t(SnmpMibS ubRequest req, | |
1773 | SnmpOid rowOid, in t depth) | |
1774 | th rows SnmpS tatusExcep tion; | |
1775 | ||
1776 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------- | |
1777 | // PAC KAGE METHO DS | |
1778 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------- | |
1779 | ||
1780 | /** | |
1781 | * Get the <CODE >SnmpOid</ CODE> inde x of the r ow that fo llows the | |
1782 | * ind ex extract ed from th e specifie d OID arra y. | |
1783 | * Bui lds the Sn mpOid corr esponding to the row OID and c alls | |
1784 | * <co de>getNext Oid(oid,us erData)</c ode>; | |
1785 | * | |
1786 | * <p> | |
1787 | * @pa ram oid Th e OID arra y. | |
1788 | * | |
1789 | * @pa ram pos Th e position in the OI D array at which the index sta rts. | |
1790 | * | |
1791 | * @pa ram userDa ta A conte xtual obje ct contain ing user-d ata. | |
1792 | * This o bject is a llocated t hrough the <code> | |
1793 | * {@link com.sun.j mx.snmp.ag ent.SnmpUs erDataFact ory}</code > | |
1794 | * for ea ch incomin g SNMP req uest. | |
1795 | * | |
1796 | * @re turn The n ext <CODE> SnmpOid</C ODE>. | |
1797 | * | |
1798 | * @ex ception Sn mpStatusEx ception Th ere is no index foll owing the | |
1799 | * specified one in th e table. | |
1800 | */ | |
1801 | SnmpOi d getNextO id(long[] oid, int p os, Object userData) | |
1802 | th rows SnmpS tatusExcep tion { | |
1803 | ||
1804 | // Construct the sub-o id startin g at pos. | |
1805 | // This sub- oid corres pond to th e oid part just afte r the entr y | |
1806 | // variable oid. | |
1807 | // | |
1808 | fi nal SnmpOi d resOid = new SnmpE ntryOid(oi d,pos); | |
1809 | ||
1810 | re turn getNe xtOid(resO id,userDat a); | |
1811 | } | |
1812 | ||
1813 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
1814 | // | |
1815 | // Reg ister an e xception w hen checki ng the Row Status var iable | |
1816 | // | |
1817 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
1818 | ||
1819 | static void chec kRowStatus Fail(SnmpM ibSubReque st req, in t errorSta tus) | |
1820 | th rows SnmpS tatusExcep tion { | |
1821 | ||
1822 | fi nal SnmpVa rBind stat usvb = re q.getRowSt atusVarBin d(); | |
1823 | fi nal SnmpSt atusExcept ion x = ne w SnmpStat usExceptio n(errorSta tus); | |
1824 | re q.register CheckExcep tion(statu svb,x); | |
1825 | } | |
1826 | ||
1827 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
1828 | // | |
1829 | // Reg ister an e xception w hen checki ng the Row Status var iable | |
1830 | // | |
1831 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
1832 | ||
1833 | static void setR owStatusFa il(SnmpMib SubRequest req, int errorStatu s) | |
1834 | th rows SnmpS tatusExcep tion { | |
1835 | ||
1836 | fi nal SnmpVa rBind stat usvb = re q.getRowSt atusVarBin d(); | |
1837 | fi nal SnmpSt atusExcept ion x = ne w SnmpStat usExceptio n(errorSta tus); | |
1838 | re q.register SetExcepti on(statusv b,x); | |
1839 | } | |
1840 | ||
1841 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
1842 | // | |
1843 | // Imp lements th e method d efined in SnmpMibNod e. | |
1844 | // | |
1845 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
1846 | @Overr ide | |
1847 | final synchroniz ed void fi ndHandling Node(SnmpV arBind var bind, | |
1848 | long[ ] oid, int depth, | |
1849 | SnmpR equestTree handlers) | |
1850 | th rows SnmpS tatusExcep tion { | |
1851 | ||
1852 | fi nal int l ength = oi d.length; | |
1853 | ||
1854 | if (handlers == null) | |
1855 | throw ne w SnmpStat usExceptio n(SnmpStat usExceptio n.snmpRspG enErr); | |
1856 | ||
1857 | if (depth >= length) | |
1858 | throw ne w SnmpStat usExceptio n(SnmpStat usExceptio n.noAccess ); | |
1859 | ||
1860 | if (oid[dept h] != node Id) | |
1861 | throw ne w SnmpStat usExceptio n(SnmpStat usExceptio n.noAccess ); | |
1862 | ||
1863 | if (depth+2 >= length) | |
1864 | throw ne w SnmpStat usExceptio n(SnmpStat usExceptio n.noAccess ); | |
1865 | ||
1866 | // Checks th at the oid is valid | |
1867 | // validateO id(oid,dep th); | |
1868 | ||
1869 | // Gets the part of th e OID that identifie s the entr y | |
1870 | fi nal SnmpOi d entryoid = new Snm pEntryOid( oid, depth +2); | |
1871 | ||
1872 | // Finds the entry: fa lse means that the e ntry does not exists | |
1873 | fi nal Object data = ha ndlers.get UserData() ; | |
1874 | fi nal boolea n hasEntry = contain s(entryoid , data); | |
1875 | ||
1876 | // Fails if the entry is not fou nd and the table doe s not | |
1877 | // not suppo rt creatio n. | |
1878 | // We know t hat the en try does n ot exists if (isentr y == false ). | |
1879 | if (!hasEntr y) { | |
1880 | if (!han dlers.isCr eationAllo wed()) { | |
1881 | // w e're not d oing a set | |
1882 | thro w new Snmp StatusExce ption(Snmp StatusExce ption.noSu chInstance ); | |
1883 | } else i f (!isCrea tionEnable d()) | |
1884 | // w e're doing a set but creation is disable d. | |
1885 | thro w new | |
1886 | SnmpStatus Exception( SnmpStatus Exception. snmpRspNoA ccess); | |
1887 | } | |
1888 | ||
1889 | fi nal long var = oi d[depth+1] ; | |
1890 | ||
1891 | // Validate the entry id | |
1892 | if (hasEntry ) { | |
1893 | // The e ntry alrea dy exists - validate the id | |
1894 | validate VarEntryId (entryoid, var,data); | |
1895 | } | |
1896 | ||
1897 | // Registers this node for the i dentified entry. | |
1898 | // | |
1899 | if (handlers .isSetRequ est() && i sRowStatus (entryoid, var,data)) | |
1900 | ||
1901 | // We on ly try to identify t he RowStat us for SET operation s | |
1902 | // | |
1903 | handlers .add(this, depth,entr yoid,varbi nd,(!hasEn try),varbi nd); | |
1904 | ||
1905 | el se | |
1906 | handlers .add(this, depth,entr yoid,varbi nd,(!hasEn try)); | |
1907 | } | |
1908 | ||
1909 | ||
1910 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
1911 | // | |
1912 | // Imp lements th e method d efined in SnmpMibNod e. The alg orithm is very | |
1913 | // lar gely inspi red from t he origina l getNext( ) method. | |
1914 | // | |
1915 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------ | |
1916 | @Overr ide | |
1917 | final synchroniz ed long[] findNextHa ndlingNode (SnmpVarBi nd varbind , | |
1918 | long[] oi d, | |
1919 | int pos, | |
1920 | int depth , | |
1921 | SnmpReque stTree han dlers, | |
1922 | AcmChecke r checker) | |
1923 | th rows SnmpS tatusExcep tion { | |
1924 | ||
1925 | int leng th = oid.l ength; | |
1926 | ||
1927 | if (hand lers == nu ll) { | |
1928 | // T his should be consid ered as a genErr, bu t we do no t want to | |
1929 | // a bort the w hole reque st, so we' re going t o throw | |
1930 | // a noSuchObj ect... | |
1931 | // | |
1932 | thro w new Snmp StatusExce ption(Snmp StatusExce ption.noSu chObject); | |
1933 | } | |
1934 | ||
1935 | final Ob ject data = handlers .getUserDa ta(); | |
1936 | final in t pduVersi on = handl ers.getReq uestPduVer sion(); | |
1937 | ||
1938 | long var = -1; | |
1939 | ||
1940 | // If th e querried oid conta ins less a rcs than t he OID of the | |
1941 | // xxxEn try object , we must return the first lea f under th e | |
1942 | // first columnar object: th e best way to do tha t is to re set | |
1943 | // the q ueried oid : | |
1944 | // oid [0] = node Id (arc of the xxxEn try object ) | |
1945 | // pos = 0 (p oints to t he arc of the xxxEnt ry object) | |
1946 | // then we just ha ve to proc eed... | |
1947 | // | |
1948 | if (pos >= length) { | |
1949 | // t his will h ave the si de effect to set | |
1950 | // oid[pos] = nodeId | |
1951 | // a nd | |
1952 | // (pos+1) = length | |
1953 | // s o we won't fall into the "else if" cases below - | |
1954 | // s o using "e lse if" ra ther than "if ..." i s guarante ed | |
1955 | // t o be safe. | |
1956 | // | |
1957 | oid = new long [1]; | |
1958 | oid[ 0] = nodeI d; | |
1959 | pos = 0; | |
1960 | leng th = 1; | |
1961 | } else i f (oid[pos ] > nodeId ) { | |
1962 | // o id[pos] is expected to be the id of the xxxEntry . .. | |
1963 | // T he id requ ested is g reater tha n the id o f the xxxE ntry, | |
1964 | // s o we won't find the next eleme nt in this table... (any | |
1965 | // e lement in this table will have a smaller OID) | |
1966 | // | |
1967 | thro w new Snmp StatusExce ption(Snmp StatusExce ption.noSu chObject); | |
1968 | } else i f (oid[pos ] < nodeId ) { | |
1969 | // w e must ret urn the fi rst leaf u nder the f irst colum nar | |
1970 | // o bject, so we are bac k to our f irst case where pos was | |
1971 | // o ut of boun ds... => r eset the o id to cont ain only t he | |
1972 | // a rc of the xxxEntry o bject. | |
1973 | // | |
1974 | oid = new long [1]; | |
1975 | oid[ 0] = nodeI d; | |
1976 | pos = 0; | |
1977 | leng th = 0; | |
1978 | } else i f ((pos + 1) < lengt h) { | |
1979 | // T he arc at the positi on "pos+1" is the id of the co lumnar | |
1980 | // o bject (ie: the id of the varia ble in the table ent ry) | |
1981 | // | |
1982 | var = oid[pos+ 1]; | |
1983 | } | |
1984 | ||
1985 | // Now t hat we've got everyt hing right we can be gin. | |
1986 | SnmpOid entryoid; | |
1987 | ||
1988 | if (pos == (length - 1)) { | |
1989 | // p os points to the las t arc in t he oid, an d this arc is | |
1990 | // g uaranteed to be the xxxEntry i d (we have handled a ll | |
1991 | // t he other p ossibiliti es before) | |
1992 | // | |
1993 | // W e must the refore ret urn the fi rst leaf b elow the f irst | |
1994 | // c olumnar ob ject in th e table. | |
1995 | // | |
1996 | // G et the fir st index. If an exce ption is r aised, | |
1997 | // t hen it mea ns that th e table is empty. We thus do n ot | |
1998 | // h ave to cat ch the exc eption - w e let it p ropagate t o | |
1999 | // t he caller. | |
2000 | // | |
2001 | entr yoid = get NextOid(da ta); | |
2002 | var = getNextV arEntryId( entryoid,v ar,data,pd uVersion); | |
2003 | } else i f ( pos == (length-2 )) { | |
2004 | // I n that cas e we have (pos+1) = (length-1) , so pos | |
2005 | // p oints to t he arc of the querri ed variabl e (columna r object). | |
2006 | // S ince the r equested o id stops t here, it m eans we ha ve | |
2007 | // t o return t he first l eaf under this colum nar object . | |
2008 | // | |
2009 | // S o we first get the f irst index : | |
2010 | // N ote: if th is raises an excepti on, this m eans that the table | |
2011 | // i s empty, s o we can l et the exc eption pro pagate to the caller . | |
2012 | // | |
2013 | entr yoid = get NextOid(da ta); | |
2014 | ||
2015 | // X XX revisit : not exac tly perfec t: | |
2016 | // a speci fic row co uld be emp ty.. But w e don't kn ow | |
2017 | // how to make the d ifference! => tradeo ff holes | |
2018 | // in tabl es can't b e properly supported (all rows | |
2019 | // must ha ve the sam e holes) | |
2020 | // | |
2021 | if ( skipEntryV ariable(en tryoid,var ,data,pduV ersion)) { | |
2022 | var = getN extVarEntr yId(entryo id,var,dat a,pduVersi on); | |
2023 | } | |
2024 | } else { | |
2025 | ||
2026 | // S o now ther e remain o ne last ca se, namely : some par t of the | |
2027 | // i ndex is pr ovided by the oid... | |
2028 | // W e build a possibly i ncomplete and invali d index fr om | |
2029 | // t he OID. | |
2030 | // T he piece o f index pr ovided sho uld begin at pos+2 | |
2031 | // oid[pos] = id of the xxxEnt ry object, | |
2032 | // oid[pos+1 ] = id of the column ar object, | |
2033 | // oid[pos+2 ] ... oid[ length-1] = piece of index. | |
2034 | // | |
2035 | ||
2036 | // W e get the next index following the provi ded index. | |
2037 | // I f this rai ses an exc eption, th en it mean s that we have | |
2038 | // r eached the last inde x in the t able, and we must th en | |
2039 | // t ry with th e next col umnar obje ct. | |
2040 | // | |
2041 | // B ug fix 426 9251 | |
2042 | // T he SnmpInd ex is defi ned to con tain a val id oid: | |
2043 | // t his is not an SNMP r equirement for the g etNext req uest. | |
2044 | // S o we no mo re use the SnmpIndex but direc tly the Sn mpOid. | |
2045 | // | |
2046 | try { | |
2047 | entryoid = getNextOi d(oid, pos + 2, data ); | |
2048 | ||
2049 | // If the variable m ust ne ski pped, fall through.. . | |
2050 | // | |
2051 | // XXX rev isit: not exactly pe rfect: | |
2052 | // a s pecific ro w could be empty.. B ut we don' t know | |
2053 | // how to make t he differe nce! => tr adeoff hol es | |
2054 | // in tables can 't be prop erly suppo rted (all rows | |
2055 | // mus t have the same hole s) | |
2056 | // | |
2057 | if (skipEn tryVariabl e(entryoid ,var,data, pduVersion )) { | |
2058 | throw new SnmpSt atusExcept ion(SnmpSt atusExcept ion.noSuch Object); | |
2059 | } | |
2060 | } ca tch(SnmpSt atusExcept ion se) { | |
2061 | entryoid = getNextOi d(data); | |
2062 | var = getN extVarEntr yId(entryo id,var,dat a,pduVersi on); | |
2063 | } | |
2064 | } | |
2065 | ||
2066 | return f indNextAcc essibleOid (entryoid, | |
2067 | varbind, | |
2068 | oid, | |
2069 | depth, | |
2070 | handlers, | |
2071 | checker, | |
2072 | data, | |
2073 | var); | |
2074 | } | |
2075 | ||
2076 | privat e long[] f indNextAcc essibleOid (SnmpOid e ntryoid, | |
2077 | SnmpVarBi nd varbind ,long[] oi d, | |
2078 | int depth , SnmpRequ estTree ha ndlers, | |
2079 | AcmChecke r checker, Object da ta, | |
2080 | long var) | |
2081 | th rows SnmpS tatusExcep tion { | |
2082 | fi nal int pd uVersion = handlers. getRequest PduVersion (); | |
2083 | ||
2084 | // Loop on e ach var (c olumn) | |
2085 | wh ile(true) { | |
2086 | // This should not happen. I f it happe ns, (bug, or customi zed | |
2087 | // metho ds returni ng garbage instead o f raising an excepti on), | |
2088 | // it pr obably mea ns that th ere is not hing to re turn anywa y. | |
2089 | // So we throw the exception . | |
2090 | // => wi ll skip to next node in the MI B tree. | |
2091 | // | |
2092 | if (entr yoid == nu ll || var == -1 ) { | |
2093 | thro w new Snmp StatusExce ption(Snmp StatusExce ption.noSu chObject); | |
2094 | } | |
2095 | ||
2096 | // So he re we know both the row (entry oid) and t he column (var) | |
2097 | // | |
2098 | ||
2099 | try { | |
2100 | // R aising an exception here will make the c atch() cla use | |
2101 | // s witch to t he next va riable. If `var' is not readab le | |
2102 | // f or this sp ecific ent ry, it is not readab le for any | |
2103 | // o ther entry => skip t o next col umn. | |
2104 | // | |
2105 | if ( !isReadabl eEntryId(e ntryoid,va r,data)) { | |
2106 | throw new SnmpStatus Exception( SnmpStatus Exception. noSuchObje ct); | |
2107 | } | |
2108 | ||
2109 | // P repare the result an d the ACM checker. | |
2110 | // | |
2111 | fina l long[] e table = e ntryoid.lo ngValue(fa lse); | |
2112 | fina l int e length = e table.leng th; | |
2113 | fina l long[] r esult = n ew long[de pth + 2 + elength]; | |
2114 | resu lt[0] = -1 ; // Bug detector! | |
2115 | ||
2116 | // C opy the en tryOid at the end of `result' | |
2117 | // | |
2118 | java .lang.Syst em.arrayco py(etable, 0, result , | |
2119 | depth+2 , elength) ; | |
2120 | ||
2121 | // S et the nod e Id and v ar Id in r esult. | |
2122 | // | |
2123 | resu lt[depth] = nodeId; | |
2124 | resu lt[depth+1 ] = var; | |
2125 | ||
2126 | // A ppend node Id.varId.< rowOid> to ACM check er. | |
2127 | // | |
2128 | chec ker.add(de pth,result ,depth,ele ngth+2); | |
2129 | ||
2130 | // N o we're go ing to ACM check our OID. | |
2131 | try { | |
2132 | checker.ch eckCurrent Oid(); | |
2133 | ||
2134 | // No exce ption thro wn by chec ker => thi s is all O K! | |
2135 | // we have it: regis ter the ha ndler and return the | |
2136 | // result. | |
2137 | // | |
2138 | handlers.a dd(this,de pth,entryo id,varbind ,false); | |
2139 | return res ult; | |
2140 | } ca tch(SnmpSt atusExcept ion e) { | |
2141 | // Skip to the next entry. If an excepti on is | |
2142 | // thrown, will be c atch by en closing ca tch | |
2143 | // and a s kip is don e to the n ext var. | |
2144 | // | |
2145 | entryoid = getNextOi d(entryoid , data); | |
2146 | } fi nally { | |
2147 | // Clean t he checker . | |
2148 | // | |
2149 | checker.re move(depth ,elength+2 ); | |
2150 | } | |
2151 | } catch( SnmpStatus Exception e) { | |
2152 | // C atching an exception here mean s we have to skip to the | |
2153 | // n ext column . | |
2154 | // | |
2155 | // B ack to the first row . | |
2156 | entr yoid = get NextOid(da ta); | |
2157 | ||
2158 | // F ind out th e next col umn. | |
2159 | // | |
2160 | var = getNextV arEntryId( entryoid,v ar,data,pd uVersion); | |
2161 | ||
2162 | } | |
2163 | ||
2164 | // This should not happen. I f it happe ns, (bug, or customi zed | |
2165 | // metho ds returni ng garbage instead o f raising an excepti on), | |
2166 | // it pr obably mea ns that th ere is not hing to re turn anywa y. | |
2167 | // No ne ed to cont inue, we t hrow an ex ception. | |
2168 | // => wi ll skip to next node in the MI B tree. | |
2169 | // | |
2170 | if (entr yoid == nu ll || var == -1 ) { | |
2171 | thro w new Snmp StatusExce ption(Snmp StatusExce ption.noSu chObject); | |
2172 | } | |
2173 | } | |
2174 | } | |
2175 | ||
2176 | ||
2177 | /** | |
2178 | * Val idate the specified OID. | |
2179 | * | |
2180 | * <p> | |
2181 | * @pa ram oid Th e OID arra y. | |
2182 | * | |
2183 | * @pa ram pos Th e position in the ar ray. | |
2184 | * | |
2185 | * @ex ception Sn mpStatusEx ception If the valid ation fail s. | |
2186 | */ | |
2187 | final void valid ateOid(lon g[] oid, i nt pos) th rows SnmpS tatusExcep tion { | |
2188 | fi nal int le ngth= oid. length; | |
2189 | ||
2190 | // Control t he length of the oid | |
2191 | // | |
2192 | if (pos +2 > = length) { | |
2193 | throw ne w SnmpStat usExceptio n(SnmpStat usExceptio n.noSuchIn stance); | |
2194 | } | |
2195 | ||
2196 | // Check tha t the entr y identifi er is spec ified | |
2197 | // | |
2198 | if (oid[pos] != nodeId ) { | |
2199 | throw ne w SnmpStat usExceptio n(SnmpStat usExceptio n.noSuchOb ject); | |
2200 | } | |
2201 | } | |
2202 | ||
2203 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------- | |
2204 | // PRI D A N E S M T ODS | |
2205 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------- | |
2206 | ||
2207 | /** | |
2208 | * Ena ble this < CODE>SnmpM ibTable</C ODE> to se nd a notif ication. | |
2209 | * | |
2210 | * <p> | |
2211 | * @pa ram notifi cation The notificat ion to sen d. | |
2212 | */ | |
2213 | privat e synchron ized void sendNotifi cation(Not ification notificati on) { | |
2214 | ||
2215 | // loop on l istener | |
2216 | // | |
2217 | fo r(java.uti l.Enumerat ion<Notifi cationList ener> k = handbackTa ble.keys() ; | |
2218 | k.hasMor eElements( ); ) { | |
2219 | ||
2220 | Notifica tionListen er listene r = k.next Element(); | |
2221 | ||
2222 | // Get t he associa ted handba ck list an d the asso ciated fil ter list | |
2223 | // | |
2224 | java.uti l.Vector<? > handback List = han dbackTable .get(liste ner) ; | |
2225 | java.uti l.Vector<N otificatio nFilter> f ilterList = | |
2226 | filt erTable.ge t(listener ) ; | |
2227 | ||
2228 | // loop on handbac k | |
2229 | // | |
2230 | java.uti l.Enumerat ion<Notifi cationFilt er> f = fi lterList.e lements(); | |
2231 | for(java .util.Enum eration<?> h = handb ackList.el ements(); | |
2232 | h.ha sMoreEleme nts(); ) { | |
2233 | ||
2234 | Obje ct handbac k = h.next Element(); | |
2235 | Noti ficationFi lter filte r = f.next Element(); | |
2236 | ||
2237 | if ( (filter == null) || | |
2238 | (filter.i sNotificat ionEnabled (notificat ion))) { | |
2239 | ||
2240 | listener.h andleNotif ication(no tification ,handback) ; | |
2241 | } | |
2242 | } | |
2243 | } | |
2244 | } | |
2245 | ||
2246 | /** | |
2247 | * Thi s method i s used by the SnmpMi bTable to create and send a ta ble | |
2248 | * ent ry notific ation to a ll the lis teners reg istered fo r this kin d of | |
2249 | * not ification. | |
2250 | * | |
2251 | * <p> | |
2252 | * @pa ram type T he notific ation type . | |
2253 | * | |
2254 | * @pa ram timeSt amp The no tification emission date. | |
2255 | * | |
2256 | * @pa ram entry The entry object. | |
2257 | */ | |
2258 | privat e void sen dNotificat ion(String type, lon g timeStam p, | |
2259 | Object entry, Ob jectName n ame) { | |
2260 | ||
2261 | sy nchronized (this) { | |
2262 | sequence Number = s equenceNum ber + 1; | |
2263 | } | |
2264 | ||
2265 | Sn mpTableEnt ryNotifica tion notif = | |
2266 | new Snmp TableEntry Notificati on(type, t his, seque nceNumber, | |
2267 | timeSta mp, entry, name); | |
2268 | ||
2269 | th is.sendNot ification( notif) ; | |
2270 | } | |
2271 | ||
2272 | /** | |
2273 | * Ret urn true i f the entr y identifi ed by the given OID index | |
2274 | * is contained in this ta ble. | |
2275 | * <p> | |
2276 | * <b> Do not cal l this met hod direct ly</b>. | |
2277 | * <p> | |
2278 | * Thi s method i s provided has a hoo k for subc lasses. | |
2279 | * It is called when a get /set reque st is rece ived in or der to | |
2280 | * det ermine whe ther the s pecified e ntry is co ntained in the table . | |
2281 | * You may want to overrid e this met hod if you need to p erform e.g . | |
2282 | * laz y evaluati on of tabl es (you ne ed to upda te the tab le when a | |
2283 | * req uest is re ceived) or if your t able is vi rtual. | |
2284 | * <p> | |
2285 | * Not e that thi s method i s called b y the Runt ime from w ithin a | |
2286 | * syn chronized block. | |
2287 | * | |
2288 | * @pa ram oid Th e index pa rt of the OID we're looking fo r. | |
2289 | * @pa ram userDa ta A conte xtual obje ct contain ing user-d ata. | |
2290 | * This o bject is a llocated t hrough the <code> | |
2291 | * {@link com.sun.j mx.snmp.ag ent.SnmpUs erDataFact ory}</code > | |
2292 | * for ea ch incomin g SNMP req uest. | |
2293 | * | |
2294 | * @re turn <code >true</cod e> if the entry is f ound, <cod e>false</c ode> | |
2295 | * other wise. | |
2296 | * | |
2297 | * @si nce 1.5 | |
2298 | **/ | |
2299 | protec ted boolea n contains (SnmpOid o id, Object userData) { | |
2300 | re turn (find Object(oid ) > -1); | |
2301 | } | |
2302 | ||
2303 | /** | |
2304 | * Loo k for the given oid in the OID table (ta bleoids) a nd returns | |
2305 | * its position. | |
2306 | * | |
2307 | * <p> | |
2308 | * @pa ram oid Th e OID we'r e looking for. | |
2309 | * | |
2310 | * @re turn The p osition of the OID i n the tabl e. -1 if t he given | |
2311 | * OID w as not fou nd. | |
2312 | * | |
2313 | **/ | |
2314 | privat e int find Object(Snm pOid oid) { | |
2315 | in t low= 0; | |
2316 | in t max= siz e - 1; | |
2317 | Sn mpOid pos; | |
2318 | in t comp; | |
2319 | in t curr= lo w + (max-l ow)/2; | |
2320 | // System.out .println(" Try to ret rieve: " + oid.toStr ing()); | |
2321 | wh ile (low < = max) { | |
2322 | ||
2323 | // XX po s = (SnmpO id) oids.e lementAt(c urr); | |
2324 | pos = ta bleoids[cu rr]; | |
2325 | ||
2326 | //System .out.print ln("Compar e with" + pos.toStri ng()); | |
2327 | // never know ...w e might fi nd somethi ng ... | |
2328 | // | |
2329 | comp = o id.compare To(pos); | |
2330 | if (comp == 0) | |
2331 | retu rn curr; | |
2332 | ||
2333 | if (oid. equals(pos ) == true) { | |
2334 | retu rn curr; | |
2335 | } | |
2336 | if (comp > 0) { | |
2337 | low = curr + 1 ; | |
2338 | } else { | |
2339 | max = curr - 1 ; | |
2340 | } | |
2341 | curr = l ow + (max- low)/2; | |
2342 | } | |
2343 | re turn -1; | |
2344 | } | |
2345 | ||
2346 | /** | |
2347 | * Sea rch the po sition at which the given oid should be inserted | |
2348 | * in the OID ta ble (table oids). | |
2349 | * | |
2350 | * <p> | |
2351 | * @pa ram oid Th e OID we w ould like to insert. | |
2352 | * | |
2353 | * @pa ram fail T ells wheth er a SnmpS tatusExcep tion must be generat ed | |
2354 | * i f the give n OID is a lready pre sent in th e table. | |
2355 | * | |
2356 | * @re turn The p osition at which the OID shoul d be inser ted in | |
2357 | * the t able. When the OID i s found, i t returns the next | |
2358 | * posit ion. Note that it is not valid to insert twice the | |
2359 | * same OID. This feature is only an o ptimizatio n to impro ve | |
2360 | * the g etNextOid( ) behaviou r. | |
2361 | * | |
2362 | * @ex ception Sn mpStatusEx ception if the OID i s already present in the | |
2363 | * ta ble and <c ode>fail</ code> is < code>true< /code>. | |
2364 | * | |
2365 | **/ | |
2366 | privat e int getI nsertionPo int(SnmpOi d oid, boo lean fail) | |
2367 | th rows SnmpS tatusExcep tion { | |
2368 | ||
2369 | fi nal int fa ilStatus = SnmpStatu sException .snmpRspNo tWritable; | |
2370 | in t low= 0; | |
2371 | in t max= siz e - 1; | |
2372 | Sn mpOid pos; | |
2373 | in t comp; | |
2374 | in t curr= lo w + (max-l ow)/2; | |
2375 | wh ile (low < = max) { | |
2376 | ||
2377 | // XX po s= (SnmpOi d) oids.el ementAt(cu rr); | |
2378 | pos= tab leoids[cur r]; | |
2379 | ||
2380 | // never know ...w e might fi nd somethi ng ... | |
2381 | // | |
2382 | comp= oi d.compareT o(pos); | |
2383 | ||
2384 | if (comp == 0) { | |
2385 | if ( fail) | |
2386 | throw new SnmpStatus Exception( failStatus ,curr); | |
2387 | else | |
2388 | return cur r+1; | |
2389 | } | |
2390 | ||
2391 | if (comp >0) { | |
2392 | low= curr +1; | |
2393 | } else { | |
2394 | max= curr -1; | |
2395 | } | |
2396 | curr= lo w + (max-l ow)/2; | |
2397 | } | |
2398 | re turn curr; | |
2399 | } | |
2400 | ||
2401 | /** | |
2402 | * Rem ove the OI D located at the giv en positio n. | |
2403 | * | |
2404 | * <p> | |
2405 | * @pa ram pos Th e position at which the OID to be remove d is locat ed. | |
2406 | * | |
2407 | **/ | |
2408 | privat e void rem oveOid(int pos) { | |
2409 | if (pos >= t ablecount) return; | |
2410 | if (pos < 0) return; | |
2411 | fi nal int l1 = --table count-pos; | |
2412 | ta bleoids[po s] = null; | |
2413 | if (l1 > 0) | |
2414 | java.lan g.System.a rraycopy(t ableoids,p os+1,table oids,pos,l 1); | |
2415 | ta bleoids[ta blecount] = null; | |
2416 | } | |
2417 | ||
2418 | /** | |
2419 | * Ins ert an OID at the gi ven positi on. | |
2420 | * | |
2421 | * <p> | |
2422 | * @pa ram oid Th e OID to b e inserted in the ta ble | |
2423 | * @pa ram pos Th e position at which the OID to be added is located . | |
2424 | * | |
2425 | **/ | |
2426 | privat e void ins ertOid(int pos, Snmp Oid oid) { | |
2427 | if (pos >= t ablesize | | tablecou nt == tabl esize) { | |
2428 | // V ector must be enlarg ed | |
2429 | ||
2430 | // S ave old ve ctor | |
2431 | fina l SnmpOid[ ] olde = t ableoids; | |
2432 | ||
2433 | // A llocate la rger vecto rs | |
2434 | tabl esize += D elta; | |
2435 | tabl eoids = ne w SnmpOid[ tablesize] ; | |
2436 | ||
2437 | // C heck pos v alidity | |
2438 | if ( pos > tabl ecount) po s = tablec ount; | |
2439 | if ( pos < 0) p os = 0; | |
2440 | ||
2441 | fina l int l1 = pos; | |
2442 | fina l int l2 = tablecoun t - pos; | |
2443 | ||
2444 | // C opy origin al vector up to `pos ' | |
2445 | if ( l1 > 0) | |
2446 | java.lang. System.arr aycopy(old e,0,tableo ids,0,l1); | |
2447 | ||
2448 | // C opy origin al vector from `pos' to end, l eaving | |
2449 | // a n empty ro om at `pos ' in the n ew vector. | |
2450 | if ( l2 > 0) | |
2451 | java.lang. System.arr aycopy(old e,l1,table oids, | |
2452 | l1+ 1,l2); | |
2453 | ||
2454 | } else i f (pos < t ablecount) { | |
2455 | // V ector is l arge enoug h to accom modate one additiona l | |
2456 | // e ntry. | |
2457 | // | |
2458 | // S hift vecto r, making an empty r oom at `po s' | |
2459 | ||
2460 | java .lang.Syst em.arrayco py(tableoi ds,pos,tab leoids, | |
2461 | pos+1,t ablecount- pos); | |
2462 | } | |
2463 | ||
2464 | // Fill the gap at `pos' | |
2465 | tableoid s[pos] = oid; | |
2466 | tablecou nt++; | |
2467 | } | |
2468 | ||
2469 | ||
2470 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------- | |
2471 | // PRO TECTED VAR IABLES | |
2472 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------- | |
2473 | ||
2474 | /** | |
2475 | * The id of the contained entry obj ect. | |
2476 | * @se rial | |
2477 | */ | |
2478 | protec ted int no deId=1; | |
2479 | ||
2480 | /** | |
2481 | * The MIB to wh ich the me tadata is linked. | |
2482 | * @se rial | |
2483 | */ | |
2484 | protec ted SnmpMi b theMib; | |
2485 | ||
2486 | /** | |
2487 | * <CO DE>true</C ODE> if re mote creat ion of ent ries via S ET operati ons | |
2488 | * is enabled. | |
2489 | * [de fault valu e is <CODE >false</CO DE>] | |
2490 | * @se rial | |
2491 | */ | |
2492 | protec ted boolea n creation Enabled = false; | |
2493 | ||
2494 | /** | |
2495 | * The entry fac tory | |
2496 | */ | |
2497 | protec ted SnmpTa bleEntryFa ctory fact ory = null ; | |
2498 | ||
2499 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------- | |
2500 | // PRI VATE VARIA BLES | |
2501 | // --- ---------- ---------- ---------- ---------- ---------- ---------- ------- | |
2502 | ||
2503 | /** | |
2504 | * The number of elements in the tab le. | |
2505 | * @se rial | |
2506 | */ | |
2507 | privat e int size =0; | |
2508 | ||
2509 | /** | |
2510 | * The list of i ndexes. | |
2511 | * @se rial | |
2512 | */ | |
2513 | // private Ve ctor index es= new Ve ctor(); | |
2514 | ||
2515 | /** | |
2516 | * The list of O IDs. | |
2517 | * @se rial | |
2518 | */ | |
2519 | // pri vate Vecto r oids= ne w Vector() ; | |
2520 | privat e final st atic int D elta = 16; | |
2521 | privat e int tablecount = 0; | |
2522 | privat e int tablesize = Del ta; | |
2523 | privat e SnmpOid tableoids[ ] = new SnmpOid[t ablesize]; | |
2524 | ||
2525 | /** | |
2526 | * The list of e ntries. | |
2527 | * @se rial | |
2528 | */ | |
2529 | privat e final Ve ctor<Objec t> entries = new Vect or<>(); | |
2530 | ||
2531 | /** | |
2532 | * The list of o bject name s. | |
2533 | * @se rial | |
2534 | */ | |
2535 | privat e final Ve ctor<Objec tName> ent rynames= n ew Vector< >(); | |
2536 | ||
2537 | /** | |
2538 | * Cal lback hand lers | |
2539 | */ | |
2540 | // fin al Vector callbacks = new Vect or(); | |
2541 | ||
2542 | /** | |
2543 | * Lis tener hash table cont aining the hand-back objects. | |
2544 | */ | |
2545 | privat e Hashtabl e<Notifica tionListen er, Vector <Object>> handbackTa ble = | |
2546 | new Hash table<>(); | |
2547 | ||
2548 | /** | |
2549 | * Lis tener hash table cont aining the filter ob jects. | |
2550 | */ | |
2551 | privat e Hashtabl e<Notifica tionListen er, Vector <Notificat ionFilter> > | |
2552 | filterTa ble = new Hashtable< >(); | |
2553 | ||
2554 | // PAC KAGE VARIA BLES | |
2555 | //---- ---------- ---- | |
2556 | /** | |
2557 | * SNM P table se quence num ber. | |
2558 | * The default v alue is se t to 0. | |
2559 | */ | |
2560 | transi ent long s equenceNum ber = 0; | |
2561 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.