KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > selfmanagement > event > MonitorEventFactory


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * MonitorEventFactory.java
26  *
27  * Created on May 24, 2005, 3:48 PM
28  */

29
30 package com.sun.enterprise.admin.selfmanagement.event;
31
32
33 import javax.management.NotificationEmitter JavaDoc;
34 import javax.management.monitor.CounterMonitor JavaDoc;
35 import javax.management.monitor.GaugeMonitor JavaDoc;
36 import javax.management.monitor.StringMonitor JavaDoc;
37 import javax.management.monitor.Monitor JavaDoc;
38 import javax.management.MBeanServer JavaDoc;
39 import java.util.Hashtable JavaDoc;
40 import javax.management.ObjectName JavaDoc;
41 import java.util.logging.Level JavaDoc;
42
43 import com.sun.enterprise.server.ApplicationServer;
44 import com.sun.enterprise.config.serverbeans.ElementProperty;
45 import java.util.regex.Pattern JavaDoc;
46 import java.util.regex.Matcher JavaDoc;
47 import static com.sun.enterprise.admin.selfmanagement.event.ManagementRuleConstants.*;
48
49 /**
50  *
51  * This is the factory class to create and configure MonitorEventType.
52  *
53  * @author Sun Micro Systens, Inc
54  */

55
56 public class MonitorEventFactory extends EventAbstractFactory {
57     
58     private MonitorEventFactory( ) {
59         super();
60         EventBuilder.getInstance().addEventFactory(EVENT_MONITOR, this);
61     }
62     
63     
64     public Event instrumentEvent(
65             ElementProperty[] properties, String JavaDoc description ) {
66         if( properties == null ){
67             throw new IllegalArgumentException JavaDoc(
68                     sm.getString("selfmgmt_event.invalid_event_property","null properties","monitor"));
69         }
70         Hashtable JavaDoc<String JavaDoc, String JavaDoc> table = new Hashtable JavaDoc<String JavaDoc,String JavaDoc>();
71         for( int i = 0; i < properties.length; i++ ){
72             table.put( properties[i].getName( ).toLowerCase(), properties[i].getValue());
73         }
74
75         boolean isMustang = false;
76         boolean isComplexType = false;
77
78         String JavaDoc monitorType = table.get(PROPERTY_MONITOR_TYPE);
79         if (monitorType == null)
80             monitorType = PROPERTY_MONITOR_COUNTER;
81         else
82             monitorType = monitorType.toLowerCase();
83         
84         String JavaDoc observedAttribute = table.get(PROPERTY_MONITOR_OBSERVED_ATTRIBUTE);
85         if (observedAttribute == null) {
86             throw new IllegalArgumentException JavaDoc(
87                     sm.getString("selfmgmt_event.invalid_event_property",PROPERTY_MONITOR_OBSERVED_ATTRIBUTE,"monitor"));
88         }
89
90         if (observedAttribute.indexOf('.') != -1) {
91             isComplexType = true;
92         }
93         Float JavaDoc jdkVersion = new Float JavaDoc( System.getProperty("java.specification.version") );
94         if( jdkVersion != null ) {
95             if( jdkVersion.floatValue() >= 1.5 )
96                 isMustang = true;
97         } else {
98             Float JavaDoc javaVersion = new Float JavaDoc( System.getProperty("java.version") );
99             if( javaVersion.floatValue() >= 1.5 )
100                 isMustang = true;
101         }
102
103         if( isMustang && isComplexType ) {
104             StatisticMonitor monitor = null;
105             if( monitorType.equals(PROPERTY_MONITOR_COUNTER)){
106                 monitor = createCounterStatisticMonitor(table);
107             } else if( monitorType.equals(PROPERTY_MONITOR_GAUGE)){
108                 monitor = createGaugeStatisticMonitor(table);
109             } else if( monitorType.equals(PROPERTY_MONITOR_STRING)) {
110                 monitor = createStringStatisticMonitor(table);
111             }
112             if( monitor == null ){
113                 _logger.log(Level.WARNING,"smgt.internal_error");
114                 return null;
115             }
116             try {
117                 String JavaDoc sourceMbeanObjName = null;
118                 String JavaDoc sourceMbeanName = null;
119                 if (table.containsKey(PROPERTY_MONITOR_OBSERVED_OBJ)) {
120                     sourceMbeanObjName = table.get(PROPERTY_MONITOR_OBSERVED_OBJ);
121                 } else if (table.containsKey(PROPERTY_MONITOR_OBSERVED_OBJ_MBEAN_NAME)) {
122                     sourceMbeanName = table.get(PROPERTY_MONITOR_OBSERVED_OBJ_MBEAN_NAME);
123                 }
124                 if (sourceMbeanName == null && sourceMbeanObjName == null) {
125                     throw new IllegalArgumentException JavaDoc(
126                             sm.getString("selfmgmt_event.invalid_event_property","observedobject","monitor"));
127                 }
128                 String JavaDoc sourceMbean = null;
129                 if(sourceMbeanObjName != null) {
130                     //final String serverNameVal = System.getProperty("com.sun.aas.instanceName");
131
Pattern JavaDoc pat = Pattern.compile("\\$\\{instance.name\\}");
132                     Matcher JavaDoc m = pat.matcher(sourceMbeanObjName);
133                     if(m.find()) {
134                         sourceMbean = m.replaceAll(instanceName);
135                     } else {
136                         sourceMbean = sourceMbeanObjName;
137                     }
138                 } else if(sourceMbeanName != null) {
139                     sourceMbean = ManagementRulesMBeanHelper.getObjName(sourceMbeanName);
140                 }
141                 /*if (!(sourceMbean.endsWith(",server=" + instanceName))) {
142                     sourceMbean = sourceMbean + ",server=" + instanceName;
143                 }*/

144                 ObjectName JavaDoc objName = new ObjectName JavaDoc(sourceMbean);
145                 //ObjectName objName = new ObjectName(table.get(PROPERTY_MONITOR_OBSERVED_OBJ));
146
monitor.addObservedObject(objName);
147             } catch (Exception JavaDoc ex) {
148                 throw new IllegalArgumentException JavaDoc(
149                     sm.getString("selfmgmt_event.invalid_event_property","observedobject","monitor"), ex);
150             }
151
152             monitor.setObservedAttribute(observedAttribute);
153
154             String JavaDoc granularityPeriod = table.get(PROPERTY_MONITOR_GRANULARITY_PERIOD);
155             if (granularityPeriod != null) {
156                 try {
157                     long gPeriod = Long.parseLong(granularityPeriod);
158                     monitor.setGranularityPeriod(gPeriod);
159                 } catch (Exception JavaDoc ex) {
160                     throw new IllegalArgumentException JavaDoc(
161                             sm.getString("selfmgmt_event.invalid_event_property",PROPERTY_MONITOR_GRANULARITY_PERIOD,"monitor"), ex);
162                 }
163             }
164                                                                                                                                                
165             ObjectName JavaDoc objName = null;
166             try {
167                 table.put("version",getNewVersionString());
168                 Hashtable JavaDoc<String JavaDoc,String JavaDoc> t = (Hashtable JavaDoc<String JavaDoc,String JavaDoc>)table.clone();
169                 if(t.containsKey(PROPERTY_MONITOR_OBSERVED_OBJ_MBEAN_NAME)) {
170                     t.remove(PROPERTY_MONITOR_OBSERVED_OBJ_MBEAN_NAME);
171                 } else if(t.containsKey(PROPERTY_MONITOR_OBSERVED_OBJ)) {
172                     t.remove(PROPERTY_MONITOR_OBSERVED_OBJ);
173                 }
174                 objName = new ObjectName JavaDoc(MonitorEvent.DOMAIN_NAME,t);
175             } catch (Exception JavaDoc ex) {
176                 _logger.log(Level.WARNING,"smgt.internal_error", ex);
177             }
178             return new MonitorEvent(monitor,objName,description);
179
180         } else {
181             Monitor JavaDoc monitor = null;
182             if( monitorType.equals(PROPERTY_MONITOR_COUNTER)){
183                 monitor = createCounterMonitor(table);
184             } else if( monitorType.equals(PROPERTY_MONITOR_GAUGE)){
185                 monitor = createGaugeMonitor(table);
186             } else if( monitorType.equals(PROPERTY_MONITOR_STRING)) {
187                 monitor = createStringMonitor(table);
188             }
189             if( monitor == null ){
190                 _logger.log(Level.WARNING,"smgt.internal_error");
191                 return null;
192             }
193             try {
194                 String JavaDoc sourceMbeanObjName = null;
195                 String JavaDoc sourceMbeanName = null;
196                 if (table.containsKey(PROPERTY_MONITOR_OBSERVED_OBJ)) {
197                     sourceMbeanObjName = table.get(PROPERTY_MONITOR_OBSERVED_OBJ);
198                 } else if (table.containsKey(PROPERTY_MONITOR_OBSERVED_OBJ_MBEAN_NAME)) {
199                     sourceMbeanName = table.get(PROPERTY_MONITOR_OBSERVED_OBJ_MBEAN_NAME);
200                 }
201                 if (sourceMbeanName == null && sourceMbeanObjName == null) {
202                     throw new IllegalArgumentException JavaDoc(
203                             sm.getString("selfmgmt_event.invalid_event_property","observedobject","monitor"));
204                 }
205                 String JavaDoc sourceMbean = null;
206                 if(sourceMbeanObjName != null) {
207                     //final String serverNameVal = System.getProperty("com.sun.aas.instanceName");
208
Pattern JavaDoc pat = Pattern.compile("\\$\\{instance.name\\}");
209                     Matcher JavaDoc m = pat.matcher(sourceMbeanObjName);
210                     if(m.find()) {
211                         sourceMbean = m.replaceAll(instanceName);
212                     } else {
213                         sourceMbean = sourceMbeanObjName;
214                     }
215                 } else if(sourceMbeanName != null) {
216                     sourceMbean = ManagementRulesMBeanHelper.getObjName(sourceMbeanName);
217                 }
218                 /*if (!(sourceMbean.endsWith(",server=" + instanceName))) {
219                     sourceMbean = sourceMbean + ",server=" + instanceName;
220                 }*/

221                 ObjectName JavaDoc objName = new ObjectName JavaDoc(sourceMbean);
222                 //ObjectName objName = new ObjectName(table.get(PROPERTY_MONITOR_OBSERVED_OBJ));
223
monitor.addObservedObject(objName);
224             } catch (Exception JavaDoc ex) {
225                 throw new IllegalArgumentException JavaDoc(
226                     sm.getString("selfmgmt_event.invalid_event_property","observedobject","monitor"), ex);
227             }
228             monitor.setObservedAttribute(observedAttribute);
229             String JavaDoc granularityPeriod = table.get(PROPERTY_MONITOR_GRANULARITY_PERIOD);
230             if (granularityPeriod != null) {
231                 try {
232                     long gPeriod = Long.parseLong(granularityPeriod);
233                     monitor.setGranularityPeriod(gPeriod);
234                 } catch (Exception JavaDoc ex) {
235                     throw new IllegalArgumentException JavaDoc(
236                             sm.getString("selfmgmt_event.invalid_event_property",PROPERTY_MONITOR_GRANULARITY_PERIOD,"monitor"), ex);
237                 }
238             }
239                                                                                                                                                
240             ObjectName JavaDoc objName = null;
241             try {
242                 table.put("version",getNewVersionString());
243                 Hashtable JavaDoc<String JavaDoc,String JavaDoc> t = (Hashtable JavaDoc<String JavaDoc,String JavaDoc>)table.clone();
244                 if(t.containsKey(PROPERTY_MONITOR_OBSERVED_OBJ_MBEAN_NAME)) {
245                     t.remove(PROPERTY_MONITOR_OBSERVED_OBJ_MBEAN_NAME);
246                 } else if(t.containsKey(PROPERTY_MONITOR_OBSERVED_OBJ)) {
247                     t.remove(PROPERTY_MONITOR_OBSERVED_OBJ);
248                 }
249                 //t.remove(PROPERTY_MONITOR_OBSERVED_OBJ);
250
objName = new ObjectName JavaDoc(MonitorEvent.DOMAIN_NAME,t);
251             } catch (Exception JavaDoc ex) {
252                 _logger.log(Level.WARNING,"smgt.internal_error", ex);
253             }
254             return new MonitorEvent(monitor,objName,description);
255
256         }
257     }
258    
259     private Monitor JavaDoc createCounterMonitor(Hashtable JavaDoc<String JavaDoc,String JavaDoc> table) {
260         CounterMonitor JavaDoc monitor = null;
261         try {
262             monitor = (CounterMonitor JavaDoc)getMBeanServer().instantiate("javax.management.monitor.CounterMonitor");
263         } catch ( Exception JavaDoc rex) {
264             _logger.log(Level.WARNING,"smgt.internal_error", rex);
265         }
266         String JavaDoc strDiffMode = table.get(PROPERTY_MONITOR_DIFFERENCEMODE);
267         if (strDiffMode != null) {
268             try {
269                 boolean diffMode = Boolean.parseBoolean(strDiffMode);
270                 monitor.setDifferenceMode(diffMode);
271             } catch (Exception JavaDoc ex) {
272                 throw new IllegalArgumentException JavaDoc(
273                         sm.getString("selfmgmt_event.invalid_event_property",PROPERTY_MONITOR_DIFFERENCEMODE,"monitor"), ex);
274             }
275         }
276         
277         String JavaDoc numberType = table.get(PROPERTY_MONITOR_NUMBERTYPE);
278         if (numberType == null)
279             numberType = "long";
280         String JavaDoc initTheshold = table.get(PROPERTY_MONITOR_INIT_THRESHOLD);
281         String JavaDoc strOffset = table.get(PROPERTY_MONITOR_OFFSET);
282         String JavaDoc strModulus = table.get(PROPERTY_MONITOR_MODULUS);
283         Number JavaDoc threshold = null;
284         Number JavaDoc offset = null;
285         Number JavaDoc modulus = null;
286         if (initTheshold == null) {
287             throw new IllegalArgumentException JavaDoc(
288                     sm.getString("selfmgmt_event.invalid_event_property",PROPERTY_MONITOR_INIT_THRESHOLD,"monitor"));
289         } else {
290             try {
291                 if (numberType.equals("long")) {
292                     threshold = Long.parseLong(initTheshold);
293                     if (strOffset != null)
294                         offset = Long.parseLong(strOffset);
295                     else
296                         offset = 0L;
297                     if (strModulus != null)
298                         modulus = Long.parseLong(strModulus);
299                     else
300                         modulus = 0L;
301                 } else if (numberType.equals("int")) {
302                     threshold = Integer.parseInt(initTheshold);
303                     if (strOffset != null)
304                         offset = Integer.parseInt(strOffset);
305                     else offset = 0;
306                     if (strModulus != null)
307                         modulus = Integer.parseInt(strModulus);
308                     else modulus = 0;
309                 } else if (numberType.equals("short")) {
310                     threshold = Short.parseShort(initTheshold);
311                     if (strOffset != null)
312                         offset = Short.parseShort(strOffset);
313                     else offset = 0;
314                     if (strModulus != null)
315                         modulus = Short.parseShort(strModulus);
316                     else modulus = 0;
317                 } else if (numberType.equals("byte")) {
318                     threshold = Byte.parseByte(initTheshold);
319                     if (strOffset != null)
320                         offset = Byte.parseByte(strOffset);
321                     else offset = 0;
322                     if (strModulus != null)
323                         modulus = Byte.parseByte(strModulus);
324                     else modulus = 0;
325                 }
326                 monitor.setInitThreshold(threshold);
327                 if (offset != null)
328                     monitor.setOffset(offset);
329                 if (modulus != null)
330                     monitor.setModulus(modulus);
331             }catch (Exception JavaDoc ex) {
332                 throw new IllegalArgumentException JavaDoc(
333                         sm.getString("selfmgmt_event.invalid_event_property",PROPERTY_MONITOR_INIT_THRESHOLD,"monitor"),ex);
334             }
335         }
336         if (!monitor.getNotify()) {
337             monitor.setNotify(true);
338         }
339         return monitor;
340     }
341    
342     private StatisticMonitor createCounterStatisticMonitor(Hashtable JavaDoc<String JavaDoc,String JavaDoc> table) {
343         CounterStatisticMonitor monitor = null;
344         try {
345             monitor = (CounterStatisticMonitor)getMBeanServer().instantiate("com.sun.enterprise.admin.selfmanagement.event.CounterStatisticMonitor");
346         } catch ( Exception JavaDoc rex) {
347             _logger.log(Level.WARNING,"smgt.internal_error", rex);
348         }
349         String JavaDoc strDiffMode = table.get(PROPERTY_MONITOR_DIFFERENCEMODE);
350         if (strDiffMode != null) {
351             try {
352                 boolean diffMode = Boolean.parseBoolean(strDiffMode);
353                 monitor.setDifferenceMode(diffMode);
354             } catch (Exception JavaDoc ex) {
355                 throw new IllegalArgumentException JavaDoc(
356                         sm.getString("selfmgmt_event.invalid_event_property",PROPERTY_MONITOR_DIFFERENCEMODE,"monitor"), ex);
357             }
358         }
359         
360         String JavaDoc numberType = table.get(PROPERTY_MONITOR_NUMBERTYPE);
361         if (numberType == null)
362             numberType = "long";
363         String JavaDoc initTheshold = table.get(PROPERTY_MONITOR_INIT_THRESHOLD);
364         String JavaDoc strOffset = table.get(PROPERTY_MONITOR_OFFSET);
365         String JavaDoc strModulus = table.get(PROPERTY_MONITOR_MODULUS);
366         Number JavaDoc threshold = null;
367         Number JavaDoc offset = null;
368         Number JavaDoc modulus = null;
369         if (initTheshold == null) {
370             throw new IllegalArgumentException JavaDoc(
371                     sm.getString("selfmgmt_event.invalid_event_property",PROPERTY_MONITOR_INIT_THRESHOLD,"monitor"));
372         } else {
373             try {
374                 if (numberType.equals("long")) {
375                     threshold = Long.parseLong(initTheshold);
376                     if (strOffset != null)
377                         offset = Long.parseLong(strOffset);
378                     else
379                         offset = 0L;
380                     if (strModulus != null)
381                         modulus = Long.parseLong(strModulus);
382                     else
383                         modulus = 0L;
384                 } else if (numberType.equals("int")) {
385                     threshold = Integer.parseInt(initTheshold);
386                     if (strOffset != null)
387                         offset = Integer.parseInt(strOffset);
388                     else offset = 0;
389                     if (strModulus != null)
390                         modulus = Integer.parseInt(strModulus);
391                     else modulus = 0;
392                 } else if (numberType.equals("short")) {
393                     threshold = Short.parseShort(initTheshold);
394                     if (strOffset != null)
395                         offset = Short.parseShort(strOffset);
396                     else offset = 0;
397                     if (strModulus != null)
398                         modulus = Short.parseShort(strModulus);
399                     else modulus = 0;
400                 } else if (numberType.equals("byte")) {
401                     threshold = Byte.parseByte(initTheshold);
402                     if (strOffset != null)
403                         offset = Byte.parseByte(strOffset);
404                     else offset = 0;
405                     if (strModulus != null)
406                         modulus = Byte.parseByte(strModulus);
407                     else modulus = 0;
408                 }
409                 monitor.setInitThreshold(threshold);
410                 if (offset != null)
411                     monitor.setOffset(offset);
412                 if (modulus != null)
413                     monitor.setModulus(modulus);
414             }catch (Exception JavaDoc ex) {
415                 throw new IllegalArgumentException JavaDoc(
416                         sm.getString("selfmgmt_event.invalid_event_property",PROPERTY_MONITOR_INIT_THRESHOLD,"monitor"),ex);
417             }
418         }
419         if (!monitor.getNotify()) {
420             monitor.setNotify(true);
421         }
422         return monitor;
423     }
424  
425     private Monitor JavaDoc createGaugeMonitor(Hashtable JavaDoc<String JavaDoc,String JavaDoc> table) {
426         GaugeMonitor JavaDoc monitor = null;
427         try {
428             monitor = (GaugeMonitor JavaDoc)getMBeanServer().instantiate("javax.management.monitor.GaugeMonitor");
429         } catch( Exception JavaDoc ex ) {
430             _logger.log(Level.WARNING, "sgmt.internal_error", ex);
431         }
432
433         String JavaDoc strDiffMode = table.get(PROPERTY_MONITOR_DIFFERENCEMODE);
434         if (strDiffMode != null) {
435             try {
436                 boolean diffMode = Boolean.parseBoolean(strDiffMode);
437                 monitor.setDifferenceMode(diffMode);
438             } catch (Exception JavaDoc ex) {
439                 throw new IllegalArgumentException JavaDoc(
440                         sm.getString("selfmgmt_event.invalid_event_property",PROPERTY_MONITOR_DIFFERENCEMODE,"monitor"), ex);
441             }
442         }
443         String JavaDoc numberType = table.get(PROPERTY_MONITOR_NUMBERTYPE);
444         if (numberType == null)
445             numberType = "long";
446         String JavaDoc lowTheshold = table.get(PROPERTY_MONITOR_LOW_THRESHOLD);
447         String JavaDoc highTheshold = table.get(PROPERTY_MONITOR_HIGH_THRESHOLD);
448         if ( (lowTheshold == null) || (highTheshold == null)) {
449             throw new IllegalArgumentException JavaDoc(
450                     sm.getString("selfmgmt_event.invalid_event_property","lowthreshold or highthreshold","monitor"));
451         }
452         Number JavaDoc lThreshold = null;
453         Number JavaDoc hThreshold = null;
454         try {
455             if (numberType.equals("long")) {
456                 lThreshold = Long.parseLong(lowTheshold);
457                 hThreshold = Long.parseLong(highTheshold);
458             } else if (numberType.equals("int")) {
459                 lThreshold = Integer.parseInt(lowTheshold);
460                 hThreshold = Integer.parseInt(highTheshold);
461             } else if (numberType.equals("short")) {
462                 lThreshold = Short.parseShort(lowTheshold);
463                 hThreshold = Short.parseShort(highTheshold);
464             } else if (numberType.equals("double")) {
465                 lThreshold = Double.parseDouble(lowTheshold);
466                 hThreshold = Double.parseDouble(highTheshold);
467             } else if (numberType.equals("float")) {
468                 lThreshold = Float.parseFloat(lowTheshold);
469                 hThreshold = Float.parseFloat(highTheshold);
470             } else if (numberType.equals("byte")) {
471                 lThreshold = Byte.parseByte(lowTheshold);
472                 hThreshold = Byte.parseByte(highTheshold);
473             }
474             monitor.setThresholds(hThreshold, lThreshold);
475         }catch (Exception JavaDoc ex) {
476             throw new IllegalArgumentException JavaDoc(
477                     sm.getString("selfmgmt_event.invalid_event_property","lowthreshold or highthreshold","monitor"),ex);
478         }
479         if (!monitor.getNotifyHigh()) {
480             monitor.setNotifyHigh(true);
481         }
482         if (!monitor.getNotifyLow()) {
483             monitor.setNotifyLow(true);
484         }
485         return monitor;
486     }
487
488     private StatisticMonitor createGaugeStatisticMonitor(Hashtable JavaDoc<String JavaDoc,String JavaDoc> table) {
489         GaugeStatisticMonitor monitor = null;
490         try {
491             monitor = (GaugeStatisticMonitor)getMBeanServer().instantiate("com.sun.enterprise.admin.selfmanagement.event.GaugeStatisticMonitor");
492         } catch( Exception JavaDoc ex ) {
493             _logger.log(Level.WARNING, "sgmt.internal_error", ex);
494         }
495                                                                                                                                                
496         String JavaDoc strDiffMode = table.get(PROPERTY_MONITOR_DIFFERENCEMODE);
497         if (strDiffMode != null) {
498             try {
499                 boolean diffMode = Boolean.parseBoolean(strDiffMode);
500                 monitor.setDifferenceMode(diffMode);
501             } catch (Exception JavaDoc ex) {
502                 throw new IllegalArgumentException JavaDoc(
503                         sm.getString("selfmgmt_event.invalid_event_property",PROPERTY_MONITOR_DIFFERENCEMODE,"monitor"), ex);
504             }
505         }
506         String JavaDoc numberType = table.get(PROPERTY_MONITOR_NUMBERTYPE);
507         if (numberType == null)
508             numberType = "long";
509         String JavaDoc lowTheshold = table.get(PROPERTY_MONITOR_LOW_THRESHOLD);
510         String JavaDoc highTheshold = table.get(PROPERTY_MONITOR_HIGH_THRESHOLD);
511         if ( (lowTheshold == null) || (highTheshold == null)) {
512             throw new IllegalArgumentException JavaDoc(
513                     sm.getString("selfmgmt_event.invalid_event_property","lowthreshold or highthreshold","monitor"));
514         }
515         Number JavaDoc lThreshold = null;
516         Number JavaDoc hThreshold = null;
517         try {
518             if (numberType.equals("long")) {
519                 lThreshold = Long.parseLong(lowTheshold);
520                 hThreshold = Long.parseLong(highTheshold);
521             } else if (numberType.equals("int")) {
522                 lThreshold = Integer.parseInt(lowTheshold);
523                 hThreshold = Integer.parseInt(highTheshold);
524             } else if (numberType.equals("short")) {
525                 lThreshold = Short.parseShort(lowTheshold);
526                 hThreshold = Short.parseShort(highTheshold);
527             } else if (numberType.equals("double")) {
528                 lThreshold = Double.parseDouble(lowTheshold);
529                 hThreshold = Double.parseDouble(highTheshold);
530             } else if (numberType.equals("float")) {
531                 lThreshold = Float.parseFloat(lowTheshold);
532                 hThreshold = Float.parseFloat(highTheshold);
533             } else if (numberType.equals("byte")) {
534                 lThreshold = Byte.parseByte(lowTheshold);
535                 hThreshold = Byte.parseByte(highTheshold);
536             }
537             monitor.setThresholds(hThreshold, lThreshold);
538         }catch (Exception JavaDoc ex) {
539             throw new IllegalArgumentException JavaDoc(
540                     sm.getString("selfmgmt_event.invalid_event_property","lowthreshold or highthreshold","monitor"),ex);
541         }
542         if (!monitor.getNotifyHigh()) {
543             monitor.setNotifyHigh(true);
544         }
545         if (!monitor.getNotifyLow()) {
546             monitor.setNotifyLow(true);
547         }
548         return monitor;
549     }
550
551     private Monitor JavaDoc createStringMonitor(Hashtable JavaDoc<String JavaDoc,String JavaDoc> table) {
552         StringMonitor JavaDoc monitor = null;
553         try {
554             monitor = (StringMonitor JavaDoc)getMBeanServer().instantiate("javax.management.monitor.StringMonitor");
555         } catch( Exception JavaDoc ex ) {
556             _logger.log(Level.WARNING, "sgmt.internal_error", ex);
557         }
558         
559         String JavaDoc strToCompare = table.get(PROPERTY_MONITOR_STRING_TO_COMPARE);
560         String JavaDoc strNotify = table.get(PROPERTY_MONITOR_STRING_NOTIFY);
561         if (strToCompare == null) {
562             throw new IllegalArgumentException JavaDoc(
563                     sm.getString("selfmgmt_event.invalid_event_property",PROPERTY_MONITOR_STRING_TO_COMPARE,"monitor"));
564         }
565         monitor.setStringToCompare(strToCompare);
566         if(strNotify == null || strNotify.equals(PROPERTY_MONITOR_STRING_NOTIFY_MATCH)) { // match has higher priority than differ
567
monitor.setNotifyMatch(true);
568             return monitor;
569         } else if(strNotify.equals(PROPERTY_MONITOR_STRING_NOTIFY_DIFFER))
570             monitor.setNotifyDiffer(true);
571         
572         return monitor;
573     }
574     
575     private StatisticMonitor createStringStatisticMonitor(Hashtable JavaDoc<String JavaDoc,String JavaDoc> table) {
576         StringStatisticMonitor monitor = null;
577         try {
578             monitor = (StringStatisticMonitor)getMBeanServer().instantiate("com.sun.enterprise.admin.selfmanagement.event.StringStatisticMonitor");
579         } catch( Exception JavaDoc ex ) {
580             _logger.log(Level.WARNING, "sgmt.internal_error", ex);
581         }
582                                                                                                                                                
583         String JavaDoc strToCompare = table.get(PROPERTY_MONITOR_STRING_TO_COMPARE);
584         String JavaDoc strNotify = table.get(PROPERTY_MONITOR_STRING_NOTIFY);
585         if (strToCompare == null) {
586             throw new IllegalArgumentException JavaDoc(
587                     sm.getString("selfmgmt_event.invalid_event_property",PROPERTY_MONITOR_STRING_TO_COMPARE,"monitor"));
588         }
589         monitor.setStringToCompare(strToCompare);
590         if(strNotify == null || strNotify.equals(PROPERTY_MONITOR_STRING_NOTIFY_MATCH)) { // match has higher priority than differ
591
monitor.setNotifyMatch(true);
592             return monitor;
593         } else if(strNotify.equals(PROPERTY_MONITOR_STRING_NOTIFY_DIFFER))
594             monitor.setNotifyDiffer(true);
595         return monitor;
596     }
597
598     static MonitorEventFactory getInstance() {
599         return instance;
600     }
601     
602     
603     private synchronized String JavaDoc getNewVersionString() {
604         seqno++;
605         return seqno.toString();
606     }
607     private static MonitorEventFactory instance = new MonitorEventFactory();
608     private Long JavaDoc seqno = 0L;
609     private static String JavaDoc instanceName = (ApplicationServer.getServerContext()).getInstanceName();
610 }
611
Popular Tags