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 | Monitor.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 | Monitor.java | Wed Sep 12 17:20:33 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 3300 |
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, 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 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 com .sun.jmx.m beanserver .GetProper tyAction; | |
30 | import com .sun.jmx.m beanserver .Introspec tor; | |
31 | import jav a.io.IOExc eption; | |
32 | import jav a.security .AccessCon trolContex t; | |
33 | import jav a.security .AccessCon troller; | |
34 | import jav a.security .Privilege dAction; | |
35 | import jav a.security .Protectio nDomain; | |
36 | import jav a.util.Lis t; | |
37 | import jav a.util.Map ; | |
38 | import jav a.util.Wea kHashMap; | |
39 | import jav a.util.con current.Co pyOnWriteA rrayList; | |
40 | import jav a.util.con current.Ex ecutors; | |
41 | import jav a.util.con current.Fu ture; | |
42 | import jav a.util.con current.Li nkedBlocki ngQueue; | |
43 | import jav a.util.con current.Sc heduledExe cutorServi ce; | |
44 | import jav a.util.con current.Sc heduledFut ure; | |
45 | import jav a.util.con current.Th readFactor y; | |
46 | import jav a.util.con current.Th readPoolEx ecutor; | |
47 | import jav a.util.con current.Ti meUnit; | |
48 | import jav a.util.con current.at omic.Atomi cInteger; | |
49 | import jav a.util.con current.at omic.Atomi cLong; | |
50 | import jav a.util.log ging.Level ; | |
51 | import jav ax.managem ent.Attrib uteNotFoun dException ; | |
52 | import jav ax.managem ent.Instan ceNotFound Exception; | |
53 | import jav ax.managem ent.Intros pectionExc eption; | |
54 | import jav ax.managem ent.MBeanA ttributeIn fo; | |
55 | import jav ax.managem ent.MBeanE xception; | |
56 | import jav ax.managem ent.MBeanI nfo; | |
57 | import jav ax.managem ent.MBeanR egistratio n; | |
58 | import jav ax.managem ent.MBeanS erver; | |
59 | import jav ax.managem ent.MBeanS erverConne ction; | |
60 | import jav ax.managem ent.Notifi cationBroa dcasterSup port; | |
61 | import jav ax.managem ent.Object Name; | |
62 | import jav ax.managem ent.Reflec tionExcept ion; | |
63 | import sta tic javax. management .monitor.M onitorNoti fication.* ; | |
64 | ||
65 | /** | |
66 | * Defines the part common to all monito r MBeans. | |
67 | * A monit or MBean m onitors va lues of an attribute common to a set of observed | |
68 | * MBeans. The obser ved attrib ute is mon itored at intervals specified by the | |
69 | * granula rity perio d. A gauge value (de rived gaug e) is deri ved from t he values | |
70 | * of the observed a ttribute. | |
71 | * | |
72 | * | |
73 | * @since 1.5 | |
74 | */ | |
75 | public abs tract clas s Monitor | |
76 | extend s Notifica tionBroadc asterSuppo rt | |
77 | implem ents Monit orMBean, M BeanRegist ration { | |
78 | ||
79 | /* | |
80 | * --- ---------- ---------- ---------- --------- | |
81 | * PA CKAGE CLAS SES | |
82 | * --- ---------- ---------- ---------- --------- | |
83 | */ | |
84 | ||
85 | static class Obs ervedObjec t { | |
86 | ||
87 | pu blic Obser vedObject( ObjectName observedO bject) { | |
88 | this.obs ervedObjec t = observ edObject; | |
89 | } | |
90 | ||
91 | pu blic final ObjectNam e getObser vedObject( ) { | |
92 | return o bservedObj ect; | |
93 | } | |
94 | pu blic final synchroni zed int ge tAlreadyNo tified() { | |
95 | return a lreadyNoti fied; | |
96 | } | |
97 | pu blic final synchroni zed void s etAlreadyN otified(in t alreadyN otified) { | |
98 | this.alr eadyNotifi ed = alrea dyNotified ; | |
99 | } | |
100 | pu blic final synchroni zed Object getDerive dGauge() { | |
101 | return d erivedGaug e; | |
102 | } | |
103 | pu blic final synchroni zed void s etDerivedG auge(Objec t derivedG auge) { | |
104 | this.der ivedGauge = derivedG auge; | |
105 | } | |
106 | pu blic final synchroni zed long g etDerivedG augeTimeSt amp() { | |
107 | return d erivedGaug eTimeStamp ; | |
108 | } | |
109 | pu blic final synchroni zed void s etDerivedG augeTimeSt amp( | |
110 | l ong derive dGaugeTime Stamp) { | |
111 | this.der ivedGaugeT imeStamp = derivedGa ugeTimeSta mp; | |
112 | } | |
113 | ||
114 | pr ivate fina l ObjectNa me observe dObject; | |
115 | pr ivate int alreadyNot ified; | |
116 | pr ivate Obje ct derived Gauge; | |
117 | pr ivate long derivedGa ugeTimeSta mp; | |
118 | } | |
119 | ||
120 | /* | |
121 | * --- ---------- ---------- ---------- --------- | |
122 | * PR IVATE VARI ABLES | |
123 | * --- ---------- ---------- ---------- --------- | |
124 | */ | |
125 | ||
126 | /** | |
127 | * Att ribute to observe. | |
128 | */ | |
129 | privat e String o bservedAtt ribute; | |
130 | ||
131 | /** | |
132 | * Mon itor granu larity per iod (in mi lliseconds ). | |
133 | * The default v alue is se t to 10 se conds. | |
134 | */ | |
135 | privat e long gra nularityPe riod = 100 00; | |
136 | ||
137 | /** | |
138 | * Mon itor state . | |
139 | * The default v alue is se t to <CODE >false</CO DE>. | |
140 | */ | |
141 | privat e boolean isActive = false; | |
142 | ||
143 | /** | |
144 | * Mon itor seque nce number . | |
145 | * The default v alue is se t to 0. | |
146 | */ | |
147 | privat e final At omicLong s equenceNum ber = new AtomicLong (); | |
148 | ||
149 | /** | |
150 | * Com plex type attribute flag. | |
151 | * The default v alue is se t to <CODE >false</CO DE>. | |
152 | */ | |
153 | privat e boolean isComplexT ypeAttribu te = false ; | |
154 | ||
155 | /** | |
156 | * Fir st attribu te name ex tracted fr om complex type attr ibute name . | |
157 | */ | |
158 | privat e String f irstAttrib ute; | |
159 | ||
160 | /** | |
161 | * Rem aining att ribute nam es extract ed from co mplex type attribute name. | |
162 | */ | |
163 | privat e final Li st<String> remaining Attributes = | |
164 | ne w CopyOnWr iteArrayLi st<String> (); | |
165 | ||
166 | /** | |
167 | * Acc essControl Context of the Monit or.start() caller. | |
168 | */ | |
169 | privat e static f inal Acces sControlCo ntext noPe rmissionsA CC = | |
170 | new Acce ssControlC ontext( | |
171 | new Prot ectionDoma in[] {new Protection Domain(nul l, null)}) ; | |
172 | privat e volatile AccessCon trolContex t acc = no Permission sACC; | |
173 | ||
174 | /** | |
175 | * Sch eduler Ser vice. | |
176 | */ | |
177 | privat e static f inal Sched uledExecut orService scheduler = | |
178 | Ex ecutors.ne wSingleThr eadSchedul edExecutor ( | |
179 | new Daem onThreadFa ctory("Sch eduler")); | |
180 | ||
181 | /** | |
182 | * Map containin g the thre ad pool ex ecutor per thread gr oup. | |
183 | */ | |
184 | privat e static f inal Map<T hreadPoolE xecutor, V oid> execu tors = | |
185 | new Weak HashMap<Th readPoolEx ecutor, Vo id>(); | |
186 | ||
187 | /** | |
188 | * Loc k for exec utors map. | |
189 | */ | |
190 | privat e static f inal Objec t executor sLock = ne w Object() ; | |
191 | ||
192 | /** | |
193 | * Max imum Pool Size | |
194 | */ | |
195 | privat e static f inal int m aximumPool Size; | |
196 | static { | |
197 | fi nal String maximumPo olSizeSysP rop = "jmx .x.monitor .maximum.p ool.size"; | |
198 | fi nal String maximumPo olSizeStr = AccessCo ntroller.d oPrivilege d( | |
199 | new GetP ropertyAct ion(maximu mPoolSizeS ysProp)); | |
200 | if (maximumP oolSizeStr == null | | | |
201 | maximumP oolSizeStr .trim().le ngth() == 0) { | |
202 | maximumP oolSize = 10; | |
203 | } else { | |
204 | int maxi mumPoolSiz eTmp = 10; | |
205 | try { | |
206 | maxi mumPoolSiz eTmp = Int eger.parse Int(maximu mPoolSizeS tr); | |
207 | } catch (NumberFor matExcepti on e) { | |
208 | if ( MONITOR_LO GGER.isLog gable(Leve l.FINER)) { | |
209 | MONITOR_LO GGER.logp( Level.FINE R, Monitor .class.get Name(), | |
210 | "< static ini tializer>" , | |
211 | "W rong value for " + m aximumPool SizeSysPro p + | |
212 | " system pro perty", e) ; | |
213 | MONITOR_LO GGER.logp( Level.FINE R, Monitor .class.get Name(), | |
214 | "< static ini tializer>" , | |
215 | ma ximumPoolS izeSysProp + " defau lts to 10" ); | |
216 | } | |
217 | maxi mumPoolSiz eTmp = 10; | |
218 | } | |
219 | if (maxi mumPoolSiz eTmp < 1) { | |
220 | maxi mumPoolSiz e = 1; | |
221 | } else { | |
222 | maxi mumPoolSiz e = maximu mPoolSizeT mp; | |
223 | } | |
224 | } | |
225 | } | |
226 | ||
227 | /** | |
228 | * Fut ure associ ated to th e current monitor ta sk. | |
229 | */ | |
230 | privat e Future<? > monitorF uture; | |
231 | ||
232 | /** | |
233 | * Sch eduler tas k to be ex ecuted by the Schedu ler Servic e. | |
234 | */ | |
235 | privat e final Sc hedulerTas k schedule rTask = ne w Schedule rTask(); | |
236 | ||
237 | /** | |
238 | * Sch eduledFutu re associa ted to the current s cheduler t ask. | |
239 | */ | |
240 | privat e Schedule dFuture<?> scheduler Future; | |
241 | ||
242 | /* | |
243 | * --- ---------- ---------- ---------- --------- | |
244 | * PR OTECTED VA RIABLES | |
245 | * --- ---------- ---------- ---------- --------- | |
246 | */ | |
247 | ||
248 | /** | |
249 | * The amount by which the capacity of the mon itor array s are | |
250 | * aut omatically increment ed when th eir size b ecomes gre ater than | |
251 | * the ir capacit y. | |
252 | */ | |
253 | protec ted final static int capacityI ncrement = 16; | |
254 | ||
255 | /** | |
256 | * The number of valid com ponents in the vecto r of obser ved object s. | |
257 | * | |
258 | */ | |
259 | protec ted int el ementCount = 0; | |
260 | ||
261 | /** | |
262 | * Mon itor error s that hav e already been notif ied. | |
263 | * @de precated e quivalent to {@link #alreadyNo tifieds}[0 ]. | |
264 | */ | |
265 | @Depre cated | |
266 | protec ted int al readyNotif ied = 0; | |
267 | ||
268 | /** | |
269 | * <p> Selected m onitor err ors that h ave alread y been not ified.</p> | |
270 | * | |
271 | * <p> Each eleme nt in this array cor responds t o an obser ved object | |
272 | * in the vector . It cont ains a bit mask of t he flags { @link | |
273 | * #OB SERVED_OBJ ECT_ERROR_ NOTIFIED} etc, indic ating whet her the | |
274 | * cor responding notificat ion has al ready been sent for the MBean | |
275 | * bei ng monitor ed.</p> | |
276 | * | |
277 | */ | |
278 | protec ted int al readyNotif ieds[] = n ew int[cap acityIncre ment]; | |
279 | ||
280 | /** | |
281 | * Ref erence to the MBean server. T his refere nce is nul l when the | |
282 | * mon itor MBean is not re gistered i n an MBean server. This | |
283 | * ref erence is initialize d before t he monitor MBean is registered | |
284 | * in the MBean server. | |
285 | * @se e #preRegi ster(MBean Server ser ver, Objec tName name ) | |
286 | */ | |
287 | protec ted MBeanS erver serv er; | |
288 | ||
289 | // Fla gs definin g possible monitor e rrors. | |
290 | // | |
291 | ||
292 | /** | |
293 | * Thi s flag is used to re set the {@ link #alre adyNotifie ds | |
294 | * alr eadyNotifi eds} monit or attribu te. | |
295 | */ | |
296 | protec ted static final int RESET_FLA GS_ALREADY _NOTIFIED = 0; | |
297 | ||
298 | /** | |
299 | * Fla g denoting that a no tification has occur red after changing | |
300 | * the observed object. T his flag i s used to check that the new | |
301 | * obs erved obje ct is regi stered in the MBean server at the time | |
302 | * of the first notificati on. | |
303 | */ | |
304 | protec ted static final int OBSERVED_ OBJECT_ERR OR_NOTIFIE D = 1; | |
305 | ||
306 | /** | |
307 | * Fla g denoting that a no tification has occur red after changing | |
308 | * the observed attribute. This fla g is used to check t hat the | |
309 | * new observed attribute belongs to the obser ved object at the | |
310 | * tim e of the f irst notif ication. | |
311 | */ | |
312 | protec ted static final int OBSERVED_ ATTRIBUTE_ ERROR_NOTI FIED = 2; | |
313 | ||
314 | /** | |
315 | * Fla g denoting that a no tification has occur red after changing | |
316 | * the observed object or the observ ed attribu te. This flag is | |
317 | * use d to check that the observed a ttribute t ype is cor rect | |
318 | * (de pending on the monit or in use) at the ti me of the first | |
319 | * not ification. | |
320 | */ | |
321 | protec ted static final int OBSERVED_ ATTRIBUTE_ TYPE_ERROR _NOTIFIED = 4; | |
322 | ||
323 | /** | |
324 | * Fla g denoting that a no tification has occur red after changing | |
325 | * the observed object or the observ ed attribu te. This flag is | |
326 | * use d to notif y any exce ption (exc ept the ca ses descri bed above) | |
327 | * whe n trying t o get the value of t he observe d attribut e at the | |
328 | * tim e of the f irst notif ication. | |
329 | */ | |
330 | protec ted static final int RUNTIME_E RROR_NOTIF IED = 8; | |
331 | ||
332 | /** | |
333 | * Thi s field is retained for compat ibility bu t should n ot be refe renced. | |
334 | * | |
335 | * @de precated N o replacem ent. | |
336 | */ | |
337 | @Depre cated | |
338 | protec ted String dbgTag = Monitor.cl ass.getNam e(); | |
339 | ||
340 | /* | |
341 | * --- ---------- ---------- ---------- --------- | |
342 | * PA CKAGE VARI ABLES | |
343 | * --- ---------- ---------- ---------- --------- | |
344 | */ | |
345 | ||
346 | /** | |
347 | * Lis t of Obser vedObjects to which the attrib ute to obs erve belon gs. | |
348 | */ | |
349 | final List<Obser vedObject> observedO bjects = | |
350 | ne w CopyOnWr iteArrayLi st<Observe dObject>() ; | |
351 | ||
352 | /** | |
353 | * Fla g denoting that a no tification has occur red after changing | |
354 | * the threshold . This fla g is used to notify any except ion | |
355 | * rel ated to in valid thre sholds set tings. | |
356 | */ | |
357 | static final int THRESHOLD _ERROR_NOT IFIED = 16; | |
358 | ||
359 | /** | |
360 | * Enu meration u sed to kee p trace of the deriv ed gauge t ype | |
361 | * in counter an d gauge mo nitors. | |
362 | */ | |
363 | enum N umericalTy pe { BYTE, SHORT, IN TEGER, LON G, FLOAT, DOUBLE }; | |
364 | ||
365 | /** | |
366 | * Con stant used to initia lize all t he numeric values. | |
367 | */ | |
368 | static final Int eger INTEG ER_ZERO = 0; | |
369 | ||
370 | ||
371 | /* | |
372 | * --- ---------- ---------- ---------- --------- | |
373 | * PU BLIC METHO DS | |
374 | * --- ---------- ---------- ---------- --------- | |
375 | */ | |
376 | ||
377 | /** | |
378 | * All ows the mo nitor MBea n to perfo rm any ope rations it needs | |
379 | * bef ore being registered in the MB ean server . | |
380 | * <P> | |
381 | * Ini tializes t he referen ce to the MBean serv er. | |
382 | * | |
383 | * @pa ram server The MBean server in which the monitor M Bean will | |
384 | * be registered . | |
385 | * @pa ram name T he object name of th e monitor MBean. | |
386 | * | |
387 | * @re turn The n ame of the monitor M Bean regis tered. | |
388 | * | |
389 | * @ex ception Ex ception | |
390 | */ | |
391 | public ObjectNam e preRegis ter(MBeanS erver serv er, Object Name name) | |
392 | th rows Excep tion { | |
393 | ||
394 | MO NITOR_LOGG ER.logp(Le vel.FINER, Monitor.c lass.getNa me(), | |
395 | "pre Register(M BeanServer , ObjectNa me)", | |
396 | "ini tialize th e referenc e on the M Bean serve r"); | |
397 | ||
398 | th is.server = server; | |
399 | re turn name; | |
400 | } | |
401 | ||
402 | /** | |
403 | * All ows the mo nitor MBea n to perfo rm any ope rations ne eded after | |
404 | * hav ing been r egistered in the MBe an server or after t he | |
405 | * reg istration has failed . | |
406 | * <P> | |
407 | * Not used in t his contex t. | |
408 | */ | |
409 | public void post Register(B oolean reg istrationD one) { | |
410 | } | |
411 | ||
412 | /** | |
413 | * All ows the mo nitor MBea n to perfo rm any ope rations it needs | |
414 | * bef ore being unregister ed by the MBean serv er. | |
415 | * <P> | |
416 | * Sto ps the mon itor. | |
417 | * | |
418 | * @ex ception Ex ception | |
419 | */ | |
420 | public void preD eregister( ) throws E xception { | |
421 | ||
422 | MO NITOR_LOGG ER.logp(Le vel.FINER, Monitor.c lass.getNa me(), | |
423 | "pre Deregister ()", "stop the monit or"); | |
424 | ||
425 | // Stop the Monitor. | |
426 | // | |
427 | st op(); | |
428 | } | |
429 | ||
430 | /** | |
431 | * All ows the mo nitor MBea n to perfo rm any ope rations ne eded after | |
432 | * hav ing been u nregistere d by the M Bean serve r. | |
433 | * <P> | |
434 | * Not used in t his contex t. | |
435 | */ | |
436 | public void post Deregister () { | |
437 | } | |
438 | ||
439 | /** | |
440 | * Sta rts the mo nitor. | |
441 | */ | |
442 | public abstract void start (); | |
443 | ||
444 | /** | |
445 | * Sto ps the mon itor. | |
446 | */ | |
447 | public abstract void stop( ); | |
448 | ||
449 | // GET TERS AND S ETTERS | |
450 | //---- ---------- ------ | |
451 | ||
452 | /** | |
453 | * Ret urns the o bject name of the fi rst object in the se t of obser ved | |
454 | * MBe ans, or <c ode>null</ code> if t here is no such obje ct. | |
455 | * | |
456 | * @re turn The o bject bein g observed . | |
457 | * | |
458 | * @se e #setObse rvedObject (ObjectNam e) | |
459 | * | |
460 | * @de precated A s of JMX 1 .2, replac ed by {@li nk #getObs ervedObjec ts} | |
461 | */ | |
462 | @Depre cated | |
463 | public synchroni zed Object Name getOb servedObje ct() { | |
464 | if (observed Objects.is Empty()) { | |
465 | return n ull; | |
466 | } else { | |
467 | return o bservedObj ects.get(0 ).getObser vedObject( ); | |
468 | } | |
469 | } | |
470 | ||
471 | /** | |
472 | * Rem oves all o bjects fro m the set of observe d objects, and then adds the | |
473 | * spe cified obj ect. | |
474 | * | |
475 | * @pa ram object The objec t to obser ve. | |
476 | * @ex ception Il legalArgum entExcepti on The spe cified | |
477 | * obj ect is nul l. | |
478 | * | |
479 | * @se e #getObse rvedObject () | |
480 | * | |
481 | * @de precated A s of JMX 1 .2, replac ed by {@li nk #addObs ervedObjec t} | |
482 | */ | |
483 | @Depre cated | |
484 | public synchroni zed void s etObserved Object(Obj ectName ob ject) | |
485 | th rows Illeg alArgument Exception { | |
486 | if (object = = null) | |
487 | throw ne w IllegalA rgumentExc eption("Nu ll observe d object") ; | |
488 | if (observed Objects.si ze() == 1 && contain sObservedO bject(obje ct)) | |
489 | return; | |
490 | ob servedObje cts.clear( ); | |
491 | ad dObservedO bject(obje ct); | |
492 | } | |
493 | ||
494 | /** | |
495 | * Add s the spec ified obje ct in the set of obs erved MBea ns, if thi s object | |
496 | * is not alread y present. | |
497 | * | |
498 | * @pa ram object The objec t to obser ve. | |
499 | * @ex ception Il legalArgum entExcepti on The spe cified obj ect is nul l. | |
500 | * | |
501 | */ | |
502 | public synchroni zed void a ddObserved Object(Obj ectName ob ject) | |
503 | th rows Illeg alArgument Exception { | |
504 | ||
505 | if (object = = null) { | |
506 | throw ne w IllegalA rgumentExc eption("Nu ll observe d object") ; | |
507 | } | |
508 | ||
509 | // Check tha t the spec ified obje ct is not already co ntained. | |
510 | // | |
511 | if (contains ObservedOb ject(objec t)) | |
512 | return; | |
513 | ||
514 | // Add the s pecified o bject in t he list. | |
515 | // | |
516 | Ob servedObje ct o = cre ateObserve dObject(ob ject); | |
517 | o. setAlready Notified(R ESET_FLAGS _ALREADY_N OTIFIED); | |
518 | o. setDerived Gauge(INTE GER_ZERO); | |
519 | o. setDerived GaugeTimeS tamp(Syste m.currentT imeMillis( )); | |
520 | ob servedObje cts.add(o) ; | |
521 | ||
522 | // Update le gacy prote cted stuff . | |
523 | // | |
524 | cr eateAlread yNotified( ); | |
525 | } | |
526 | ||
527 | /** | |
528 | * Rem oves the s pecified o bject from the set o f observed MBeans. | |
529 | * | |
530 | * @pa ram object The objec t to remov e. | |
531 | * | |
532 | */ | |
533 | public synchroni zed void r emoveObser vedObject( ObjectName object) { | |
534 | // Check for null obje ct. | |
535 | // | |
536 | if (object = = null) | |
537 | return; | |
538 | ||
539 | fi nal Observ edObject o = getObse rvedObject (object); | |
540 | if (o != nul l) { | |
541 | // Remov e the spec ified obje ct from th e list. | |
542 | // | |
543 | observed Objects.re move(o); | |
544 | // Updat e legacy p rotected s tuff. | |
545 | // | |
546 | createAl readyNotif ied(); | |
547 | } | |
548 | } | |
549 | ||
550 | /** | |
551 | * Tes ts whether the speci fied objec t is in th e set of o bserved MB eans. | |
552 | * | |
553 | * @pa ram object The objec t to check . | |
554 | * @re turn <CODE >true</COD E> if the specified object is present, | |
555 | * <CO DE>false</ CODE> othe rwise. | |
556 | * | |
557 | */ | |
558 | public synchroni zed boolea n contains ObservedOb ject(Objec tName obje ct) { | |
559 | re turn getOb servedObje ct(object) != null; | |
560 | } | |
561 | ||
562 | /** | |
563 | * Ret urns an ar ray contai ning the o bjects bei ng observe d. | |
564 | * | |
565 | * @re turn The o bjects bei ng observe d. | |
566 | * | |
567 | */ | |
568 | public synchroni zed Object Name[] get ObservedOb jects() { | |
569 | Ob jectName[] names = n ew ObjectN ame[observ edObjects. size()]; | |
570 | fo r (int i = 0; i < na mes.length ; i++) | |
571 | names[i] = observe dObjects.g et(i).getO bservedObj ect(); | |
572 | re turn names ; | |
573 | } | |
574 | ||
575 | /** | |
576 | * Get s the attr ibute bein g observed . | |
577 | * <BR >The obser ved attrib ute is not initializ ed by defa ult (set t o null). | |
578 | * | |
579 | * @re turn The a ttribute b eing obser ved. | |
580 | * | |
581 | * @se e #setObse rvedAttrib ute | |
582 | */ | |
583 | public synchroni zed String getObserv edAttribut e() { | |
584 | re turn obser vedAttribu te; | |
585 | } | |
586 | ||
587 | /** | |
588 | * Set s the attr ibute to o bserve. | |
589 | * <BR >The obser ved attrib ute is not initializ ed by defa ult (set t o null). | |
590 | * | |
591 | * @pa ram attrib ute The at tribute to observe. | |
592 | * @ex ception Il legalArgum entExcepti on The spe cified | |
593 | * att ribute is null. | |
594 | * | |
595 | * @se e #getObse rvedAttrib ute | |
596 | */ | |
597 | public void setO bservedAtt ribute(Str ing attrib ute) | |
598 | th rows Illeg alArgument Exception { | |
599 | ||
600 | if (attribut e == null) { | |
601 | throw ne w IllegalA rgumentExc eption("Nu ll observe d attribut e"); | |
602 | } | |
603 | ||
604 | // Update al readyNotif ied array. | |
605 | // | |
606 | sy nchronized (this) { | |
607 | if (obse rvedAttrib ute != nul l && | |
608 | obse rvedAttrib ute.equals (attribute )) | |
609 | retu rn; | |
610 | observed Attribute = attribut e; | |
611 | ||
612 | // Reset the compl ex type at tribute in formation | |
613 | // such that it is recalcula ted again. | |
614 | // | |
615 | cleanupI sComplexTy peAttribut e(); | |
616 | ||
617 | int inde x = 0; | |
618 | for (Obs ervedObjec t o : obse rvedObject s) { | |
619 | rese tAlreadyNo tified(o, index++, | |
620 | OBS ERVED_ATTR IBUTE_ERRO R_NOTIFIED | | |
621 | OBS ERVED_ATTR IBUTE_TYPE _ERROR_NOT IFIED); | |
622 | } | |
623 | } | |
624 | } | |
625 | ||
626 | /** | |
627 | * Get s the gran ularity pe riod (in m illisecond s). | |
628 | * <BR >The defau lt value o f the gran ularity pe riod is 10 seconds. | |
629 | * | |
630 | * @re turn The g ranularity period va lue. | |
631 | * | |
632 | * @se e #setGran ularityPer iod | |
633 | */ | |
634 | public synchroni zed long g etGranular ityPeriod( ) { | |
635 | re turn granu larityPeri od; | |
636 | } | |
637 | ||
638 | /** | |
639 | * Set s the gran ularity pe riod (in m illisecond s). | |
640 | * <BR >The defau lt value o f the gran ularity pe riod is 10 seconds. | |
641 | * | |
642 | * @pa ram period The granu larity per iod value. | |
643 | * @ex ception Il legalArgum entExcepti on The gra nularity | |
644 | * per iod is les s than or equal to z ero. | |
645 | * | |
646 | * @se e #getGran ularityPer iod | |
647 | */ | |
648 | public synchroni zed void s etGranular ityPeriod( long perio d) | |
649 | th rows Illeg alArgument Exception { | |
650 | ||
651 | if (period < = 0) { | |
652 | throw ne w IllegalA rgumentExc eption("No npositive granularit y " + | |
653 | "pe riod"); | |
654 | } | |
655 | ||
656 | if (granular ityPeriod == period) | |
657 | return; | |
658 | gr anularityP eriod = pe riod; | |
659 | ||
660 | // Reschedul e the sche duler task if the mo nitor is a ctive. | |
661 | // | |
662 | if (isActive ()) { | |
663 | cleanupF utures(); | |
664 | schedule rFuture = scheduler. schedule(s chedulerTa sk, | |
665 | p eriod, | |
666 | T imeUnit.MI LLISECONDS ); | |
667 | } | |
668 | } | |
669 | ||
670 | /** | |
671 | * Tes ts whether the monit or MBean i s active. A monitor MBean is | |
672 | * mar ked active when the {@link #st art start} method is called. | |
673 | * It becomes in active whe n the {@li nk #stop s top} metho d is | |
674 | * cal led. | |
675 | * | |
676 | * @re turn <CODE >true</COD E> if the monitor MB ean is act ive, | |
677 | * <CO DE>false</ CODE> othe rwise. | |
678 | */ | |
679 | /* Thi s method m ust be syn chronized so that th e monitori ng thread will | |
680 | cor rectly see modificat ions to th e isActive variable. See the M onitorTask | |
681 | act ion execut ed by the Scheduled Executor S ervice. */ | |
682 | public synchroni zed boolea n isActive () { | |
683 | re turn isAct ive; | |
684 | } | |
685 | ||
686 | /* | |
687 | * --- ---------- ---------- ---------- --------- | |
688 | * PA CKAGE METH ODS | |
689 | * --- ---------- ---------- ---------- --------- | |
690 | */ | |
691 | ||
692 | /** | |
693 | * Sta rts the mo nitor. | |
694 | */ | |
695 | void d oStart() { | |
696 | MONITOR_ LOGGER.log p(Level.FI NER, Monit or.class.g etName(), | |
697 | "doS tart()", " start the monitor"); | |
698 | ||
699 | sy nchronized (this) { | |
700 | if (isAc tive()) { | |
701 | MONI TOR_LOGGER .logp(Leve l.FINER, M onitor.cla ss.getName (), | |
702 | "doSta rt()", "th e monitor is already active"); | |
703 | retu rn; | |
704 | } | |
705 | ||
706 | isActive = true; | |
707 | ||
708 | // Reset the compl ex type at tribute in formation | |
709 | // such that it is recalcula ted again. | |
710 | // | |
711 | cleanupI sComplexTy peAttribut e(); | |
712 | ||
713 | // Cache the Acces sControlCo ntext of t he Monitor .start() c aller. | |
714 | // The m onitor tas ks will be executed within thi s context. | |
715 | // | |
716 | acc = Ac cessContro ller.getCo ntext(); | |
717 | ||
718 | // Start the sched uler. | |
719 | // | |
720 | cleanupF utures(); | |
721 | schedule rTask.setM onitorTask (new Monit orTask()); | |
722 | schedule rFuture = scheduler. schedule(s chedulerTa sk, | |
723 | g etGranular ityPeriod( ), | |
724 | T imeUnit.MI LLISECONDS ); | |
725 | } | |
726 | } | |
727 | ||
728 | /** | |
729 | * Sto ps the mon itor. | |
730 | */ | |
731 | void d oStop() { | |
732 | MO NITOR_LOGG ER.logp(Le vel.FINER, Monitor.c lass.getNa me(), | |
733 | "doS top()", "s top the mo nitor"); | |
734 | ||
735 | sy nchronized (this) { | |
736 | if (!isA ctive()) { | |
737 | MONI TOR_LOGGER .logp(Leve l.FINER, M onitor.cla ss.getName (), | |
738 | "doSto p()", "the monitor i s not acti ve"); | |
739 | retu rn; | |
740 | } | |
741 | ||
742 | isActive = false; | |
743 | ||
744 | // Cance l the sche duler task associate d with the | |
745 | // sched uler and i ts associa ted monito r task. | |
746 | // | |
747 | cleanupF utures(); | |
748 | ||
749 | // Reset the Acces sControlCo ntext. | |
750 | // | |
751 | acc = no Permission sACC; | |
752 | ||
753 | // Reset the compl ex type at tribute in formation | |
754 | // such that it is recalcula ted again. | |
755 | // | |
756 | cleanupI sComplexTy peAttribut e(); | |
757 | } | |
758 | } | |
759 | ||
760 | /** | |
761 | * Get s the deri ved gauge of the spe cified obj ect, if th is object is | |
762 | * con tained in the set of observed MBeans, or <code>nul l</code> o therwise. | |
763 | * | |
764 | * @pa ram object the name of the obj ect whose derived ga uge is to | |
765 | * be returned. | |
766 | * | |
767 | * @re turn The d erived gau ge of the specified object. | |
768 | * | |
769 | * @si nce 1.6 | |
770 | */ | |
771 | synchr onized Obj ect getDer ivedGauge( ObjectName object) { | |
772 | fi nal Observ edObject o = getObse rvedObject (object); | |
773 | re turn o == null ? nul l : o.getD erivedGaug e(); | |
774 | } | |
775 | ||
776 | /** | |
777 | * Get s the deri ved gauge timestamp of the spe cified obj ect, if | |
778 | * thi s object i s containe d in the s et of obse rved MBean s, or | |
779 | * <co de>0</code > otherwis e. | |
780 | * | |
781 | * @pa ram object the name of the obj ect whose derived ga uge | |
782 | * tim estamp is to be retu rned. | |
783 | * | |
784 | * @re turn The d erived gau ge timesta mp of the specified object. | |
785 | * | |
786 | */ | |
787 | synchr onized lon g getDeriv edGaugeTim eStamp(Obj ectName ob ject) { | |
788 | fi nal Observ edObject o = getObse rvedObject (object); | |
789 | re turn o == null ? 0 : o.getDeri vedGaugeTi meStamp(); | |
790 | } | |
791 | ||
792 | Object getAttrib ute(MBeanS erverConne ction mbsc , | |
793 | Object Name objec t, | |
794 | String attribute ) | |
795 | th rows Attri buteNotFou ndExceptio n, | |
796 | Insta nceNotFoun dException , | |
797 | MBean Exception, | |
798 | Refle ctionExcep tion, | |
799 | IOExc eption { | |
800 | // Check for "Observed Attribute" replaceme nt. | |
801 | // This coul d happen i f a thread A called setObserve dAttribute () | |
802 | // while oth er thread B was in t he middle of the mon itor() met hod | |
803 | // and recei ved the ol d observed attribute value. | |
804 | // | |
805 | fi nal boolea n lookupMB eanInfo; | |
806 | sy nchronized (this) { | |
807 | if (!isA ctive()) | |
808 | thro w new Ille galArgumen tException ( | |
809 | "The monit or has bee n stopped" ); | |
810 | if (!att ribute.equ als(getObs ervedAttri bute())) | |
811 | thro w new Ille galArgumen tException ( | |
812 | "The obser ved attrib ute has be en changed "); | |
813 | lookupMB eanInfo = | |
814 | (fir stAttribut e == null && attribu te.indexOf ('.') != - 1); | |
815 | } | |
816 | ||
817 | // Look up M BeanInfo i f needed | |
818 | // | |
819 | fi nal MBeanI nfo mbi; | |
820 | if (lookupMB eanInfo) { | |
821 | try { | |
822 | mbi = mbsc.get MBeanInfo( object); | |
823 | } catch (Introspec tionExcept ion e) { | |
824 | thro w new Ille galArgumen tException (e); | |
825 | } | |
826 | } else { | |
827 | mbi = nu ll; | |
828 | } | |
829 | ||
830 | // Check for complex t ype attrib ute | |
831 | // | |
832 | fi nal String fa; | |
833 | sy nchronized (this) { | |
834 | if (!isA ctive()) | |
835 | thro w new Ille galArgumen tException ( | |
836 | "The monit or has bee n stopped" ); | |
837 | if (!att ribute.equ als(getObs ervedAttri bute())) | |
838 | thro w new Ille galArgumen tException ( | |
839 | "The obser ved attrib ute has be en changed "); | |
840 | if (firs tAttribute == null) { | |
841 | if ( attribute. indexOf('. ') != -1) { | |
842 | MBeanAttri buteInfo m baiArray[] = mbi.get Attributes (); | |
843 | for (MBean AttributeI nfo mbai : mbaiArray ) { | |
844 | if (at tribute.eq uals(mbai. getName()) ) { | |
845 | fi rstAttribu te = attri bute; | |
846 | br eak; | |
847 | } | |
848 | } | |
849 | if (firstA ttribute = = null) { | |
850 | String tokens[] = attribut e.split("\ \.", -1); | |
851 | firstA ttribute = tokens[0] ; | |
852 | for (i nt i = 1; i < tokens .length; i ++) | |
853 | re mainingAtt ributes.ad d(tokens[i ]); | |
854 | isComp lexTypeAtt ribute = t rue; | |
855 | } | |
856 | } el se { | |
857 | firstAttri bute = att ribute; | |
858 | } | |
859 | } | |
860 | fa = fir stAttribut e; | |
861 | } | |
862 | re turn mbsc. getAttribu te(object, fa); | |
863 | } | |
864 | ||
865 | Compar able<?> ge tComparabl eFromAttri bute(Objec tName obje ct, | |
866 | Strin g attribut e, | |
867 | Objec t value) | |
868 | th rows Attri buteNotFou ndExceptio n { | |
869 | if (isComple xTypeAttri bute) { | |
870 | Object v = value; | |
871 | for (Str ing attr : remaining Attributes ) | |
872 | v = Introspect or.element FromComple x(v, attr) ; | |
873 | return ( Comparable <?>) v; | |
874 | } else { | |
875 | return ( Comparable <?>) value ; | |
876 | } | |
877 | } | |
878 | ||
879 | boolea n isCompar ableTypeVa lid(Object Name objec t, | |
880 | String attribute , | |
881 | Compar able<?> va lue) { | |
882 | re turn true; | |
883 | } | |
884 | ||
885 | String buildErro rNotificat ion(Object Name objec t, | |
886 | String attribute , | |
887 | Compar able<?> va lue) { | |
888 | re turn null; | |
889 | } | |
890 | ||
891 | void o nErrorNoti fication(M onitorNoti fication n otificatio n) { | |
892 | } | |
893 | ||
894 | Compar able<?> ge tDerivedGa ugeFromCom parable(Ob jectName o bject, | |
895 | St ring attri bute, | |
896 | Co mparable<? > value) { | |
897 | re turn (Comp arable<?>) value; | |
898 | } | |
899 | ||
900 | Monito rNotificat ion buildA larmNotifi cation(Obj ectName ob ject, | |
901 | Str ing attrib ute, | |
902 | Com parable<?> value){ | |
903 | re turn null; | |
904 | } | |
905 | ||
906 | boolea n isThresh oldTypeVal id(ObjectN ame object , | |
907 | String attribute, | |
908 | Compara ble<?> val ue) { | |
909 | re turn true; | |
910 | } | |
911 | ||
912 | static Class<? e xtends Num ber> class ForType(Nu mericalTyp e type) { | |
913 | sw itch (type ) { | |
914 | case BYT E: | |
915 | retu rn Byte.cl ass; | |
916 | case SHO RT: | |
917 | retu rn Short.c lass; | |
918 | case INT EGER: | |
919 | retu rn Integer .class; | |
920 | case LON G: | |
921 | retu rn Long.cl ass; | |
922 | case FLO AT: | |
923 | retu rn Float.c lass; | |
924 | case DOU BLE: | |
925 | retu rn Double. class; | |
926 | default: | |
927 | thro w new Ille galArgumen tException ( | |
928 | "Unsupport ed numeric al type"); | |
929 | } | |
930 | } | |
931 | ||
932 | static boolean i sValidForT ype(Object value, Cl ass<? exte nds Number > c) { | |
933 | re turn ((val ue == INTE GER_ZERO) || c.isIns tance(valu e)); | |
934 | } | |
935 | ||
936 | /** | |
937 | * Get the speci fied {@cod e Observed Object} if this obje ct is | |
938 | * con tained in the set of observed MBeans, or {@code nu ll} | |
939 | * oth erwise. | |
940 | * | |
941 | * @pa ram object the name of the {@c ode Observ edObject} to retriev e. | |
942 | * | |
943 | * @re turn The { @code Obse rvedObject } associat ed to the supplied | |
944 | * {@c ode Object Name}. | |
945 | * | |
946 | * @si nce 1.6 | |
947 | */ | |
948 | synchr onized Obs ervedObjec t getObser vedObject( ObjectName object) { | |
949 | fo r (Observe dObject o : observed Objects) | |
950 | if (o.ge tObservedO bject().eq uals(objec t)) | |
951 | retu rn o; | |
952 | re turn null; | |
953 | } | |
954 | ||
955 | /** | |
956 | * Fac tory metho d for Obse rvedObject creation. | |
957 | * | |
958 | * @si nce 1.6 | |
959 | */ | |
960 | Observ edObject c reateObser vedObject( ObjectName object) { | |
961 | re turn new O bservedObj ect(object ); | |
962 | } | |
963 | ||
964 | /** | |
965 | * Cre ate the {@ link #alre adyNotifie d} array f rom | |
966 | * the {@code Ob servedObje ct} array list. | |
967 | */ | |
968 | synchr onized voi d createAl readyNotif ied() { | |
969 | // Update el ementCount . | |
970 | // | |
971 | el ementCount = observe dObjects.s ize(); | |
972 | ||
973 | // Update ar rays. | |
974 | // | |
975 | al readyNotif ieds = new int[eleme ntCount]; | |
976 | fo r (int i = 0; i < el ementCount ; i++) { | |
977 | alreadyN otifieds[i ] = observ edObjects. get(i).get AlreadyNot ified(); | |
978 | } | |
979 | up dateDeprec atedAlread yNotified( ); | |
980 | } | |
981 | ||
982 | /** | |
983 | * Upd ate the de precated { @link #alr eadyNotifi ed} field. | |
984 | */ | |
985 | synchr onized voi d updateDe precatedAl readyNotif ied() { | |
986 | if (elementC ount > 0) | |
987 | alreadyN otified = alreadyNot ifieds[0]; | |
988 | el se | |
989 | alreadyN otified = 0; | |
990 | } | |
991 | ||
992 | /** | |
993 | * Upd ate the {@ link #alre adyNotifie ds} array element at the given index | |
994 | * wit h the alre ady notifi ed flag in the given {@code Ob servedObje ct}. | |
995 | * Ens ure the de precated { @link #alr eadyNotifi ed} field is updated | |
996 | * if appropriat e. | |
997 | */ | |
998 | synchr onized voi d updateAl readyNotif ied(Observ edObject o , int inde x) { | |
999 | al readyNotif ieds[index ] = o.getA lreadyNoti fied(); | |
1000 | if (index == 0) | |
1001 | updateDe precatedAl readyNotif ied(); | |
1002 | } | |
1003 | ||
1004 | /** | |
1005 | * Che ck if the given bits in the gi ven elemen t of {@lin k #already Notifieds} | |
1006 | * are set. | |
1007 | */ | |
1008 | synchr onized boo lean isAlr eadyNotifi ed(Observe dObject o, int mask) { | |
1009 | re turn ((o.g etAlreadyN otified() & mask) != 0); | |
1010 | } | |
1011 | ||
1012 | /** | |
1013 | * Set the given bits in t he given e lement of {@link #al readyNotif ieds}. | |
1014 | * Ens ure the de precated { @link #alr eadyNotifi ed} field is updated | |
1015 | * if appropriat e. | |
1016 | */ | |
1017 | synchr onized voi d setAlrea dyNotified (ObservedO bject o, i nt index, | |
1018 | int mask, int an[]) { | |
1019 | fi nal int i = computeA lreadyNoti fiedIndex( o, index, an); | |
1020 | if (i == -1) | |
1021 | return; | |
1022 | o. setAlready Notified(o .getAlread yNotified( ) | mask); | |
1023 | up dateAlread yNotified( o, i); | |
1024 | } | |
1025 | ||
1026 | /** | |
1027 | * Res et the giv en bits in the given element o f {@link # alreadyNot ifieds}. | |
1028 | * Ens ure the de precated { @link #alr eadyNotifi ed} field is updated | |
1029 | * if appropriat e. | |
1030 | */ | |
1031 | synchr onized voi d resetAlr eadyNotifi ed(Observe dObject o, | |
1032 | int ind ex, int ma sk) { | |
1033 | o. setAlready Notified(o .getAlread yNotified( ) & ~mask) ; | |
1034 | up dateAlread yNotified( o, index); | |
1035 | } | |
1036 | ||
1037 | /** | |
1038 | * Res et all bit s in the g iven eleme nt of {@li nk #alread yNotifieds }. | |
1039 | * Ens ure the de precated { @link #alr eadyNotifi ed} field is updated | |
1040 | * if appropriat e. | |
1041 | */ | |
1042 | synchr onized voi d resetAll AlreadyNot ified(Obse rvedObject o, | |
1043 | int index, int an[]) { | |
1044 | fi nal int i = computeA lreadyNoti fiedIndex( o, index, an); | |
1045 | if (i == -1) | |
1046 | return; | |
1047 | o. setAlready Notified(R ESET_FLAGS _ALREADY_N OTIFIED); | |
1048 | up dateAlread yNotified( o, index); | |
1049 | } | |
1050 | ||
1051 | /** | |
1052 | * Che ck if the {@link #al readyNotif ieds} arra y has been modified. | |
1053 | * If true recom pute the i ndex for t he given o bserved ob ject. | |
1054 | */ | |
1055 | synchr onized int computeAl readyNotif iedIndex(O bservedObj ect o, | |
1056 | i nt index, int an[]) { | |
1057 | if (an == al readyNotif ieds) { | |
1058 | return i ndex; | |
1059 | } else { | |
1060 | return o bservedObj ects.index Of(o); | |
1061 | } | |
1062 | } | |
1063 | ||
1064 | /* | |
1065 | * --- ---------- ---------- ---------- --------- | |
1066 | * PRI D A N E S M T ODS | |
1067 | * --- ---------- ---------- ---------- --------- | |
1068 | */ | |
1069 | ||
1070 | /** | |
1071 | * Thi s method i s used by the monito r MBean to create an d send a | |
1072 | * mon itor notif ication to all the l isteners r egistered for this | |
1073 | * kin d of notif ication. | |
1074 | * | |
1075 | * @pa ram type T he notific ation type . | |
1076 | * @pa ram timeSt amp The no tification emission date. | |
1077 | * @pa ram msg Th e notifica tion messa ge. | |
1078 | * @pa ram derGau ge The der ived gauge . | |
1079 | * @pa ram trigge r The thre shold/stri ng (depend ing on the monitor | |
1080 | * typ e) that tr iggered of f the noti fication. | |
1081 | * @pa ram object The Objec tName of t he observe d object t hat trigge red | |
1082 | * off the notif ication. | |
1083 | * @pa ram onErro r Flag ind icating if this moni tor notifi cation is | |
1084 | * an error noti fication o r an alarm notificat ion. | |
1085 | */ | |
1086 | privat e void sen dNotificat ion(String type, lon g timeStam p, String msg, | |
1087 | Object derGauge, Object tr igger, | |
1088 | Object Name objec t, boolean onError) { | |
1089 | if (!isActiv e()) | |
1090 | return; | |
1091 | ||
1092 | if (MONITOR_ LOGGER.isL oggable(Le vel.FINER) ) { | |
1093 | MONITOR_ LOGGER.log p(Level.FI NER, Monit or.class.g etName(), | |
1094 | "sendNotif ication", "send noti fication: " + | |
1095 | "\n\tNotif ication ob served obj ect = " + object + | |
1096 | "\n\tNotif ication ob served att ribute = " + observe dAttribute + | |
1097 | "\n\tNotif ication de rived gaug e = " + de rGauge); | |
1098 | } | |
1099 | ||
1100 | lo ng seqno = sequenceN umber.getA ndIncremen t(); | |
1101 | ||
1102 | Mo nitorNotif ication mn = | |
1103 | new Moni torNotific ation(type , | |
1104 | this , | |
1105 | seqn o, | |
1106 | time Stamp, | |
1107 | msg, | |
1108 | obje ct, | |
1109 | obse rvedAttrib ute, | |
1110 | derG auge, | |
1111 | trig ger); | |
1112 | if (onError) | |
1113 | onErrorN otificatio n(mn); | |
1114 | se ndNotifica tion(mn); | |
1115 | } | |
1116 | ||
1117 | /** | |
1118 | * Thi s method i s called b y the moni tor each t ime | |
1119 | * the granulari ty period has been e xceeded. | |
1120 | * @pa ram o The observed o bject. | |
1121 | */ | |
1122 | privat e void mon itor(Obser vedObject o, int ind ex, int an []) { | |
1123 | ||
1124 | St ring attri bute; | |
1125 | St ring notif Type = nul l; | |
1126 | St ring msg = null; | |
1127 | Ob ject derGa uge = null ; | |
1128 | Ob ject trigg er = null; | |
1129 | Ob jectName o bject; | |
1130 | Co mparable<? > value = null; | |
1131 | Mo nitorNotif ication al arm = null ; | |
1132 | ||
1133 | if (!isActiv e()) | |
1134 | return; | |
1135 | ||
1136 | // Check tha t neither the observ ed object nor the | |
1137 | // observed attribute are null. If the ob served | |
1138 | // object or observed attribute is null, t his means | |
1139 | // that the monitor st arted befo re a compl ete | |
1140 | // initializ ation and nothing is done. | |
1141 | // | |
1142 | sy nchronized (this) { | |
1143 | object = o.getObse rvedObject (); | |
1144 | attribut e = getObs ervedAttri bute(); | |
1145 | if (obje ct == null || attrib ute == nul l) { | |
1146 | retu rn; | |
1147 | } | |
1148 | } | |
1149 | ||
1150 | // Check tha t the obse rved objec t is regis tered in t he | |
1151 | // MBean ser ver and th at the obs erved attr ibute | |
1152 | // belongs t o the obse rved objec t. | |
1153 | // | |
1154 | Ob ject attri buteValue = null; | |
1155 | tr y { | |
1156 | attribut eValue = g etAttribut e(server, object, at tribute); | |
1157 | if (attr ibuteValue == null) | |
1158 | if ( isAlreadyN otified( | |
1159 | o, OBS ERVED_ATTR IBUTE_TYPE _ERROR_NOT IFIED)) | |
1160 | return; | |
1161 | else { | |
1162 | notifType = OBSERVED _ATTRIBUTE _TYPE_ERRO R; | |
1163 | setAlready Notified( | |
1164 | o, ind ex, OBSERV ED_ATTRIBU TE_TYPE_ER ROR_NOTIFI ED, an); | |
1165 | msg = "The observed attribute value is n ull."; | |
1166 | MONITOR_LO GGER.logp( Level.FINE ST, Monito r.class.ge tName(), | |
1167 | "m onitor", m sg); | |
1168 | } | |
1169 | } catch (Nul lPointerEx ception np _ex) { | |
1170 | if (isAl readyNotif ied(o, RUN TIME_ERROR _NOTIFIED) ) | |
1171 | retu rn; | |
1172 | else { | |
1173 | noti fType = RU NTIME_ERRO R; | |
1174 | setA lreadyNoti fied(o, in dex, RUNTI ME_ERROR_N OTIFIED, a n); | |
1175 | msg = | |
1176 | "The monit or must be registere d in the M Bean " + | |
1177 | "server or an MBeanS erverConne ction must be " + | |
1178 | "explicitl y supplied ."; | |
1179 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1180 | "monit or", msg); | |
1181 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1182 | "monit or", np_ex .toString( )); | |
1183 | } | |
1184 | } catch (Ins tanceNotFo undExcepti on inf_ex) { | |
1185 | if (isAl readyNotif ied(o, OBS ERVED_OBJE CT_ERROR_N OTIFIED)) | |
1186 | retu rn; | |
1187 | else { | |
1188 | noti fType = OB SERVED_OBJ ECT_ERROR; | |
1189 | setA lreadyNoti fied( | |
1190 | o, index, OBSERVED_O BJECT_ERRO R_NOTIFIED , an); | |
1191 | msg = | |
1192 | "The obser ved object must be a ccessible in " + | |
1193 | "the MBean ServerConn ection."; | |
1194 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1195 | "monit or", msg); | |
1196 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1197 | "monit or", inf_e x.toString ()); | |
1198 | } | |
1199 | } catch (Att ributeNotF oundExcept ion anf_ex ) { | |
1200 | if (isAl readyNotif ied(o, OBS ERVED_ATTR IBUTE_ERRO R_NOTIFIED )) | |
1201 | retu rn; | |
1202 | else { | |
1203 | noti fType = OB SERVED_ATT RIBUTE_ERR OR; | |
1204 | setA lreadyNoti fied( | |
1205 | o, index, OBSERVED_A TTRIBUTE_E RROR_NOTIF IED, an); | |
1206 | msg = | |
1207 | "The obser ved attrib ute must b e accessib le in " + | |
1208 | "the obser ved object ."; | |
1209 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1210 | "monit or", msg); | |
1211 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1212 | "monit or", anf_e x.toString ()); | |
1213 | } | |
1214 | } catch (MBe anExceptio n mb_ex) { | |
1215 | if (isAl readyNotif ied(o, RUN TIME_ERROR _NOTIFIED) ) | |
1216 | retu rn; | |
1217 | else { | |
1218 | noti fType = RU NTIME_ERRO R; | |
1219 | setA lreadyNoti fied(o, in dex, RUNTI ME_ERROR_N OTIFIED, a n); | |
1220 | msg = mb_ex.ge tMessage() == null ? "" : mb_e x.getMessa ge(); | |
1221 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1222 | "monit or", msg); | |
1223 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1224 | "monit or", mb_ex .toString( )); | |
1225 | } | |
1226 | } catch (Ref lectionExc eption ref _ex) { | |
1227 | if (isAl readyNotif ied(o, RUN TIME_ERROR _NOTIFIED) ) { | |
1228 | retu rn; | |
1229 | } else { | |
1230 | noti fType = RU NTIME_ERRO R; | |
1231 | setA lreadyNoti fied(o, in dex, RUNTI ME_ERROR_N OTIFIED, a n); | |
1232 | msg = ref_ex.g etMessage( ) == null ? "" : ref _ex.getMes sage(); | |
1233 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1234 | "monit or", msg); | |
1235 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1236 | "monit or", ref_e x.toString ()); | |
1237 | } | |
1238 | } catch (IOE xception i o_ex) { | |
1239 | if (isAl readyNotif ied(o, RUN TIME_ERROR _NOTIFIED) ) | |
1240 | retu rn; | |
1241 | else { | |
1242 | noti fType = RU NTIME_ERRO R; | |
1243 | setA lreadyNoti fied(o, in dex, RUNTI ME_ERROR_N OTIFIED, a n); | |
1244 | msg = io_ex.ge tMessage() == null ? "" : io_e x.getMessa ge(); | |
1245 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1246 | "monit or", msg); | |
1247 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1248 | "monit or", io_ex .toString( )); | |
1249 | } | |
1250 | } catch (Run timeExcept ion rt_ex) { | |
1251 | if (isAl readyNotif ied(o, RUN TIME_ERROR _NOTIFIED) ) | |
1252 | retu rn; | |
1253 | else { | |
1254 | noti fType = RU NTIME_ERRO R; | |
1255 | setA lreadyNoti fied(o, in dex, RUNTI ME_ERROR_N OTIFIED, a n); | |
1256 | msg = rt_ex.ge tMessage() == null ? "" : rt_e x.getMessa ge(); | |
1257 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1258 | "monit or", msg); | |
1259 | MONI TOR_LOGGER .logp(Leve l.FINEST, Monitor.cl ass.getNam e(), | |
1260 | "monit or", rt_ex .toString( )); | |
1261 | } | |
1262 | } | |
1263 | ||
1264 | sy nchronized (this) { | |
1265 | ||
1266 | // Check if the mo nitor has been stopp ed. | |
1267 | // | |
1268 | if (!isA ctive()) | |
1269 | retu rn; | |
1270 | ||
1271 | // Check if the ob served att ribute has been chan ged. | |
1272 | // | |
1273 | // Avoid race cond ition wher e mbs.getA ttribute() succeeded but | |
1274 | // anoth er thread replaced t he observe d attribut e meanwhil e. | |
1275 | // | |
1276 | // Avoid setting c omputed de rived gaug e on erron eous attri bute. | |
1277 | // | |
1278 | if (!att ribute.equ als(getObs ervedAttri bute())) | |
1279 | retu rn; | |
1280 | ||
1281 | // Deriv e a Compar able objec t from the ObservedA ttribute v alue | |
1282 | // if th e type of the Observ edAttribut e value is a complex type. | |
1283 | // | |
1284 | if (msg == null) { | |
1285 | try { | |
1286 | value = ge tComparabl eFromAttri bute(objec t, | |
1287 | attri bute, | |
1288 | attri buteValue) ; | |
1289 | } ca tch (Class CastExcept ion e) { | |
1290 | if (isAlre adyNotifie d( | |
1291 | o, OBSERVED_ ATTRIBUTE_ TYPE_ERROR _NOTIFIED) ) | |
1292 | return ; | |
1293 | else { | |
1294 | notifT ype = OBSE RVED_ATTRI BUTE_TYPE_ ERROR; | |
1295 | setAlr eadyNotifi ed(o, inde x, | |
1296 | OB SERVED_ATT RIBUTE_TYP E_ERROR_NO TIFIED, an ); | |
1297 | msg = | |
1298 | "T he observe d attribut e value do es not " + | |
1299 | "i mplement t he Compara ble interf ace."; | |
1300 | MONITO R_LOGGER.l ogp(Level. FINEST, | |
1301 | Monitor. class.getN ame(), "mo nitor", ms g); | |
1302 | MONITO R_LOGGER.l ogp(Level. FINEST, | |
1303 | Monitor. class.getN ame(), "mo nitor", e. toString() ); | |
1304 | } | |
1305 | } ca tch (Attri buteNotFou ndExceptio n e) { | |
1306 | if (isAlre adyNotifie d(o, OBSER VED_ATTRIB UTE_ERROR_ NOTIFIED)) | |
1307 | return ; | |
1308 | else { | |
1309 | notifT ype = OBSE RVED_ATTRI BUTE_ERROR ; | |
1310 | setAlr eadyNotifi ed( | |
1311 | o, index, OB SERVED_ATT RIBUTE_ERR OR_NOTIFIE D, an); | |
1312 | msg = | |
1313 | "T he observe d attribut e must be accessible in " + | |
1314 | "t he observe d object." ; | |
1315 | MONITO R_LOGGER.l ogp(Level. FINEST, | |
1316 | Monitor. class.getN ame(), "mo nitor", ms g); | |
1317 | MONITO R_LOGGER.l ogp(Level. FINEST, | |
1318 | Monitor. class.getN ame(), "mo nitor", e. toString() ); | |
1319 | } | |
1320 | } ca tch (Runti meExceptio n e) { | |
1321 | if (isAlre adyNotifie d(o, RUNTI ME_ERROR_N OTIFIED)) | |
1322 | return ; | |
1323 | else { | |
1324 | notifT ype = RUNT IME_ERROR; | |
1325 | setAlr eadyNotifi ed(o, inde x, | |
1326 | RU NTIME_ERRO R_NOTIFIED , an); | |
1327 | msg = e.getMessa ge() == nu ll ? "" : e.getMessa ge(); | |
1328 | MONITO R_LOGGER.l ogp(Level. FINEST, | |
1329 | Monitor. class.getN ame(), "mo nitor", ms g); | |
1330 | MONITO R_LOGGER.l ogp(Level. FINEST, | |
1331 | Monitor. class.getN ame(), "mo nitor", e. toString() ); | |
1332 | } | |
1333 | } | |
1334 | } | |
1335 | ||
1336 | // Check that the observed a ttribute t ype is sup ported by this | |
1337 | // monit or. | |
1338 | // | |
1339 | if (msg == null) { | |
1340 | if ( !isCompara bleTypeVal id(object, attribute , value)) { | |
1341 | if (isAlre adyNotifie d( | |
1342 | o, OBSERVED_ ATTRIBUTE_ TYPE_ERROR _NOTIFIED) ) | |
1343 | return ; | |
1344 | else { | |
1345 | notifT ype = OBSE RVED_ATTRI BUTE_TYPE_ ERROR; | |
1346 | setAlr eadyNotifi ed(o, inde x, | |
1347 | OB SERVED_ATT RIBUTE_TYP E_ERROR_NO TIFIED, an ); | |
1348 | msg = "The obser ved attrib ute type i s not vali d."; | |
1349 | MONITO R_LOGGER.l ogp(Level. FINEST, | |
1350 | Monitor. class.getN ame(), "mo nitor", ms g); | |
1351 | } | |
1352 | } | |
1353 | } | |
1354 | ||
1355 | // Check that thre shold type is suppor ted by thi s monitor. | |
1356 | // | |
1357 | if (msg == null) { | |
1358 | if ( !isThresho ldTypeVali d(object, attribute, value)) { | |
1359 | if (isAlre adyNotifie d(o, THRES HOLD_ERROR _NOTIFIED) ) | |
1360 | return ; | |
1361 | else { | |
1362 | notifT ype = THRE SHOLD_ERRO R; | |
1363 | setAlr eadyNotifi ed(o, inde x, | |
1364 | TH RESHOLD_ER ROR_NOTIFI ED, an); | |
1365 | msg = "The thres hold type is not val id."; | |
1366 | MONITO R_LOGGER.l ogp(Level. FINEST, | |
1367 | Monitor. class.getN ame(), "mo nitor", ms g); | |
1368 | } | |
1369 | } | |
1370 | } | |
1371 | ||
1372 | // Let s omeone sub classing t he monitor to perfor m addition al | |
1373 | // monit or consist ency check s and repo rt errors if necessa ry. | |
1374 | // | |
1375 | if (msg == null) { | |
1376 | msg = buildErr orNotifica tion(objec t, attribu te, value) ; | |
1377 | if ( msg != nul l) { | |
1378 | if (isAlre adyNotifie d(o, RUNTI ME_ERROR_N OTIFIED)) | |
1379 | return ; | |
1380 | else { | |
1381 | notifT ype = RUNT IME_ERROR; | |
1382 | setAlr eadyNotifi ed(o, inde x, | |
1383 | RU NTIME_ERRO R_NOTIFIED , an); | |
1384 | MONITO R_LOGGER.l ogp(Level. FINEST, | |
1385 | Monitor. class.getN ame(), "mo nitor", ms g); | |
1386 | } | |
1387 | } | |
1388 | } | |
1389 | ||
1390 | // If no errors we re found t hen clear all error flags and | |
1391 | // let t he monitor decide if a notific ation must be sent. | |
1392 | // | |
1393 | if (msg == null) { | |
1394 | // C lear all a lready not ified flag s. | |
1395 | // | |
1396 | rese tAllAlread yNotified( o, index, an); | |
1397 | ||
1398 | // G et derived gauge fro m comparab le value. | |
1399 | // | |
1400 | derG auge = get DerivedGau geFromComp arable(obj ect, | |
1401 | att ribute, | |
1402 | val ue); | |
1403 | ||
1404 | o.se tDerivedGa uge(derGau ge); | |
1405 | o.se tDerivedGa ugeTimeSta mp(System. currentTim eMillis()) ; | |
1406 | ||
1407 | // C heck if an alarm mus t be fired . | |
1408 | // | |
1409 | alar m = buildA larmNotifi cation(obj ect, | |
1410 | att ribute, | |
1411 | (Co mparable<? >) derGaug e); | |
1412 | } | |
1413 | ||
1414 | } | |
1415 | ||
1416 | // Notify mo nitor erro rs | |
1417 | // | |
1418 | if (msg != n ull) | |
1419 | sendNoti fication(n otifType, | |
1420 | S ystem.curr entTimeMil lis(), | |
1421 | m sg, | |
1422 | d erGauge, | |
1423 | t rigger, | |
1424 | o bject, | |
1425 | t rue); | |
1426 | ||
1427 | // Notify mo nitor alar ms | |
1428 | // | |
1429 | if (alarm != null && a larm.getTy pe() != nu ll) | |
1430 | sendNoti fication(a larm.getTy pe(), | |
1431 | S ystem.curr entTimeMil lis(), | |
1432 | a larm.getMe ssage(), | |
1433 | d erGauge, | |
1434 | a larm.getTr igger(), | |
1435 | o bject, | |
1436 | f alse); | |
1437 | } | |
1438 | ||
1439 | /** | |
1440 | * Cle anup the s cheduler a nd monitor tasks fut ures. | |
1441 | */ | |
1442 | privat e synchron ized void cleanupFut ures() { | |
1443 | if (schedule rFuture != null) { | |
1444 | schedule rFuture.ca ncel(false ); | |
1445 | schedule rFuture = null; | |
1446 | } | |
1447 | if (monitorF uture != n ull) { | |
1448 | monitorF uture.canc el(false); | |
1449 | monitorF uture = nu ll; | |
1450 | } | |
1451 | } | |
1452 | ||
1453 | /** | |
1454 | * Cle anup the " is complex type attr ibute" inf o. | |
1455 | */ | |
1456 | privat e synchron ized void cleanupIsC omplexType Attribute( ) { | |
1457 | fi rstAttribu te = null; | |
1458 | re mainingAtt ributes.cl ear(); | |
1459 | is ComplexTyp eAttribute = false; | |
1460 | } | |
1461 | ||
1462 | /** | |
1463 | * Sch edulerTask nested cl ass: This class impl ements the Runnable interface. | |
1464 | * | |
1465 | * The Scheduler Task is ex ecuted per iodically with a giv en fixed d elay by | |
1466 | * the Scheduled Executor Service. | |
1467 | */ | |
1468 | privat e class Sc hedulerTas k implemen ts Runnabl e { | |
1469 | ||
1470 | pr ivate Moni torTask ta sk; | |
1471 | ||
1472 | /* | |
1473 | * --------- ---------- ---------- ---------- --- | |
1474 | * CONSTRUC TORS | |
1475 | * --------- ---------- ---------- ---------- --- | |
1476 | * / | |
1477 | ||
1478 | pu blic Sched ulerTask() { | |
1479 | } | |
1480 | ||
1481 | /* | |
1482 | * --------- ---------- ---------- ---------- --- | |
1483 | * GETTERS/ SETTERS | |
1484 | * --------- ---------- ---------- ---------- --- | |
1485 | * / | |
1486 | ||
1487 | pu blic void setMonitor Task(Monit orTask tas k) { | |
1488 | this.tas k = task; | |
1489 | } | |
1490 | ||
1491 | /* | |
1492 | * --------- ---------- ---------- ---------- --- | |
1493 | * PUBLIC M ETHODS | |
1494 | * --------- ---------- ---------- ---------- --- | |
1495 | * / | |
1496 | ||
1497 | pu blic void run() { | |
1498 | synchron ized (Moni tor.this) { | |
1499 | Moni tor.this.m onitorFutu re = task. submit(); | |
1500 | } | |
1501 | } | |
1502 | } | |
1503 | ||
1504 | /** | |
1505 | * Mon itorTask n ested clas s: This cl ass implem ents the R unnable in terface. | |
1506 | * | |
1507 | * The MonitorTa sk is exec uted perio dically wi th a given fixed del ay by the | |
1508 | * Sch eduled Exe cutor Serv ice. | |
1509 | */ | |
1510 | privat e class Mo nitorTask implements Runnable { | |
1511 | ||
1512 | pr ivate Thre adPoolExec utor execu tor; | |
1513 | ||
1514 | /* | |
1515 | * --------- ---------- ---------- ---------- --- | |
1516 | * CONSTRUC TORS | |
1517 | * --------- ---------- ---------- ---------- --- | |
1518 | * / | |
1519 | ||
1520 | pu blic Monit orTask() { | |
1521 | // Find out if the re's alrea dy an exis ting execu tor for th e calling | |
1522 | // threa d and reus e it. Othe rwise, cre ate a new one and st ore it in | |
1523 | // the e xecutors m ap. If the re is a Se curityMana ger, the g roup of | |
1524 | // Syste m.getSecur ityManager () is used , else the group of the thread | |
1525 | // insta ntiating t his Monito rTask, i.e . the grou p of the t hread that | |
1526 | // calls "Monitor. start()". | |
1527 | Security Manager s = System.g etSecurity Manager(); | |
1528 | ThreadGr oup group = (s != nu ll) ? s.ge tThreadGro up() : | |
1529 | Thre ad.current Thread().g etThreadGr oup(); | |
1530 | synchron ized (exec utorsLock) { | |
1531 | for (ThreadPoo lExecutor e : execut ors.keySet ()) { | |
1532 | DaemonThre adFactory tf = | |
1533 | (D aemonThrea dFactory) e.getThrea dFactory() ; | |
1534 | ThreadGrou p tg = tf. getThreadG roup(); | |
1535 | if (tg == group) { | |
1536 | execut or = e; | |
1537 | break; | |
1538 | } | |
1539 | } | |
1540 | if ( executor = = null) { | |
1541 | executor = new Threa dPoolExecu tor( | |
1542 | ma ximumPoolS ize, | |
1543 | ma ximumPoolS ize, | |
1544 | 60 L, | |
1545 | Ti meUnit.SEC ONDS, | |
1546 | ne w LinkedBl ockingQueu e<Runnable >(), | |
1547 | ne w DaemonTh readFactor y("ThreadG roup<" + | |
1548 | gr oup.getNam e() + "> E xecutor", group)); | |
1549 | executor.a llowCoreTh readTimeOu t(true); | |
1550 | executors. put(execut or, null); | |
1551 | } | |
1552 | } | |
1553 | } | |
1554 | ||
1555 | /* | |
1556 | * --------- ---------- ---------- ---------- --- | |
1557 | * PUBLIC M ETHODS | |
1558 | * --------- ---------- ---------- ---------- --- | |
1559 | * / | |
1560 | ||
1561 | pu blic Futur e<?> submi t() { | |
1562 | return e xecutor.su bmit(this) ; | |
1563 | } | |
1564 | ||
1565 | pu blic void run() { | |
1566 | final Sc heduledFut ure<?> sf; | |
1567 | final Ac cessContro lContext a c; | |
1568 | synchron ized (Moni tor.this) { | |
1569 | sf = Monitor.t his.schedu lerFuture; | |
1570 | ac = Monitor.t his.acc; | |
1571 | } | |
1572 | Privileg edAction<V oid> actio n = new Pr ivilegedAc tion<Void> () { | |
1573 | publ ic Void ru n() { | |
1574 | if (Monito r.this.isA ctive()) { | |
1575 | final int an[] = alreadyNo tifieds; | |
1576 | int in dex = 0; | |
1577 | for (O bservedObj ect o : Mo nitor.this .observedO bjects) { | |
1578 | if (Monitor. this.isAct ive()) { | |
1579 | Monitor. this.monit or(o, inde x++, an); | |
1580 | } | |
1581 | } | |
1582 | } | |
1583 | return nul l; | |
1584 | } | |
1585 | }; | |
1586 | if (ac = = null) { | |
1587 | thro w new Secu rityExcept ion("Acces sControlCo ntext cann ot be null "); | |
1588 | } | |
1589 | AccessCo ntroller.d oPrivilege d(action, ac); | |
1590 | synchron ized (Moni tor.this) { | |
1591 | if ( Monitor.th is.isActiv e() && | |
1592 | Monitor.th is.schedul erFuture = = sf) { | |
1593 | Monitor.th is.monitor Future = n ull; | |
1594 | Monitor.th is.schedul erFuture = | |
1595 | schedu ler.schedu le(Monitor .this.sche dulerTask, | |
1596 | Monitor .this.getG ranularity Period(), | |
1597 | TimeUni t.MILLISEC ONDS); | |
1598 | } | |
1599 | } | |
1600 | } | |
1601 | } | |
1602 | ||
1603 | /** | |
1604 | * Dae mon thread factory u sed by the monitor e xecutors. | |
1605 | * <P> | |
1606 | * Thi s factory creates al l new thre ads used b y an Execu tor in | |
1607 | * the same Thre adGroup. I f there is a Securit yManager, it uses | |
1608 | * the group of System.get SecurityMa nager(), e lse the gr oup of | |
1609 | * the thread in stantiatin g this Dae monThreadF actory. Ea ch new | |
1610 | * thr ead is cre ated as a daemon thr ead with p riority | |
1611 | * Thr ead.NORM_P RIORITY. N ew threads have name s accessib le via | |
1612 | * Thr ead.getNam e() of "{@ literal JM X Monitor <pool-name > Pool [Th read-M]}", | |
1613 | * whe re M is th e sequence number of the threa d created by this | |
1614 | * fac tory. | |
1615 | */ | |
1616 | privat e static c lass Daemo nThreadFac tory imple ments Thre adFactory { | |
1617 | fi nal Thread Group grou p; | |
1618 | fi nal Atomic Integer th readNumber = new Ato micInteger (1); | |
1619 | fi nal String namePrefi x; | |
1620 | st atic final String na meSuffix = "]"; | |
1621 | ||
1622 | pu blic Daemo nThreadFac tory(Strin g poolName ) { | |
1623 | Security Manager s = System.g etSecurity Manager(); | |
1624 | group = (s != null ) ? s.getT hreadGroup () : | |
1625 | Thread .currentTh read().get ThreadGrou p(); | |
1626 | namePref ix = "JMX Monitor " + poolName + " Pool [Thread-"; | |
1627 | } | |
1628 | ||
1629 | pu blic Daemo nThreadFac tory(Strin g poolName , ThreadGr oup thread Group) { | |
1630 | group = threadGrou p; | |
1631 | namePref ix = "JMX Monitor " + poolName + " Pool [Thread-"; | |
1632 | } | |
1633 | ||
1634 | pu blic Threa dGroup get ThreadGrou p() { | |
1635 | return g roup; | |
1636 | } | |
1637 | ||
1638 | pu blic Threa d newThrea d(Runnable r) { | |
1639 | Thread t = new Thr ead(group, | |
1640 | r, | |
1641 | namePr efix + | |
1642 | thread Number.get AndIncreme nt() + | |
1643 | nameSu ffix, | |
1644 | 0); | |
1645 | t.setDae mon(true); | |
1646 | if (t.ge tPriority( ) != Threa d.NORM_PRI ORITY) | |
1647 | t.se tPriority( Thread.NOR M_PRIORITY ); | |
1648 | return t ; | |
1649 | } | |
1650 | } | |
1651 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.