1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 package org.coach.tracing.server; 26 27 import org.coach.idltree.*; 28 import org.coach.tracing.*; 29 import org.coach.tracing.api.*; 30 import java.text.DateFormat ; 31 import java.text.SimpleDateFormat ; 32 33 public class EventRecord 34 { 35 private static EventDataBase eventDB; 36 TraceRecord tr; 37 public IdlNode idlNode; 38 long currentIndex; 39 IdentityDescriptor identity; 40 private int indent = 4; 41 42 public EventRecord() 43 { 44 tr = new TraceRecord(); 45 } 46 47 public EventRecord(TraceEvent e) 48 { 49 this(); 50 try 51 { 52 tr.trail_label = e.trail_label; 53 tr.message_id = e.message_id; 54 identity = e.identity; 55 tr.trail_id = e.trail_id; 56 tr.event_counter = e.event_counter; 57 tr.thread_id = e.thread_id; 58 tr.op_name = e.op_name; 59 tr.interaction_point = e.interaction_point; 60 tr.time_stamp = e.time_stamp; 61 tr.linkKey = -1; 62 63 if (tr.interaction_point == InteractionPoint.STUB_OUT || tr.interaction_point == InteractionPoint.POA_IN) 64 { 65 idlNode = new IdlOperation(e.identity.object_repository_id, tr.op_name, e.parameters, e.parameter_values, false); 66 } 67 if (tr.interaction_point == InteractionPoint.ONEWAY_STUB_OUT || tr.interaction_point == InteractionPoint.ONEWAY_POA_IN) 68 { 69 idlNode = new IdlOperation(e.identity.object_repository_id, tr.op_name, e.parameters, e.parameter_values, true); 70 } 71 if (tr.interaction_point == InteractionPoint.STUB_IN || tr.interaction_point == InteractionPoint.POA_OUT) 72 { 73 idlNode = new IdlReply(e.identity.object_repository_id, tr.op_name, e.parameters, e.parameter_values); 74 } 75 if (tr.interaction_point == InteractionPoint.STUB_IN_EXCEPTION || tr.interaction_point == InteractionPoint.POA_OUT_EXCEPTION) 76 { 77 idlNode = new IdlReply(e.identity.object_repository_id, tr.op_name, e.parameter_values[0]); 78 } 79 } 80 catch (Exception ex) 81 { 82 ex.printStackTrace(); 83 } 84 } 85 86 public static void setEventDB(EventDataBase db) { 87 eventDB = db; 88 } 89 90 public TraceRecord getTraceRecord() 91 { 92 return tr; 93 } 94 95 public Long key() 96 { 97 return new Long (tr.key_id); 98 } 99 100 public long getKey() 101 { 102 return tr.key_id; 103 } 104 105 public Long getLinkKey() 106 { 107 return new Long (tr.linkKey); 108 } 109 110 public long getLink() 111 { 112 return tr.linkKey; 113 } 114 115 public Long getIdentityKey() 116 { 117 return new Long (tr.identityKey); 118 } 119 120 public InteractionPoint getInteractionPoint() 121 { 122 return tr.interaction_point; 123 } 124 125 public String getProcessId() 126 { 127 return identity.process_id; 128 } 129 130 public String getMessageId() 131 { 132 return tr.message_id; 133 } 134 135 public long getIndex() 136 { 137 return tr.event_counter; 138 } 139 140 public int getEventCounter() { 141 return tr.event_counter; 142 } 143 144 public boolean isOutgoingMessage() 145 { 146 return (tr.interaction_point == InteractionPoint.STUB_OUT || tr.interaction_point == InteractionPoint.POA_OUT || tr.interaction_point == InteractionPoint.POA_OUT_EXCEPTION || tr.interaction_point == InteractionPoint.ONEWAY_STUB_OUT); 147 } 148 149 public boolean isIncommingMessage() 150 { 151 return !isOutgoingMessage(); 152 } 153 154 public boolean isReturn() 155 { 156 return ((tr.interaction_point == InteractionPoint.POA_OUT) || (tr.interaction_point == InteractionPoint.POA_OUT_EXCEPTION) || (tr.interaction_point == InteractionPoint.STUB_IN) || (tr.interaction_point == InteractionPoint.STUB_IN_EXCEPTION)); 157 } 158 159 public boolean isForward() 160 { 161 return !isReturn(); 162 } 163 164 public boolean isException() 165 { 166 return((tr.interaction_point == InteractionPoint.POA_OUT_EXCEPTION) || (tr.interaction_point == InteractionPoint.STUB_IN_EXCEPTION)); 167 } 168 169 public boolean isOneway() 170 { 171 return ((tr.interaction_point == InteractionPoint.ONEWAY_STUB_OUT) || (tr.interaction_point == InteractionPoint.ONEWAY_POA_IN)); 172 } 173 174 public boolean isLinked() 175 { 176 return tr.linkKey != -1; 177 } 178 179 public String getTimeStamp() 180 { 181 java.util.Date date = new java.util.Date (tr.time_stamp); 182 SimpleDateFormat simpledateformat = (SimpleDateFormat )DateFormat.getDateTimeInstance(1, 1); 183 simpledateformat.applyPattern("EEE MMM d H:mm:ss:SS yyyy"); 184 String time = simpledateformat.format(date); 185 186 return time; 187 } 188 189 public long getTime() 190 { 191 return tr.time_stamp; 192 } 193 194 public String getTrailLabel() { 195 return tr.trail_label; 196 } 197 198 public String getTrailId() 199 { 200 return tr.trail_id; 201 } 202 203 public String getOpName() { 204 return tr.op_name; 205 } 206 207 public String getThreadId() 208 { 209 return tr.thread_id; 210 } 211 212 public String getInteractionPointName() 213 { 214 switch (tr.interaction_point.value()) 215 { 216 case InteractionPoint._STUB_OUT: return "STUB_OUT"; 217 case InteractionPoint._STUB_IN: return "STUB_IN"; 218 case InteractionPoint._POA_OUT: return "POA_OUT"; 219 case InteractionPoint._POA_IN: return "POA_IN"; 220 case InteractionPoint._STUB_IN_EXCEPTION: return "STUB_IN_EXCEPTION"; 221 case InteractionPoint._POA_OUT_EXCEPTION: return "POA_OUT_EXCEPTION"; 222 case InteractionPoint._ONEWAY_STUB_OUT: return "ONEWAY_STUB_OUT"; 223 case InteractionPoint._ONEWAY_POA_IN: return "ONEWAY_POA_IN"; 224 } 225 return ""; 226 } 227 228 static public String getIdentityKindName(IdentityKind kind) 229 { 230 switch (kind.value()) 231 { 232 case IdentityKind._CCM_CONTAINER: return "CCM_CONTAINER"; 233 case IdentityKind._CCM_COMPONENT: return "CCM_COMPONENT"; 234 case IdentityKind._CCM_OBJECT: return "CCM_OBJECT"; 235 case IdentityKind._CCM_PROCESS: return "CCM_PROCESS"; 236 case IdentityKind._CCM_NODE: return "CCM_NODE"; 237 case IdentityKind._CCM_DOMAIN: return "CCM_DOMAIN"; 238 } 239 return ""; 240 } 241 242 public String getParameterValues() 243 { 244 if (idlNode == null) { 245 return ""; 247 } 248 XmlWriter w = new XmlWriter(indent); 249 XmlNode.write(idlNode, w); 250 return w.toString(); 251 } 252 253 public IdlNode getParameters() 254 { 255 return null; 269 } 270 271 public void setCurrentIndex(long i) 272 { 273 currentIndex = i; 274 } 275 276 public long getCurrentIndex() 277 { 278 return currentIndex; 279 } 280 281 public String toXml(EventDataBase db) 282 { 283 StringBuffer sb = new StringBuffer (); 284 285 sb.append(indent() + "<traceEvent id='" + getKey() + "'>\n"); 286 indent++; 287 sb.append(indent() + "<interactionPoint>" + getInteractionPointName() + "</interactionPoint>\n"); 288 sb.append(indent() + "<trailLabel>" + tr.trail_label + "</trailLabel>\n"); 289 sb.append(indent() + "<originator>" + getTrailId() + "</originator>\n"); 290 sb.append(indent() + "<yposIndex>" + currentIndex + "</yposIndex>\n"); 291 sb.append(indent() + "<timeStamp>" + getTimeStamp() + "</timeStamp>\n"); 292 sb.append(indent() + "<linkedEvent>" + tr.linkKey + "</linkedEvent>\n"); 293 sb.append(indent() + "<operation>" + getOpName() + "</operation>\n"); 294 sb.append(indent() + "<identityKey>" + tr.identityKey + "</identityKey>\n"); 295 sb.append(indent() + "<parametersKey>" + tr.parametersKey + "</parametersKey>\n"); 296 297 indent--; 298 sb.append(indent() + "</traceEvent>\n"); 299 300 return sb.toString(); 301 } 302 303 private String indent() 304 { 305 StringBuffer sb = new StringBuffer (""); 306 for (int i = 0; i < indent; i++) 307 { 308 sb.append(" "); 309 } 310 return sb.toString(); 311 } 312 } 313 | Popular Tags |