KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.admin.selfmanagement.event;
25 import javax.management.ObjectName JavaDoc;
26 import javax.management.NotificationFilter JavaDoc;
27 import javax.management.monitor.Monitor JavaDoc;
28 import com.sun.enterprise.admin.common.MBeanServerFactory;
29 import java.util.logging.Logger JavaDoc;
30 import java.util.logging.Level JavaDoc;
31 import com.sun.logging.LogDomains;
32 import com.sun.enterprise.util.i18n.StringManager;
33
34
35 public class MonitorEvent implements Event {
36     private static Logger JavaDoc _logger=LogDomains.getLogger(LogDomains.SELF_MANAGEMENT_LOGGER);
37     private static StringManager sm = StringManager.getManager(MonitorEvent.class);
38     
39     MonitorEvent(StatisticMonitor monitor, ObjectName JavaDoc objName, String JavaDoc description) {
40         monitor.start();
41         try {
42             MBeanServerFactory.getMBeanServer().registerMBean(monitor,objName);
43         } catch (Exception JavaDoc ex) {
44             _logger.log(Level.WARNING,"smgt.internal_error", ex);
45         }
46         
47         this.sMonitor = monitor;
48         this.objName = objName;
49         if (description != null)
50             this.description = description;
51         else
52             this.description = defaultDescription;
53     }
54
55     MonitorEvent(Monitor JavaDoc monitor, ObjectName JavaDoc objName, String JavaDoc description) {
56         monitor.start();
57         try {
58             MBeanServerFactory.getMBeanServer().registerMBean(monitor,objName);
59         } catch (Exception JavaDoc ex) {
60             _logger.log(Level.WARNING,"smgt.internal_error", ex);
61         }
62
63         this.monitor = monitor;
64         this.objName = objName;
65         if (description != null)
66             this.description = description;
67         else
68             this.description = defaultDescription;
69     }
70     
71     
72     public ObjectName JavaDoc getObjectName() {
73         return objName;
74     }
75     public String JavaDoc getType() {
76         return "monitor";
77     }
78     public NotificationFilter JavaDoc getNotificationFilter() {
79         return null;
80     }
81     public String JavaDoc getDescription() {
82         return description;
83     }
84     public void destroy() {
85         try {
86         if (monitor != null)
87             monitor.stop();
88         if (sMonitor != null)
89             sMonitor.stop();
90         } catch (Exception JavaDoc ex) {
91             _logger.log(Level.WARNING,"smgt.internal_error", ex);
92         }
93         try {
94             MBeanServerFactory.getMBeanServer().unregisterMBean(objName);
95         } catch (Exception JavaDoc ex) {
96             _logger.log(Level.WARNING,"smgt.internal_error", ex);
97         }
98     }
99     private ObjectName JavaDoc objName = null;
100     private static String JavaDoc description = null;
101     private static String JavaDoc defaultDescription = sm.getString("selfmgmt_event.monitor_event_description");
102     private StatisticMonitor sMonitor = null;
103     private Monitor JavaDoc monitor = null;
104 }
105
Popular Tags