1 23 24 package com.sun.enterprise.admin.selfmanagement.event; 25 26 import java.util.HashMap ; 27 import javax.management.Notification ; 28 import javax.management.NotificationBroadcasterSupport ; 29 import javax.management.MBeanNotificationInfo ; 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 40 public class TraceEventImpl extends NotificationBroadcasterSupport 41 implements TraceEventImplMBean { 42 43 public TraceEventImpl() { 44 CallflowEventListener.setTraceImpl(this); 45 } 46 47 50 private long sequenceNumber = 0; 51 52 53 public void requestEnd(String requestId, 54 long nanoTime, String threadId) { 55 56 long seqno; 57 synchronized (this) { 58 seqno = sequenceNumber++; 59 } 60 HashMap map = new HashMap (); 61 map.put(REQUEST_ID,requestId); 62 map.put(NANO_TIME,nanoTime); 63 map.put(THREAD_ID, threadId); 64 Notification n = new Notification ( 65 REQUEST_END, this, seqno, "request end!"); 66 n.setUserData(map); 67 sendNotification(n); 68 69 } 70 71 public void requestStart(String requestId, RequestType requestType, 72 String callerIPAddress, long nanoTime, String threadId) { 73 74 long seqno; 75 synchronized (this) { 76 seqno = sequenceNumber++; 77 } 78 HashMap map = new HashMap (); 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 n = new Notification ( 85 REQUEST_START, this, seqno, "request start!"); 86 n.setUserData(map); 87 sendNotification(n); 88 89 } 90 91 public void ejbMethodStart(String requestId, String methodName, 92 String componentType, String appName, String moduleName, 93 String componentName, String tranId, String secId, 94 long nanoTime, String threadId) { 95 long seqno; 96 synchronized (this) { 97 seqno = sequenceNumber++; 98 } 99 HashMap map = new HashMap (); 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 n = new Notification ( 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 requestId, Throwable exception, 118 long nanoTime, String threadId) { 119 120 long seqno; 121 synchronized (this) { 122 seqno = sequenceNumber++; 123 } 124 HashMap map = new HashMap (); 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 n = new Notification ( 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 requestId, Throwable exception, 140 long nanoTime, String threadId) { 141 142 long seqno; 143 synchronized (this) { 144 seqno = sequenceNumber++; 145 } 146 HashMap map = new HashMap (); 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 n = new Notification ( 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 requestId, String methodName, 162 String applicationName, String componentType, 163 String componentName, String callerPrincipal, 164 long nanoTime, String threadId) { 165 166 long seqno; 167 synchronized (this) { 168 seqno = sequenceNumber++; 169 } 170 HashMap map = new HashMap (); 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 n = new Notification ( 180 WEB_COMPONENT_METHOD_ENTRY, 181 this, seqno, "web method start!"); 182 n.setUserData(map); 183 sendNotification(n); 184 } 185 186 187 public MBeanNotificationInfo [] getNotificationInfo() { 188 return notifsInfo; 189 } 190 191 private String 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 getExceptionString(Throwable exception) { 206 StringBuffer exceptionMsg = new StringBuffer (); 207 exceptionMsg.append(" Message: "); 208 String message = exception.getMessage(); 209 exceptionMsg.append(message); 210 String 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 [] 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 [] notifsInfo = { 233 new MBeanNotificationInfo ( 234 types, 235 "javax.management.Notification", 236 "Notifications sent by the TraceEventImpl MBean") 237 }; 238 239 240 241 } 242 | Popular Tags |