KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 import java.util.HashMap JavaDoc;
27 import javax.management.Notification JavaDoc;
28 import javax.management.NotificationBroadcasterSupport JavaDoc;
29 import javax.management.MBeanNotificationInfo JavaDoc;
30 import com.sun.enterprise.server.ServerContext;
31
32 import com.sun.enterprise.admin.monitor.callflow.RequestType;
33 import static com.sun.appserv.management.event.TraceEventHelper.*;
34
35
36
37 /**
38  * TraceEventImpl.java
39  */

40 public class TraceEventImpl extends NotificationBroadcasterSupport JavaDoc
41                             implements TraceEventImplMBean {
42     
43     public TraceEventImpl() {
44         CallflowEventListener.setTraceImpl(this);
45     }
46     
47     /**
48      * Notification sequence number within the source object.
49      */

50     private long sequenceNumber = 0;
51     
52     
53     public void requestEnd(String JavaDoc requestId,
54                 long nanoTime, String JavaDoc threadId) {
55
56         long seqno;
57         synchronized (this) {
58             seqno = sequenceNumber++;
59         }
60         HashMap JavaDoc map = new HashMap JavaDoc();
61         map.put(REQUEST_ID,requestId);
62         map.put(NANO_TIME,nanoTime);
63         map.put(THREAD_ID, threadId);
64         Notification JavaDoc n = new Notification JavaDoc(
65                          REQUEST_END, this, seqno, "request end!");
66         n.setUserData(map);
67         sendNotification(n);
68         
69     }
70
71     public void requestStart(String JavaDoc requestId, RequestType requestType,
72                 String JavaDoc callerIPAddress, long nanoTime, String JavaDoc threadId) {
73
74         long seqno;
75         synchronized (this) {
76             seqno = sequenceNumber++;
77         }
78         HashMap JavaDoc map = new HashMap JavaDoc();
79         map.put(REQUEST_ID,requestId);
80         map.put(REQUEST_TYPE,getRequestTypeString(requestType));
81         map.put(CALLER_IPADDRESS,callerIPAddress);
82         map.put(NANO_TIME,nanoTime);
83         map.put(THREAD_ID, threadId);
84         Notification JavaDoc n = new Notification JavaDoc(
85                          REQUEST_START, this, seqno, "request start!");
86         n.setUserData(map);
87         sendNotification(n);
88         
89     }
90
91     public void ejbMethodStart(String JavaDoc requestId, String JavaDoc methodName,
92                 String JavaDoc componentType, String JavaDoc appName, String JavaDoc moduleName,
93                 String JavaDoc componentName, String JavaDoc tranId, String JavaDoc secId,
94                 long nanoTime, String JavaDoc threadId) {
95         long seqno;
96         synchronized (this) {
97             seqno = sequenceNumber++;
98         }
99         HashMap JavaDoc map = new HashMap JavaDoc();
100         map.put(REQUEST_ID,requestId);
101         map.put(METHOD_NAME,methodName);
102         map.put(COMPONENT_TYPE,componentType);
103         map.put(APPLICATION_NAME,appName);
104         map.put(MODULE_NAME,moduleName);
105         map.put(COMPONENT_NAME,componentName);
106         map.put(TRANSACTION_ID,tranId);
107         map.put(SECURITY_ID,secId);
108         map.put(NANO_TIME,nanoTime);
109         map.put(THREAD_ID, threadId);
110         Notification JavaDoc n = new Notification JavaDoc(
111                          EJB_COMPONENT_METHOD_ENTRY,
112                          this, seqno, "ejb method start!");
113         n.setUserData(map);
114         sendNotification(n);
115     }
116
117     public void ejbMethodEnd(String JavaDoc requestId, Throwable JavaDoc exception,
118                 long nanoTime, String JavaDoc threadId) {
119
120         long seqno;
121         synchronized (this) {
122             seqno = sequenceNumber++;
123         }
124         HashMap JavaDoc map = new HashMap JavaDoc();
125         map.put(REQUEST_ID,requestId);
126         if (exception != null) {
127             map.put(EXCEPTION,getExceptionString(exception));
128             map.put(EXCEPTION_OBJECT,exception);
129         }
130         map.put(NANO_TIME,nanoTime);
131         map.put(THREAD_ID, threadId);
132         Notification JavaDoc n = new Notification JavaDoc(
133                          EJB_COMPONENT_METHOD_EXIT,
134                          this, seqno, "ejb method end!");
135         n.setUserData(map);
136         sendNotification(n);
137     }
138
139   public void webMethodEnd(String JavaDoc requestId, Throwable JavaDoc exception,
140                 long nanoTime, String JavaDoc threadId) {
141
142         long seqno;
143         synchronized (this) {
144             seqno = sequenceNumber++;
145         }
146         HashMap JavaDoc map = new HashMap JavaDoc();
147         map.put(REQUEST_ID,requestId);
148         if (exception != null) {
149             map.put(EXCEPTION,getExceptionString(exception));
150             map.put(EXCEPTION_OBJECT,exception);
151         }
152         map.put(NANO_TIME,nanoTime);
153         map.put(THREAD_ID, threadId);
154         Notification JavaDoc n = new Notification JavaDoc(
155                          WEB_COMPONENT_METHOD_EXIT,
156                          this, seqno, "web method end!");
157         n.setUserData(map);
158         sendNotification(n);
159     }
160
161  public void webMethodStart(String JavaDoc requestId, String JavaDoc methodName,
162                 String JavaDoc applicationName, String JavaDoc componentType,
163                 String JavaDoc componentName, String JavaDoc callerPrincipal,
164                 long nanoTime, String JavaDoc threadId) {
165
166         long seqno;
167         synchronized (this) {
168             seqno = sequenceNumber++;
169         }
170         HashMap JavaDoc map = new HashMap JavaDoc();
171         map.put(REQUEST_ID,requestId);
172         map.put(METHOD_NAME,methodName);
173         map.put(COMPONENT_TYPE,componentType);
174         map.put(COMPONENT_NAME,componentName);
175         map.put(CALLER_PRINCIPAL,callerPrincipal);
176         map.put(APPLICATION_NAME,applicationName);
177         map.put(NANO_TIME,nanoTime);
178         map.put(THREAD_ID, threadId);
179         Notification JavaDoc n = new Notification JavaDoc(
180                          WEB_COMPONENT_METHOD_ENTRY,
181                          this, seqno, "web method start!");
182         n.setUserData(map);
183         sendNotification(n);
184     }
185
186
187     public MBeanNotificationInfo JavaDoc[] getNotificationInfo() {
188         return notifsInfo;
189     }
190
191     private String JavaDoc getRequestTypeString(RequestType requestType) {
192        if (RequestType.REMOTE_WEB == requestType)
193            return "remote web request";
194        if (RequestType.REMOTE_EJB == requestType)
195            return "remote ejb request";
196        if (RequestType.REMOTE_ASYNC_MESSAGE == requestType)
197            return "remote asynchronous message request";
198        if (RequestType.TIMER_EJB == requestType)
199            return "timer ejb request";
200        if (RequestType.REMOTE_WEB_SERVICE == requestType)
201            return "remote web service request";
202        return "unknown request type";
203     }
204
205     private String JavaDoc getExceptionString(Throwable JavaDoc exception) {
206             StringBuffer JavaDoc exceptionMsg = new StringBuffer JavaDoc();
207             exceptionMsg.append(" Message: ");
208             String JavaDoc message = exception.getMessage();
209             exceptionMsg.append(message);
210             String JavaDoc className = exception.getClass().getName();
211             exceptionMsg.append(" Exception Class Name: ");
212             exceptionMsg.append(className);
213             if (exception.getCause() != null) {
214                 exceptionMsg.append(" Exception Cause Message: ");
215                 exceptionMsg.append(exception.getCause().getMessage());
216                 exceptionMsg.append(" Exception Cause Class Name: ");
217                 exceptionMsg.append(exception.getCause().getClass().getName());
218             }
219             return exceptionMsg.toString();
220     }
221     
222     private static final String JavaDoc[] types = {
223             REQUEST_START,
224             REQUEST_END,
225             WEB_COMPONENT_METHOD_ENTRY,
226             WEB_COMPONENT_METHOD_EXIT,
227             EJB_COMPONENT_METHOD_ENTRY,
228             EJB_COMPONENT_METHOD_EXIT
229     };
230     
231     
232     private static final MBeanNotificationInfo JavaDoc[] notifsInfo = {
233         new MBeanNotificationInfo JavaDoc(
234                 types,
235                 "javax.management.Notification",
236                 "Notifications sent by the TraceEventImpl MBean")
237     };
238
239     
240     
241 }
242
Popular Tags