KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > event > TraceEventHelper


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

28
29 package com.sun.appserv.management.event;
30
31 import java.util.Map JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import javax.management.Notification JavaDoc;
34
35
36 /*
37  *
38  * @author Sun Microsystems, Inc
39  */

40 public class TraceEventHelper {
41
42     public static final String JavaDoc REQUEST_ID =
43                   "com.sun.appserv.management.event.trace.requestid";
44
45     public static final String JavaDoc REQUEST_TYPE =
46                   "com.sun.appserv.management.event.trace.requesttype";
47
48     public static final String JavaDoc CALLER_IPADDRESS =
49                   "com.sun.appserv.management.event.trace.callerip";
50
51     public static final String JavaDoc CALLER_PRINCIPAL =
52                   "com.sun.appserv.management.event.trace.callerprincipal";
53
54     public static final String JavaDoc NANO_TIME =
55                   "com.sun.appserv.management.event.trace.nanotime";
56
57     public static final String JavaDoc THREAD_ID =
58                   "com.sun.appserv.management.event.trace.threadid";
59
60     public static final String JavaDoc METHOD_NAME =
61                   "com.sun.appserv.management.event.trace.methodname";
62
63     public static final String JavaDoc COMPONENT_TYPE =
64                   "com.sun.appserv.management.event.trace.componenttype";
65
66     public static final String JavaDoc COMPONENT_NAME =
67                   "com.sun.appserv.management.event.trace.componentname";
68
69     public static final String JavaDoc APPLICATION_NAME =
70                   "com.sun.appserv.management.event.trace.applicationname";
71
72     public static final String JavaDoc MODULE_NAME =
73                   "com.sun.appserv.management.event.trace.modulename";
74
75     public static final String JavaDoc TRANSACTION_ID =
76                   "com.sun.appserv.management.event.trace.transactionid";
77
78     public static final String JavaDoc SECURITY_ID =
79                   "com.sun.appserv.management.event.trace.securityid";
80
81     public static final String JavaDoc EXCEPTION =
82                   "com.sun.appserv.management.event.trace.exception";
83
84     public static final String JavaDoc EXCEPTION_OBJECT =
85                   "com.sun.appserv.management.event.trace.exceptionobject";
86
87    // event types
88
public static final String JavaDoc REQUEST_START = "trace.request_start";
89     public static final String JavaDoc REQUEST_END = "trace.request_end";
90     public static final String JavaDoc WEB_COMPONENT_METHOD_ENTRY =
91                                 "trace.web_component_method_entry";
92     public static final String JavaDoc WEB_COMPONENT_METHOD_EXIT =
93                                 "trace.web_component_method_exit";
94     public static final String JavaDoc EJB_COMPONENT_METHOD_ENTRY =
95                                 "trace.ejb_component_method_entry";
96     public static final String JavaDoc EJB_COMPONENT_METHOD_EXIT =
97                                 "trace.ejb_component_method_exit";
98
99
100
101
102     public TraceEventHelper(Notification JavaDoc notif) {
103         if (notif.getUserData() == null)
104             throw new IllegalArgumentException JavaDoc();
105         Object JavaDoc uData = notif.getUserData();
106         if (!(uData instanceof Map JavaDoc)) {
107             throw new IllegalArgumentException JavaDoc();
108         }
109         this.userData = (HashMap JavaDoc)((HashMap JavaDoc)uData).clone();
110     }
111
112     public TraceEventHelper(Map JavaDoc userData) {
113         this.userData = (HashMap JavaDoc)((HashMap JavaDoc)userData).clone();
114     }
115
116     public String JavaDoc getRequestId() {
117         return (String JavaDoc)userData.get(REQUEST_ID);
118     }
119
120     public String JavaDoc getRequestId(Notification JavaDoc notification) {
121         Object JavaDoc userData = notification.getUserData();
122         if (userData != null) {
123             return (String JavaDoc)((Map JavaDoc)userData).get(REQUEST_ID);
124         } else {
125           return null;
126         }
127     }
128
129     public String JavaDoc getRequestType() {
130         return (String JavaDoc)userData.get(REQUEST_TYPE);
131     }
132
133     public static String JavaDoc getRequestType(Notification JavaDoc notification) {
134         Object JavaDoc userData = notification.getUserData();
135         if (userData != null) {
136             return (String JavaDoc)((Map JavaDoc)userData).get(REQUEST_TYPE);
137         } else {
138           return null;
139         }
140     }
141
142     public String JavaDoc getCallerIP() {
143         return (String JavaDoc)userData.get(CALLER_IPADDRESS);
144     }
145
146     public static String JavaDoc getCallerIP(Notification JavaDoc notification) {
147         Object JavaDoc userData = notification.getUserData();
148         if (userData != null) {
149             return (String JavaDoc)((Map JavaDoc)userData).get(CALLER_IPADDRESS);
150         } else {
151           return null;
152         }
153     }
154
155     public String JavaDoc getCallerPrincipal() {
156         return (String JavaDoc)userData.get(CALLER_PRINCIPAL);
157     }
158
159     public static String JavaDoc getCallerPrincipal(Notification JavaDoc notification) {
160         Object JavaDoc userData = notification.getUserData();
161         if (userData != null) {
162             return (String JavaDoc)((Map JavaDoc)userData).get(CALLER_PRINCIPAL);
163         } else {
164           return null;
165         }
166     }
167
168     public Long JavaDoc getNanoTime() {
169         return (Long JavaDoc)userData.get(NANO_TIME);
170     }
171
172     public static Long JavaDoc getNanoTime(Notification JavaDoc notification) {
173         Object JavaDoc userData = notification.getUserData();
174         if (userData != null) {
175             return (Long JavaDoc)((Map JavaDoc)userData).get(NANO_TIME);
176         } else {
177           return -1L;
178         }
179     }
180
181     public String JavaDoc getThreadID() {
182         return (String JavaDoc)userData.get(THREAD_ID);
183     }
184
185     public static String JavaDoc getThreadId(Notification JavaDoc notification) {
186         Object JavaDoc userData = notification.getUserData();
187         if (userData != null) {
188             return (String JavaDoc)((Map JavaDoc)userData).get(THREAD_ID);
189         } else {
190           return null;
191         }
192     }
193
194     public String JavaDoc getMethodName() {
195         return (String JavaDoc)userData.get(METHOD_NAME);
196     }
197
198     public static String JavaDoc getMethodName(Notification JavaDoc notification) {
199         Object JavaDoc userData = notification.getUserData();
200         if (userData != null) {
201             return (String JavaDoc)((Map JavaDoc)userData).get(METHOD_NAME);
202         } else {
203           return null;
204         }
205     }
206
207     public String JavaDoc getComponentType() {
208         return (String JavaDoc)userData.get(COMPONENT_TYPE);
209     }
210
211     public static String JavaDoc getComponentType(Notification JavaDoc notification) {
212         Object JavaDoc userData = notification.getUserData();
213         if (userData != null) {
214             return (String JavaDoc)((Map JavaDoc)userData).get(COMPONENT_TYPE);
215         } else {
216           return null;
217         }
218     }
219
220     public String JavaDoc getComponentName() {
221         return (String JavaDoc)userData.get(COMPONENT_NAME);
222     }
223
224     public static String JavaDoc getComponentName(Notification JavaDoc notification) {
225         Object JavaDoc userData = notification.getUserData();
226         if (userData != null) {
227             return (String JavaDoc)((Map JavaDoc)userData).get(COMPONENT_NAME);
228         } else {
229           return null;
230         }
231     }
232
233     public String JavaDoc getApplicationName() {
234         return (String JavaDoc)userData.get(APPLICATION_NAME);
235     }
236
237     public static String JavaDoc getApplicationName(Notification JavaDoc notification) {
238         Object JavaDoc userData = notification.getUserData();
239         if (userData != null) {
240             return (String JavaDoc)((Map JavaDoc)userData).get(APPLICATION_NAME);
241         } else {
242           return null;
243         }
244     }
245
246     public String JavaDoc getModuleName() {
247         return (String JavaDoc)userData.get(MODULE_NAME);
248     }
249
250     public static String JavaDoc getModuleName(Notification JavaDoc notification) {
251         Object JavaDoc userData = notification.getUserData();
252         if (userData != null) {
253             return (String JavaDoc)((Map JavaDoc)userData).get(MODULE_NAME);
254         } else {
255           return null;
256         }
257     }
258
259     public String JavaDoc getTransactionID() {
260         return (String JavaDoc)userData.get(TRANSACTION_ID);
261     }
262
263     public static String JavaDoc getTransactionID(Notification JavaDoc notification) {
264         Object JavaDoc userData = notification.getUserData();
265         if (userData != null) {
266             return (String JavaDoc)((Map JavaDoc)userData).get(TRANSACTION_ID);
267         } else {
268           return null;
269         }
270     }
271
272     public String JavaDoc getSecurityID() {
273         return (String JavaDoc)userData.get(SECURITY_ID);
274     }
275
276     public static String JavaDoc getSecurityID(Notification JavaDoc notification) {
277         Object JavaDoc userData = notification.getUserData();
278         if (userData != null) {
279             return (String JavaDoc)((Map JavaDoc)userData).get(SECURITY_ID);
280         } else {
281           return null;
282         }
283     }
284
285     public String JavaDoc getExceptionString() {
286         return (String JavaDoc)userData.get(EXCEPTION);
287     }
288
289     public static String JavaDoc getExceptionString(Notification JavaDoc notification) {
290         Object JavaDoc userData = notification.getUserData();
291         if (userData != null) {
292             return (String JavaDoc)((Map JavaDoc)userData).get(EXCEPTION);
293         } else {
294           return null;
295         }
296     }
297
298     public Throwable JavaDoc getExceptionObject() {
299         return (Throwable JavaDoc)userData.get(EXCEPTION_OBJECT);
300     }
301
302     public static Throwable JavaDoc getExceptionObject(Notification JavaDoc notification) {
303         Object JavaDoc userData = notification.getUserData();
304         if (userData != null) {
305             return (Throwable JavaDoc)((Map JavaDoc)userData).get(EXCEPTION_OBJECT);
306         } else {
307           return null;
308         }
309     }
310
311    private Map JavaDoc userData = null;
312
313 }
314
Popular Tags