Produced by Araxis Merge on 9/25/2018 2:13:11 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\javax\management\monitor | CounterMonitor.java | Mon Jan 22 14:46:52 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\javax\management\monitor | CounterMonitor.java | Wed Sep 12 17:20:30 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 1960 |
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 9, 2008, 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 ja vax.manage ment.monit or; | |
27 | ||
28 | import sta tic com.su n.jmx.defa ults.JmxPr operties.M ONITOR_LOG GER; | |
29 | import jav a.util.log ging.Level ; | |
30 | import jav ax.managem ent.Object Name; | |
31 | import jav ax.managem ent.MBeanN otificatio nInfo; | |
32 | import sta tic javax. management .monitor.M onitor.Num ericalType .*; | |
33 | import sta tic javax. management .monitor.M onitorNoti fication.* ; | |
34 | ||
35 | /** | |
36 | * Defines a monitor MBean des igned to o bserve the values of a counter | |
37 | * attribu te. | |
38 | * | |
39 | * <P> A c ounter mon itor sends a {@link | |
40 | * Monitor Notificati on#THRESHO LD_VALUE_E XCEEDED th reshold | |
41 | * notific ation} whe n the valu e of the c ounter rea ches or ex ceeds a | |
42 | * thresho ld known a s the comp arison lev el. The n otify flag must be | |
43 | * set to <CODE>true </CODE>. | |
44 | * | |
45 | * <P> In addition, an offset mechanism enables pa rticular c ounting | |
46 | * interva ls to be d etected. If the off set value is not zer o, | |
47 | * wheneve r the thre shold is t riggered b y the coun ter value reaching a | |
48 | * compari son level, that comp arison lev el is incr emented by the | |
49 | * offset value. Th is is rega rded as ta king place instantan eously, | |
50 | * that is , before t he count i s incremen ted. Thus , for each level, | |
51 | * the thr eshold tri ggers an e vent notif ication ev ery time t he count | |
52 | * increas es by an i nterval eq ual to the offset va lue. | |
53 | * | |
54 | * <P> If the counte r can wrap around it s maximum value, the modulus | |
55 | * needs t o be speci fied. The modulus i s the valu e at which the | |
56 | * counter is reset to zero. | |
57 | * | |
58 | * <P> If the counte r differen ce mode is used, the value of the | |
59 | * derived gauge is calculated as the di fference b etween the observed | |
60 | * counter values fo r two succ essive obs ervations. If this difference | |
61 | * is nega tive, the value of t he derived gauge is incremente d by the | |
62 | * value o f the modu lus. The derived ga uge value (V[t]) is calculated | |
63 | * using t he followi ng method: | |
64 | * | |
65 | * <UL> | |
66 | * <LI>if (counter[t ] - counte r[t-GP]) i s positive then | |
67 | * V[t] = counter[t] - counter [t-GP] | |
68 | * <LI>if (counter[t ] - counte r[t-GP]) i s negative then | |
69 | * V[t] = counter[t] - counter [t-GP] + M ODULUS | |
70 | * </UL> | |
71 | * | |
72 | * This im plementati on of the counter mo nitor requ ires the o bserved | |
73 | * attribu te to be o f the type integer ( <CODE>Byte </CODE>, | |
74 | * <CODE>I nteger</CO DE>, <CODE >Short</CO DE>, <CODE >Long</COD E>). | |
75 | * | |
76 | * | |
77 | * @since 1.5 | |
78 | */ | |
79 | public cla ss Counter Monitor ex tends Moni tor implem ents Count erMonitorM Bean { | |
80 | ||
81 | /* | |
82 | * --- ---------- ---------- ---------- --------- | |
83 | * PA CKAGE CLAS SES | |
84 | * --- ---------- ---------- ---------- --------- | |
85 | */ | |
86 | ||
87 | static class Cou nterMonito rObservedO bject exte nds Observ edObject { | |
88 | ||
89 | pu blic Count erMonitorO bservedObj ect(Object Name obser vedObject) { | |
90 | super(ob servedObje ct); | |
91 | } | |
92 | ||
93 | pu blic final synchroni zed Number getThresh old() { | |
94 | return t hreshold; | |
95 | } | |
96 | pu blic final synchroni zed void s etThreshol d(Number t hreshold) { | |
97 | this.thr eshold = t hreshold; | |
98 | } | |
99 | pu blic final synchroni zed Number getPrevio usScanCoun ter() { | |
100 | return p reviousSca nCounter; | |
101 | } | |
102 | pu blic final synchroni zed void s etPrevious ScanCounte r( | |
103 | Number pre viousScanC ounter) { | |
104 | this.pre viousScanC ounter = p reviousSca nCounter; | |
105 | } | |
106 | pu blic final synchroni zed boolea n getModul usExceeded () { | |
107 | return m odulusExce eded; | |
108 | } | |
109 | pu blic final synchroni zed void s etModulusE xceeded( | |
110 | b oolean mod ulusExceed ed) { | |
111 | this.mod ulusExceed ed = modul usExceeded ; | |
112 | } | |
113 | pu blic final synchroni zed Number getDerive dGaugeExce eded() { | |
114 | return d erivedGaug eExceeded; | |
115 | } | |
116 | pu blic final synchroni zed void s etDerivedG augeExceed ed( | |
117 | N umber deri vedGaugeEx ceeded) { | |
118 | this.der ivedGaugeE xceeded = derivedGau geExceeded ; | |
119 | } | |
120 | pu blic final synchroni zed boolea n getDeriv edGaugeVal id() { | |
121 | return d erivedGaug eValid; | |
122 | } | |
123 | pu blic final synchroni zed void s etDerivedG augeValid( | |
124 | b oolean der ivedGaugeV alid) { | |
125 | this.der ivedGaugeV alid = der ivedGaugeV alid; | |
126 | } | |
127 | pu blic final synchroni zed boolea n getEvent AlreadyNot ified() { | |
128 | return e ventAlread yNotified; | |
129 | } | |
130 | pu blic final synchroni zed void s etEventAlr eadyNotifi ed( | |
131 | boo lean event AlreadyNot ified) { | |
132 | this.eve ntAlreadyN otified = eventAlrea dyNotified ; | |
133 | } | |
134 | pu blic final synchroni zed Numeri calType ge tType() { | |
135 | return t ype; | |
136 | } | |
137 | pu blic final synchroni zed void s etType(Num ericalType type) { | |
138 | this.typ e = type; | |
139 | } | |
140 | ||
141 | pr ivate Numb er thresho ld; | |
142 | pr ivate Numb er previou sScanCount er; | |
143 | pr ivate bool ean modulu sExceeded; | |
144 | pr ivate Numb er derived GaugeExcee ded; | |
145 | pr ivate bool ean derive dGaugeVali d; | |
146 | pr ivate bool ean eventA lreadyNoti fied; | |
147 | pr ivate Nume ricalType type; | |
148 | } | |
149 | ||
150 | /* | |
151 | * --- ---------- ---------- ---------- --------- | |
152 | * PR IVATE VARI ABLES | |
153 | * --- ---------- ---------- ---------- --------- | |
154 | */ | |
155 | ||
156 | /** | |
157 | * Cou nter modul us. | |
158 | * <BR >The defau lt value i s a null I nteger obj ect. | |
159 | */ | |
160 | privat e Number m odulus = I NTEGER_ZER O; | |
161 | ||
162 | /** | |
163 | * Cou nter offse t. | |
164 | * <BR >The defau lt value i s a null I nteger obj ect. | |
165 | */ | |
166 | privat e Number o ffset = IN TEGER_ZERO ; | |
167 | ||
168 | /** | |
169 | * Fla g indicati ng if the counter mo nitor noti fies when exceeding | |
170 | * the threshold . The def ault value is set to | |
171 | * <CO DE>false</ CODE>. | |
172 | */ | |
173 | privat e boolean notify = f alse; | |
174 | ||
175 | /** | |
176 | * Fla g indicati ng if the counter di fference m ode is use d. If the | |
177 | * cou nter diffe rence mode is used, the derive d gauge is the | |
178 | * dif ference be tween two consecutiv e observed values. Otherwise, | |
179 | * the derived g auge is di rectly the value of the observ ed | |
180 | * att ribute. T he default value is set to <CO DE>false</ CODE>. | |
181 | */ | |
182 | privat e boolean difference Mode = fal se; | |
183 | ||
184 | /** | |
185 | * Ini tial count er thresho ld. This value is u sed to ini tialize | |
186 | * the threshold when a ne w object i s added to the list and reset | |
187 | * the threshold to its in itial valu e each tim e the coun ter | |
188 | * res ets. | |
189 | */ | |
190 | privat e Number i nitThresho ld = INTEG ER_ZERO; | |
191 | ||
192 | privat e static f inal Strin g[] types = { | |
193 | RU NTIME_ERRO R, | |
194 | OB SERVED_OBJ ECT_ERROR, | |
195 | OB SERVED_ATT RIBUTE_ERR OR, | |
196 | OB SERVED_ATT RIBUTE_TYP E_ERROR, | |
197 | TH RESHOLD_ER ROR, | |
198 | TH RESHOLD_VA LUE_EXCEED ED | |
199 | }; | |
200 | ||
201 | privat e static f inal MBean Notificati onInfo[] n otifsInfo = { | |
202 | ne w MBeanNot ificationI nfo( | |
203 | types, | |
204 | "javax.m anagement. monitor.Mo nitorNotif ication", | |
205 | "Notific ations sen t by the C ounterMoni tor MBean" ) | |
206 | }; | |
207 | ||
208 | /* | |
209 | * --- ---------- ---------- ---------- --------- | |
210 | * CO NSTRUCTORS | |
211 | * --- ---------- ---------- ---------- --------- | |
212 | */ | |
213 | ||
214 | /** | |
215 | * Def ault const ructor. | |
216 | */ | |
217 | public CounterMo nitor() { | |
218 | } | |
219 | ||
220 | /* | |
221 | * --- ---------- ---------- ---------- --------- | |
222 | * PU BLIC METHO DS | |
223 | * --- ---------- ---------- ---------- --------- | |
224 | */ | |
225 | ||
226 | /** | |
227 | * Sta rts the co unter moni tor. | |
228 | */ | |
229 | public synchroni zed void s tart() { | |
230 | if (isActive ()) { | |
231 | MONITOR_ LOGGER.log p(Level.FI NER, Count erMonitor. class.getN ame(), | |
232 | "start", " the monito r is alrea dy active" ); | |
233 | return; | |
234 | } | |
235 | // Reset val ues. | |
236 | // | |
237 | fo r (Observe dObject o : observed Objects) { | |
238 | final Co unterMonit orObserved Object cmo = | |
239 | (Cou nterMonito rObservedO bject) o; | |
240 | cmo.setT hreshold(i nitThresho ld); | |
241 | cmo.setM odulusExce eded(false ); | |
242 | cmo.setE ventAlread yNotified( false); | |
243 | cmo.setP reviousSca nCounter(n ull); | |
244 | } | |
245 | do Start(); | |
246 | } | |
247 | ||
248 | /** | |
249 | * Sto ps the cou nter monit or. | |
250 | */ | |
251 | public synchroni zed void s top() { | |
252 | do Stop(); | |
253 | } | |
254 | ||
255 | // GET TERS AND S ETTERS | |
256 | //---- ---------- ------ | |
257 | ||
258 | /** | |
259 | * Get s the deri ved gauge of the spe cified obj ect, if th is object is | |
260 | * con tained in the set of observed MBeans, or <code>nul l</code> o therwise. | |
261 | * | |
262 | * @pa ram object the name of the obj ect whose derived ga uge is to | |
263 | * be returned. | |
264 | * | |
265 | * @re turn The d erived gau ge of the specified object. | |
266 | * | |
267 | */ | |
268 | @Overr ide | |
269 | public synchroni zed Number getDerive dGauge(Obj ectName ob ject) { | |
270 | re turn (Numb er) super. getDerived Gauge(obje ct); | |
271 | } | |
272 | ||
273 | /** | |
274 | * Get s the deri ved gauge timestamp of the spe cified obj ect, if | |
275 | * thi s object i s containe d in the s et of obse rved MBean s, or | |
276 | * <co de>0</code > otherwis e. | |
277 | * | |
278 | * @pa ram object the name of the obj ect whose derived ga uge | |
279 | * tim estamp is to be retu rned. | |
280 | * | |
281 | * @re turn The d erived gau ge timesta mp of the specified object. | |
282 | * | |
283 | */ | |
284 | @Overr ide | |
285 | public synchroni zed long g etDerivedG augeTimeSt amp(Object Name objec t) { | |
286 | re turn super .getDerive dGaugeTime Stamp(obje ct); | |
287 | } | |
288 | ||
289 | /** | |
290 | * Get s the curr ent thresh old value of the spe cified obj ect, if | |
291 | * thi s object i s containe d in the s et of obse rved MBean s, or | |
292 | * <co de>null</c ode> other wise. | |
293 | * | |
294 | * @pa ram object the name of the obj ect whose threshold is to be | |
295 | * ret urned. | |
296 | * | |
297 | * @re turn The t hreshold v alue of th e specifie d object. | |
298 | * | |
299 | */ | |
300 | public synchroni zed Number getThresh old(Object Name objec t) { | |
301 | fi nal Counte rMonitorOb servedObje ct o = | |
302 | (Counter MonitorObs ervedObjec t) getObse rvedObject (object); | |
303 | if (o == nul l) | |
304 | return n ull; | |
305 | ||
306 | // If the co unter that is monito red rolls over when it reaches a | |
307 | // maximum v alue, then the modul us value n eeds to be set to th at | |
308 | // maximum v alue. The threshold will then also roll over whene ver | |
309 | // it strict ly exceeds the modul us value. When the t hreshold r olls | |
310 | // over, it is reset t o the valu e that was specified through t he | |
311 | // latest ca ll to the monitor's setInitThr eshold met hod, befor e | |
312 | // any offse ts were ap plied. | |
313 | // | |
314 | if (offset.l ongValue() > 0L && | |
315 | modulus. longValue( ) > 0L && | |
316 | o.getThr eshold().l ongValue() > modulus .longValue ()) { | |
317 | return i nitThresho ld; | |
318 | } else { | |
319 | return o .getThresh old(); | |
320 | } | |
321 | } | |
322 | ||
323 | /** | |
324 | * Get s the init ial thresh old value common to all observ ed objects . | |
325 | * | |
326 | * @re turn The i nitial thr eshold. | |
327 | * | |
328 | * @se e #setInit Threshold | |
329 | * | |
330 | */ | |
331 | public synchroni zed Number getInitTh reshold() { | |
332 | re turn initT hreshold; | |
333 | } | |
334 | ||
335 | /** | |
336 | * Set s the init ial thresh old value common to all observ ed objects . | |
337 | * | |
338 | * <BR >The curre nt thresho ld of ever y object i n the set of | |
339 | * obs erved MBea ns is upda ted conseq uently. | |
340 | * | |
341 | * @pa ram value The initia l threshol d value. | |
342 | * | |
343 | * @ex ception Il legalArgum entExcepti on The spe cified | |
344 | * thr eshold is null or th e threshol d value is less than zero. | |
345 | * | |
346 | * @se e #getInit Threshold | |
347 | * | |
348 | */ | |
349 | public synchroni zed void s etInitThre shold(Numb er value) | |
350 | th rows Illeg alArgument Exception { | |
351 | ||
352 | if (value == null) { | |
353 | throw ne w IllegalA rgumentExc eption("Nu ll thresho ld"); | |
354 | } | |
355 | if (value.lo ngValue() < 0L) { | |
356 | throw ne w IllegalA rgumentExc eption("Ne gative thr eshold"); | |
357 | } | |
358 | ||
359 | if (initThre shold.equa ls(value)) | |
360 | return; | |
361 | in itThreshol d = value; | |
362 | ||
363 | // Reset val ues. | |
364 | // | |
365 | in t index = 0; | |
366 | fo r (Observe dObject o : observed Objects) { | |
367 | resetAlr eadyNotifi ed(o, inde x++, THRES HOLD_ERROR _NOTIFIED) ; | |
368 | final Co unterMonit orObserved Object cmo = | |
369 | (Cou nterMonito rObservedO bject) o; | |
370 | cmo.setT hreshold(v alue); | |
371 | cmo.setM odulusExce eded(false ); | |
372 | cmo.setE ventAlread yNotified( false); | |
373 | } | |
374 | } | |
375 | ||
376 | /** | |
377 | * Ret urns the d erived gau ge of the first obje ct in the set of | |
378 | * obs erved MBea ns. | |
379 | * | |
380 | * @re turn The d erived gau ge. | |
381 | * | |
382 | * @de precated A s of JMX 1 .2, replac ed by | |
383 | * {@l ink #getDe rivedGauge (ObjectNam e)} | |
384 | */ | |
385 | @Depre cated | |
386 | public synchroni zed Number getDerive dGauge() { | |
387 | if (observed Objects.is Empty()) { | |
388 | return n ull; | |
389 | } else { | |
390 | return ( Number) ob servedObje cts.get(0) .getDerive dGauge(); | |
391 | } | |
392 | } | |
393 | ||
394 | /** | |
395 | * Get s the deri ved gauge timestamp of the fir st object in the set | |
396 | * of observed M Beans. | |
397 | * | |
398 | * @re turn The d erived gau ge timesta mp. | |
399 | * | |
400 | * @de precated A s of JMX 1 .2, replac ed by | |
401 | * {@l ink #getDe rivedGauge TimeStamp( ObjectName )} | |
402 | */ | |
403 | @Depre cated | |
404 | public synchroni zed long g etDerivedG augeTimeSt amp() { | |
405 | if (observed Objects.is Empty()) { | |
406 | return 0 ; | |
407 | } else { | |
408 | return o bservedObj ects.get(0 ).getDeriv edGaugeTim eStamp(); | |
409 | } | |
410 | } | |
411 | ||
412 | /** | |
413 | * Get s the thre shold valu e of the f irst objec t in the s et of | |
414 | * obs erved MBea ns. | |
415 | * | |
416 | * @re turn The t hreshold v alue. | |
417 | * | |
418 | * @se e #setThre shold | |
419 | * | |
420 | * @de precated A s of JMX 1 .2, replac ed by {@li nk #getThr eshold(Obj ectName)} | |
421 | */ | |
422 | @Depre cated | |
423 | public synchroni zed Number getThresh old() { | |
424 | re turn getTh reshold(ge tObservedO bject()); | |
425 | } | |
426 | ||
427 | /** | |
428 | * Set s the init ial thresh old value. | |
429 | * | |
430 | * @pa ram value The initia l threshol d value. | |
431 | * | |
432 | * @ex ception Il legalArgum entExcepti on The spe cified thr eshold is | |
433 | * nul l or the t hreshold v alue is le ss than ze ro. | |
434 | * | |
435 | * @se e #getThre shold() | |
436 | * | |
437 | * @de precated A s of JMX 1 .2, replac ed by {@li nk #setIni tThreshold } | |
438 | */ | |
439 | @Depre cated | |
440 | public synchroni zed void s etThreshol d(Number v alue) | |
441 | th rows Illeg alArgument Exception { | |
442 | se tInitThres hold(value ); | |
443 | } | |
444 | ||
445 | /** | |
446 | * Get s the offs et value c ommon to a ll observe d MBeans. | |
447 | * | |
448 | * @re turn The o ffset valu e. | |
449 | * | |
450 | * @se e #setOffs et | |
451 | */ | |
452 | public synchroni zed Number getOffset () { | |
453 | re turn offse t; | |
454 | } | |
455 | ||
456 | /** | |
457 | * Set s the offs et value c ommon to a ll observe d MBeans. | |
458 | * | |
459 | * @pa ram value The offset value. | |
460 | * | |
461 | * @ex ception Il legalArgum entExcepti on The spe cified | |
462 | * off set is nul l or the o ffset valu e is less than zero. | |
463 | * | |
464 | * @se e #getOffs et | |
465 | */ | |
466 | public synchroni zed void s etOffset(N umber valu e) | |
467 | th rows Illeg alArgument Exception { | |
468 | ||
469 | if (value == null) { | |
470 | throw ne w IllegalA rgumentExc eption("Nu ll offset" ); | |
471 | } | |
472 | if (value.lo ngValue() < 0L) { | |
473 | throw ne w IllegalA rgumentExc eption("Ne gative off set"); | |
474 | } | |
475 | ||
476 | if (offset.e quals(valu e)) | |
477 | return; | |
478 | of fset = val ue; | |
479 | ||
480 | in t index = 0; | |
481 | fo r (Observe dObject o : observed Objects) { | |
482 | resetAlr eadyNotifi ed(o, inde x++, THRES HOLD_ERROR _NOTIFIED) ; | |
483 | } | |
484 | } | |
485 | ||
486 | /** | |
487 | * Get s the modu lus value common to all observ ed MBeans. | |
488 | * | |
489 | * @se e #setModu lus | |
490 | * | |
491 | * @re turn The m odulus val ue. | |
492 | */ | |
493 | public synchroni zed Number getModulu s() { | |
494 | re turn modul us; | |
495 | } | |
496 | ||
497 | /** | |
498 | * Set s the modu lus value common to all observ ed MBeans. | |
499 | * | |
500 | * @pa ram value The modulu s value. | |
501 | * | |
502 | * @ex ception Il legalArgum entExcepti on The spe cified | |
503 | * mod ulus is nu ll or the modulus va lue is les s than zer o. | |
504 | * | |
505 | * @se e #getModu lus | |
506 | */ | |
507 | public synchroni zed void s etModulus( Number val ue) | |
508 | th rows Illeg alArgument Exception { | |
509 | ||
510 | if (value == null) { | |
511 | throw ne w IllegalA rgumentExc eption("Nu ll modulus "); | |
512 | } | |
513 | if (value.lo ngValue() < 0L) { | |
514 | throw ne w IllegalA rgumentExc eption("Ne gative mod ulus"); | |
515 | } | |
516 | ||
517 | if (modulus. equals(val ue)) | |
518 | return; | |
519 | mo dulus = va lue; | |
520 | ||
521 | // Reset val ues. | |
522 | // | |
523 | in t index = 0; | |
524 | fo r (Observe dObject o : observed Objects) { | |
525 | resetAlr eadyNotifi ed(o, inde x++, THRES HOLD_ERROR _NOTIFIED) ; | |
526 | final Co unterMonit orObserved Object cmo = | |
527 | (Cou nterMonito rObservedO bject) o; | |
528 | cmo.setM odulusExce eded(false ); | |
529 | } | |
530 | } | |
531 | ||
532 | /** | |
533 | * Get s the noti fication's on/off sw itch value common to all | |
534 | * obs erved MBea ns. | |
535 | * | |
536 | * @re turn <CODE >true</COD E> if the counter mo nitor noti fies when | |
537 | * exc eeding the threshold , <CODE>fa lse</CODE> otherwise . | |
538 | * | |
539 | * @se e #setNoti fy | |
540 | */ | |
541 | public synchroni zed boolea n getNotif y() { | |
542 | re turn notif y; | |
543 | } | |
544 | ||
545 | /** | |
546 | * Set s the noti fication's on/off sw itch value common to all | |
547 | * obs erved MBea ns. | |
548 | * | |
549 | * @pa ram value The notifi cation's o n/off swit ch value. | |
550 | * | |
551 | * @se e #getNoti fy | |
552 | */ | |
553 | public synchroni zed void s etNotify(b oolean val ue) { | |
554 | if (notify = = value) | |
555 | return; | |
556 | no tify = val ue; | |
557 | } | |
558 | ||
559 | /** | |
560 | * Get s the diff erence mod e flag val ue common to all obs erved MBea ns. | |
561 | * | |
562 | * @re turn <CODE >true</COD E> if the difference mode is u sed, | |
563 | * <CO DE>false</ CODE> othe rwise. | |
564 | * | |
565 | * @se e #setDiff erenceMode | |
566 | */ | |
567 | public synchroni zed boolea n getDiffe renceMode( ) { | |
568 | re turn diffe renceMode; | |
569 | } | |
570 | ||
571 | /** | |
572 | * Set s the diff erence mod e flag val ue common to all obs erved MBea ns. | |
573 | * | |
574 | * @pa ram value The differ ence mode flag value . | |
575 | * | |
576 | * @se e #getDiff erenceMode | |
577 | */ | |
578 | public synchroni zed void s etDifferen ceMode(boo lean value ) { | |
579 | if (differen ceMode == value) | |
580 | return; | |
581 | di fferenceMo de = value ; | |
582 | ||
583 | // Reset val ues. | |
584 | // | |
585 | fo r (Observe dObject o : observed Objects) { | |
586 | final Co unterMonit orObserved Object cmo = | |
587 | (Cou nterMonito rObservedO bject) o; | |
588 | cmo.setT hreshold(i nitThresho ld); | |
589 | cmo.setM odulusExce eded(false ); | |
590 | cmo.setE ventAlread yNotified( false); | |
591 | cmo.setP reviousSca nCounter(n ull); | |
592 | } | |
593 | } | |
594 | ||
595 | /** | |
596 | * Ret urns a <CO DE>Notific ationInfo< /CODE> obj ect contai ning the | |
597 | * nam e of the J ava class of the not ification and the no tification | |
598 | * typ es sent by the count er monitor . | |
599 | */ | |
600 | @Overr ide | |
601 | public MBeanNoti ficationIn fo[] getNo tification Info() { | |
602 | re turn notif sInfo.clon e(); | |
603 | } | |
604 | ||
605 | /* | |
606 | * --- ---------- ---------- ---------- --------- | |
607 | * PRI D A N E S M T ODS | |
608 | * --- ---------- ---------- ---------- --------- | |
609 | */ | |
610 | ||
611 | /** | |
612 | * Upd ates the d erived gau ge attribu te of the observed o bject. | |
613 | * | |
614 | * @pa ram scanCo unter The value of t he observe d attribut e. | |
615 | * @pa ram o The observed o bject. | |
616 | * @re turn <CODE >true</COD E> if the derived ga uge value is valid, | |
617 | * <CO DE>false</ CODE> othe rwise. Th e derived gauge valu e is | |
618 | * inv alid when the differ enceMode f lag is set to | |
619 | * <CO DE>true</C ODE> and i t is the f irst notif ication (s o we | |
620 | * hav en't 2 con secutive v alues to u pdate the derived ga uge). | |
621 | */ | |
622 | privat e synchron ized boole an updateD erivedGaug e( | |
623 | Ob ject scanC ounter, Co unterMonit orObserved Object o) { | |
624 | ||
625 | bo olean is_d erived_gau ge_valid; | |
626 | ||
627 | // The count er differe nce mode i s used. | |
628 | // | |
629 | if (differen ceMode) { | |
630 | ||
631 | // The p revious sc an counter has been initialize d. | |
632 | // | |
633 | if (o.ge tPreviousS canCounter () != null ) { | |
634 | setD erivedGaug eWithDiffe rence((Num ber)scanCo unter, nul l, o); | |
635 | ||
636 | // I f derived gauge is n egative it means tha t the | |
637 | // c ounter has wrapped a round and the value of the | |
638 | // t hreshold n eeds to be reset to its initia l value. | |
639 | // | |
640 | if ( ((Number)o .getDerive dGauge()). longValue( ) < 0L) { | |
641 | if (modulu s.longValu e() > 0L) { | |
642 | setDer ivedGaugeW ithDiffere nce((Numbe r)scanCoun ter, | |
643 | modulu s, o); | |
644 | } | |
645 | o.setThres hold(initT hreshold); | |
646 | o.setEvent AlreadyNot ified(fals e); | |
647 | } | |
648 | is_d erived_gau ge_valid = true; | |
649 | } | |
650 | // The p revious sc an counter has not b een initia lized. | |
651 | // We ca nnot updat e the deri ved gauge. .. | |
652 | // | |
653 | else { | |
654 | is_d erived_gau ge_valid = false; | |
655 | } | |
656 | o.setPre viousScanC ounter((Nu mber)scanC ounter); | |
657 | } | |
658 | // The count er differe nce mode i s not used . | |
659 | // | |
660 | el se { | |
661 | o.setDer ivedGauge( (Number)sc anCounter) ; | |
662 | is_deriv ed_gauge_v alid = tru e; | |
663 | } | |
664 | re turn is_de rived_gaug e_valid; | |
665 | } | |
666 | ||
667 | /** | |
668 | * Upd ates the n otificatio n attribut e of the o bserved ob ject | |
669 | * and notifies the listen ers only o nce if the notify fl ag | |
670 | * is set to <CO DE>true</C ODE>. | |
671 | * @pa ram o The observed o bject. | |
672 | */ | |
673 | privat e synchron ized Monit orNotifica tion updat eNotificat ions( | |
674 | Co unterMonit orObserved Object o) { | |
675 | ||
676 | Mo nitorNotif ication n = null; | |
677 | ||
678 | // Send noti fication i f notify i s true. | |
679 | // | |
680 | if (!o.getEv entAlready Notified() ) { | |
681 | if (((Nu mber)o.get DerivedGau ge()).long Value() >= | |
682 | o.ge tThreshold ().longVal ue()) { | |
683 | if ( notify) { | |
684 | n = new Mo nitorNotif ication(TH RESHOLD_VA LUE_EXCEED ED, | |
685 | th is, | |
686 | 0, | |
687 | 0, | |
688 | "" , | |
689 | nu ll, | |
690 | nu ll, | |
691 | nu ll, | |
692 | o. getThresho ld()); | |
693 | } | |
694 | if ( !differenc eMode) { | |
695 | o.setEvent AlreadyNot ified(true ); | |
696 | } | |
697 | } | |
698 | } else { | |
699 | if (MONI TOR_LOGGER .isLoggabl e(Level.FI NER)) { | |
700 | fina l StringBu ilder strb = new Str ingBuilder () | |
701 | .app end("The n otificatio n:") | |
702 | .app end("\n\tN otificatio n observed object = ") | |
703 | .app end(o.getO bservedObj ect()) | |
704 | .app end("\n\tN otificatio n observed attribute = ") | |
705 | .app end(getObs ervedAttri bute()) | |
706 | .app end("\n\tN otificatio n threshol d level = ") | |
707 | .app end(o.getT hreshold() ) | |
708 | .app end("\n\tN otificatio n derived gauge = ") | |
709 | .app end(o.getD erivedGaug e()) | |
710 | .app end("\nhas already b een sent") ; | |
711 | MONI TOR_LOGGER .logp(Leve l.FINER, C ounterMoni tor.class. getName(), | |
712 | "updat eNotificat ions", str b.toString ()); | |
713 | } | |
714 | } | |
715 | ||
716 | re turn n; | |
717 | } | |
718 | ||
719 | /** | |
720 | * Upd ates the t hreshold a ttribute o f the obse rved objec t. | |
721 | * @pa ram o The observed o bject. | |
722 | */ | |
723 | privat e synchron ized void updateThre shold(Coun terMonitor ObservedOb ject o) { | |
724 | ||
725 | // Calculate the new t hreshold v alue if th e threshol d has been | |
726 | // exceeded and if the offset va lue is gre ater than zero. | |
727 | // | |
728 | if (((Number )o.getDeri vedGauge() ).longValu e() >= | |
729 | o.getThr eshold().l ongValue() ) { | |
730 | ||
731 | if (offs et.longVal ue() > 0L) { | |
732 | ||
733 | // I ncrement t he thresho ld until i ts value i s greater | |
734 | // t han the on e for the current de rived gaug e. | |
735 | // | |
736 | long threshold _value = o .getThresh old().long Value(); | |
737 | whil e (((Numbe r)o.getDer ivedGauge( )).longVal ue() >= | |
738 | thresho ld_value) { | |
739 | threshold_ value += o ffset.long Value(); | |
740 | } | |
741 | ||
742 | // S et thresho ld attribu te. | |
743 | // | |
744 | swit ch (o.getT ype()) { | |
745 | case INTEG ER: | |
746 | o.setT hreshold(I nteger.val ueOf((int) threshold_ value)); | |
747 | break; | |
748 | case BYTE: | |
749 | o.setT hreshold(B yte.valueO f((byte)th reshold_va lue)); | |
750 | break; | |
751 | case SHORT : | |
752 | o.setT hreshold(S hort.value Of((short) threshold_ value)); | |
753 | break; | |
754 | case LONG: | |
755 | o.setT hreshold(L ong.valueO f(threshol d_value)); | |
756 | break; | |
757 | default: | |
758 | // Sho uld never occur... | |
759 | MONITO R_LOGGER.l ogp(Level. FINEST, | |
760 | CounterM onitor.cla ss.getName (), | |
761 | "updateT hreshold", | |
762 | "the thr eshold typ e is inval id"); | |
763 | break; | |
764 | } | |
765 | ||
766 | // I f the coun ter can wr ap around when it re aches | |
767 | // i ts maximum and we ar e not deal ing with c ounter | |
768 | // d ifferences then we n eed to res et the thr eshold | |
769 | // t o its init ial value too. | |
770 | // | |
771 | if ( !differenc eMode) { | |
772 | if (modulu s.longValu e() > 0L) { | |
773 | if (o. getThresho ld().longV alue() > | |
774 | mo dulus.long Value()) { | |
775 | o. setModulus Exceeded(t rue); | |
776 | o. setDerived GaugeExcee ded( | |
777 | (Number) o.getDeri vedGauge() ); | |
778 | } | |
779 | } | |
780 | } | |
781 | ||
782 | // T hreshold v alue has b een modifi ed so we c an notify again. | |
783 | // | |
784 | o.se tEventAlre adyNotifie d(false); | |
785 | } else { | |
786 | o.se tModulusEx ceeded(tru e); | |
787 | o.se tDerivedGa ugeExceede d((Number) o.getDeri vedGauge() ); | |
788 | } | |
789 | } | |
790 | } | |
791 | ||
792 | /** | |
793 | * Set s the deri ved gauge of the spe cified obs erved obje ct when th e | |
794 | * dif ferenceMod e flag is set to <CO DE>true</C ODE>. Int eger types | |
795 | * onl y are allo wed. | |
796 | * | |
797 | * @pa ram scanCo unter The value of t he observe d attribut e. | |
798 | * @pa ram mod Th e counter modulus va lue. | |
799 | * @pa ram o The observed o bject. | |
800 | */ | |
801 | privat e synchron ized void setDerived GaugeWithD ifference( | |
802 | Nu mber scanC ounter, Nu mber mod, CounterMon itorObserv edObject o ) { | |
803 | /* We do the arithmeti c using lo ngs here e ven though the | |
804 | result ma y end up i n a smalle r type. S ince | |
805 | l == (byt e)l (mod 2 56) for an y long l, | |
806 | (byte) (( byte)l1 + (byte)l2) == (byte) (l1 + l2), | |
807 | and likew ise for su btraction. So it's the same a s if | |
808 | we had do ne the ari thmetic in the small er type.*/ | |
809 | ||
810 | lo ng derived = | |
811 | scanCoun ter.longVa lue() - o. getPreviou sScanCount er().longV alue(); | |
812 | if (mod != n ull) | |
813 | derived += modulus .longValue (); | |
814 | ||
815 | sw itch (o.ge tType()) { | |
816 | ca se INTEGER : o.setDer ivedGauge( Integer.va lueOf((int ) derived) ); break; | |
817 | ca se BYTE: o .setDerive dGauge(Byt e.valueOf( (byte) der ived)); br eak; | |
818 | ca se SHORT: o.setDeriv edGauge(Sh ort.valueO f((short) derived)); break; | |
819 | ca se LONG: o .setDerive dGauge(Lon g.valueOf( derived)); break; | |
820 | de fault: | |
821 | // Shoul d never oc cur... | |
822 | MONITOR_ LOGGER.log p(Level.FI NEST, Coun terMonitor .class.get Name(), | |
823 | "setDerive dGaugeWith Difference ", | |
824 | "the thres hold type is invalid "); | |
825 | break; | |
826 | } | |
827 | } | |
828 | ||
829 | /* | |
830 | * --- ---------- ---------- ---------- --------- | |
831 | * PA CKAGE METH ODS | |
832 | * --- ---------- ---------- ---------- --------- | |
833 | */ | |
834 | ||
835 | /** | |
836 | * Fac tory metho d for Obse rvedObject creation. | |
837 | * | |
838 | * @si nce 1.6 | |
839 | */ | |
840 | @Overr ide | |
841 | Observ edObject c reateObser vedObject( ObjectName object) { | |
842 | fi nal Counte rMonitorOb servedObje ct cmo = | |
843 | new Coun terMonitor ObservedOb ject(objec t); | |
844 | cm o.setThres hold(initT hreshold); | |
845 | cm o.setModul usExceeded (false); | |
846 | cm o.setEvent AlreadyNot ified(fals e); | |
847 | cm o.setPrevi ousScanCou nter(null) ; | |
848 | re turn cmo; | |
849 | } | |
850 | ||
851 | /** | |
852 | * Thi s method g lobally se ts the der ived gauge type for the given | |
853 | * "ob ject" and "attribute " after ch ecking tha t the type of the | |
854 | * sup plied obse rved attri bute value is one of the value types | |
855 | * sup ported by this monit or. | |
856 | */ | |
857 | @Overr ide | |
858 | synchr onized boo lean isCom parableTyp eValid(Obj ectName ob ject, | |
859 | Str ing attrib ute, | |
860 | Com parable<?> value) { | |
861 | fi nal Counte rMonitorOb servedObje ct o = | |
862 | (Counter MonitorObs ervedObjec t) getObse rvedObject (object); | |
863 | if (o == nul l) | |
864 | return f alse; | |
865 | ||
866 | // Check tha t the obse rved attri bute is of type "Int eger". | |
867 | // | |
868 | if (value in stanceof I nteger) { | |
869 | o.setTyp e(INTEGER) ; | |
870 | } else if (v alue insta nceof Byte ) { | |
871 | o.setTyp e(BYTE); | |
872 | } else if (v alue insta nceof Shor t) { | |
873 | o.setTyp e(SHORT); | |
874 | } else if (v alue insta nceof Long ) { | |
875 | o.setTyp e(LONG); | |
876 | } else { | |
877 | return f alse; | |
878 | } | |
879 | re turn true; | |
880 | } | |
881 | ||
882 | @Overr ide | |
883 | synchr onized Com parable<?> getDerive dGaugeFrom Comparable ( | |
884 | ObjectName object, | |
885 | String att ribute, | |
886 | Comparable <?> value) { | |
887 | fi nal Counte rMonitorOb servedObje ct o = | |
888 | (Counter MonitorObs ervedObjec t) getObse rvedObject (object); | |
889 | if (o == nul l) | |
890 | return n ull; | |
891 | ||
892 | // Check if counter ha s wrapped around. | |
893 | // | |
894 | if (o.getMod ulusExceed ed()) { | |
895 | if (((Nu mber)o.get DerivedGau ge()).long Value() < | |
896 | o.ge tDerivedGa ugeExceede d().longVa lue()) { | |
897 | o.setThres hold(initT hreshold); | |
898 | o.setModul usExceeded (false); | |
899 | o.setEvent AlreadyNot ified(fals e); | |
900 | } | |
901 | } | |
902 | ||
903 | // Update th e derived gauge attr ibutes and check the | |
904 | // validity of the new value. Th e derived gauge valu e | |
905 | // is invali d when the differenc eMode flag is set to | |
906 | // true and it is the first noti fication, i.e. we | |
907 | // haven't g ot 2 conse cutive val ues to upd ate the | |
908 | // derived g auge. | |
909 | // | |
910 | o. setDerived GaugeValid (updateDer ivedGauge( value, o)) ; | |
911 | ||
912 | re turn (Comp arable<?>) o.getDeri vedGauge() ; | |
913 | } | |
914 | ||
915 | @Overr ide | |
916 | synchr onized voi d onErrorN otificatio n(MonitorN otificatio n notifica tion) { | |
917 | fi nal Counte rMonitorOb servedObje ct o = (Co unterMonit orObserved Object) | |
918 | getObser vedObject( notificati on.getObse rvedObject ()); | |
919 | if (o == nul l) | |
920 | return; | |
921 | ||
922 | // Reset val ues. | |
923 | // | |
924 | o. setModulus Exceeded(f alse); | |
925 | o. setEventAl readyNotif ied(false) ; | |
926 | o. setPreviou sScanCount er(null); | |
927 | } | |
928 | ||
929 | @Overr ide | |
930 | synchr onized Mon itorNotifi cation bui ldAlarmNot ification( | |
931 | Obj ectName ob ject, | |
932 | Str ing attrib ute, | |
933 | Com parable<?> value) { | |
934 | fi nal Counte rMonitorOb servedObje ct o = | |
935 | (Counter MonitorObs ervedObjec t) getObse rvedObject (object); | |
936 | if (o == nul l) | |
937 | return n ull; | |
938 | ||
939 | // Notify th e listener s and upda te the thr eshold if | |
940 | // the updat ed derived gauge val ue is vali d. | |
941 | // | |
942 | fi nal Monito rNotificat ion alarm; | |
943 | if (o.getDer ivedGaugeV alid()) { | |
944 | alarm = updateNoti fications( o); | |
945 | updateTh reshold(o) ; | |
946 | } else { | |
947 | alarm = null; | |
948 | } | |
949 | re turn alarm ; | |
950 | } | |
951 | ||
952 | /** | |
953 | * Tes ts if the threshold, offset an d modulus of the spe cified obs erved | |
954 | * obj ect are of the same type as th e counter. Only inte ger types are | |
955 | * all owed. | |
956 | * | |
957 | * Not e: | |
958 | * I f the opti onal offse t or modul us have no t been ini tialized, their | |
959 | * d efault val ue is an I nteger obj ect with a value equ al to zero . | |
960 | * | |
961 | * @pa ram object The obser ved object . | |
962 | * @pa ram attrib ute The ob served att ribute. | |
963 | * @pa ram value The sample value. | |
964 | * @re turn <CODE >true</COD E> if type is the sa me, | |
965 | * <CO DE>false</ CODE> othe rwise. | |
966 | */ | |
967 | @Overr ide | |
968 | synchr onized boo lean isThr esholdType Valid(Obje ctName obj ect, | |
969 | Stri ng attribu te, | |
970 | Comp arable<?> value) { | |
971 | fi nal Counte rMonitorOb servedObje ct o = | |
972 | (Counter MonitorObs ervedObjec t) getObse rvedObject (object); | |
973 | if (o == nul l) | |
974 | return f alse; | |
975 | ||
976 | Cl ass<? exte nds Number > c = clas sForType(o .getType() ); | |
977 | re turn (c.is Instance(o .getThresh old()) && | |
978 | isVa lidForType (offset, c ) && | |
979 | isVa lidForType (modulus, c)); | |
980 | } | |
981 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.