KickJava   Java API By Example, From Geeks To Geeks.

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


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

28
29 package com.sun.enterprise.admin.selfmanagement.event;
30
31
32 import javax.management.NotificationEmitter JavaDoc;
33 import javax.management.MBeanServer JavaDoc;
34
35 import com.sun.enterprise.config.serverbeans.ElementProperty;
36 import java.util.logging.Level JavaDoc;
37 import static com.sun.enterprise.admin.selfmanagement.event.ManagementRuleConstants.*;
38
39 /**
40  *
41  * @author Sun Micro Systems, Inc
42  */

43
44 public class TraceEventFactory extends EventAbstractFactory {
45     
46     private TraceEventFactory( ) {
47         super();
48         EventBuilder.getInstance().addEventFactory(EVENT_TRACE, this);
49         try {
50             TraceEventImpl impl = (TraceEventImpl) getMBeanServer().instantiate(
51                     "com.sun.enterprise.admin.selfmanagement.event.TraceEventImpl");
52             getMBeanServer().registerMBean(impl,TraceEvent.getTraceImplObjectName());
53         } catch (javax.management.ReflectionException JavaDoc rex) {
54             _logger.log(Level.WARNING,"smgt.internal_error", rex);
55         } catch (javax.management.InstanceAlreadyExistsException JavaDoc iex) {
56             _logger.log(Level.WARNING,"smgt.internal_error", iex);
57         } catch (Exception JavaDoc ex) {
58             _logger.log(Level.WARNING,"smgt.internal_error", ex);
59             
60         }
61     }
62
63     private synchronized void enableNotifications(boolean enable) {
64         if (!notificationsEnabled) {
65             CallflowEventListener.register();
66             notificationsEnabled = true;
67         } else if (!enable) {
68             CallflowEventListener.unregister();
69         }
70     }
71     
72     public Event instrumentEvent(
73             ElementProperty[] properties, String JavaDoc description ) {
74         enableNotifications(true);
75         String JavaDoc eventName = "*";
76         String JavaDoc ipAddress = "*";
77         String JavaDoc callerPrincipal = "*";
78         String JavaDoc componentName = "*";
79         for( int i = 0; i < properties.length; i++ ){
80             ElementProperty property = properties[i];
81             String JavaDoc propertyName = property.getName( ).toLowerCase( );
82             if( propertyName.equals(PROPERTY_TRACE_NAME)) {
83                 eventName = "trace." + property.getValue( ).toLowerCase( );
84                 if (!TraceEvent.isValidType(eventName))
85                     throw new IllegalArgumentException JavaDoc(
86                             sm.getString(PROPERTY_TRACE_NAME,
87                             "selfmgmt_event.invalid_event_property",EVENT_TRACE));
88             }
89             if(propertyName.equals(PROPERTY_TRACE_IPADDRESS)) {
90                 ipAddress = property.getValue( ).toLowerCase( );
91             }
92             if(propertyName.equals(PROPERTY_TRACE_CALLERPRINCIPAL)) {
93                 callerPrincipal = property.getValue( ).toLowerCase( );
94             }
95             if(propertyName.equals(PROPERTY_TRACE_COMPONENTNAME)) {
96                 componentName = property.getValue( ).toLowerCase( );
97             }
98         }
99         return new TraceEvent(eventName,
100                    new TraceEventNotificationFilter(eventName, ipAddress, callerPrincipal, componentName),
101                    description);
102     }
103     
104     static TraceEventFactory getInstance() {
105         return instance;
106     }
107     private boolean notificationsEnabled = false;
108     private static TraceEventFactory instance = new TraceEventFactory();
109 }
110
Popular Tags