KickJava   Java API By Example, From Geeks To Geeks.

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


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  * LogEvent.java
26  *
27  */

28
29 package com.sun.enterprise.admin.selfmanagement.event;
30
31 import javax.management.NotificationFilter JavaDoc;
32 import javax.management.ObjectName JavaDoc;
33 import javax.management.MalformedObjectNameException JavaDoc;
34 import com.sun.enterprise.util.SystemPropertyConstants;
35 import com.sun.enterprise.util.i18n.StringManager;
36 import java.util.logging.Logger JavaDoc;
37 import java.util.logging.Level JavaDoc;
38 import com.sun.logging.LogDomains;
39 import com.sun.enterprise.admin.common.MBeanServerFactory;
40 import javax.management.MBeanServer JavaDoc;
41
42
43 /**
44  *
45  * @author hemanth
46  */

47 public class LogEvent implements Event {
48     private static StringManager sm = StringManager.getManager(LogEvent.class);
49     private static Logger JavaDoc _logger=LogDomains.getLogger(LogDomains.SELF_MANAGEMENT_LOGGER);
50     
51     /** Creates a new instance of LogEvent */
52     public LogEvent( LogEventFilter filter , String JavaDoc description) {
53         notificationFilter = filter;
54         if (description != null)
55             this.description = description;
56         else
57             description = defaultDescription;
58     }
59     
60     public ObjectName JavaDoc getObjectName() {
61         return getLogObjectName();
62     }
63     
64     
65     public String JavaDoc getType() {
66         return "log";
67     }
68     
69     public NotificationFilter JavaDoc getNotificationFilter( ){
70         return notificationFilter;
71     }
72     
73     public String JavaDoc getDescription() {
74         return description;
75     }
76     
77     public void destroy() {
78         // do nothing
79
}
80     
81     static ObjectName JavaDoc getLogObjectName() {
82         if (objName != null)
83             return objName;
84         try {
85             objName = new ObjectName JavaDoc( "amx:j2eeType=X-Logging,name="+
86                     System.getProperty(SystemPropertyConstants.SERVER_NAME )+
87                     ",X-ServerRootMonitor=" +
88                     System.getProperty(SystemPropertyConstants.SERVER_NAME ));
89             MBeanServer JavaDoc mbeanServer = MBeanServerFactory.getMBeanServer();
90             if (mbeanServer.isRegistered(objName)) {
91                 return objName;
92             } else
93                 _logger.log(Level.WARNING,"smgt.internal_error",
94                         new Object JavaDoc[] {sm.getString("selfmgmt_event.log_mbean_is_not_available")});
95         }catch (MalformedObjectNameException JavaDoc mex) {
96             _logger.log(Level.WARNING,"smgt.internal_error", mex);
97         }
98         return objName;
99         
100     }
101     
102     private static ObjectName JavaDoc objName = null;
103     private static String JavaDoc defaultDescription = sm.getString("selfmgmt_event.log_event_description");
104     private static String JavaDoc description = null;
105     private LogEventFilter notificationFilter = null;
106 }
107
Popular Tags