KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > tracing > server > EventRecord


1 /***************************************************************************/
2 /* COACH: Component Based Open Source Architecture for */
3 /* Distributed Telecom Applications */
4 /* See: http://www.objectweb.org/ */
5 /* */
6 /* Copyright (C) 2003 Lucent Technologies Nederland BV */
7 /* Bell Labs Advanced Technologies - EMEA */
8 /* */
9 /* Initial developer(s): Harold Batteram */
10 /* */
11 /* This library is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public */
13 /* License as published by the Free Software Foundation; either */
14 /* version 2.1 of the License, or (at your option) any later version. */
15 /* */
16 /* This library is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
19 /* Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public */
22 /* License along with this library; if not, write to the Free Software */
23 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
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 JavaDoc;
31 import java.text.SimpleDateFormat JavaDoc;
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 JavaDoc 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 JavaDoc key()
96     {
97         return new Long JavaDoc(tr.key_id);
98     }
99     
100     public long getKey()
101     {
102         return tr.key_id;
103     }
104
105     public Long JavaDoc getLinkKey()
106     {
107         return new Long JavaDoc(tr.linkKey);
108     }
109
110     public long getLink()
111     {
112         return tr.linkKey;
113     }
114
115     public Long JavaDoc getIdentityKey()
116     {
117         return new Long JavaDoc(tr.identityKey);
118     }
119             
120     public InteractionPoint getInteractionPoint()
121     {
122         return tr.interaction_point;
123     }
124     
125     public String JavaDoc getProcessId()
126     {
127         return identity.process_id;
128     }
129
130     public String JavaDoc 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 JavaDoc getTimeStamp()
180     {
181         java.util.Date JavaDoc date = new java.util.Date JavaDoc(tr.time_stamp);
182         SimpleDateFormat JavaDoc simpledateformat = (SimpleDateFormat JavaDoc)DateFormat.getDateTimeInstance(1, 1);
183         simpledateformat.applyPattern("EEE MMM d H:mm:ss:SS yyyy");
184         String JavaDoc 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 JavaDoc getTrailLabel() {
195         return tr.trail_label;
196     }
197         
198     public String JavaDoc getTrailId()
199     {
200         return tr.trail_id;
201     }
202
203     public String JavaDoc getOpName() {
204         return tr.op_name;
205     }
206     
207     public String JavaDoc getThreadId()
208     {
209         return tr.thread_id;
210     }
211
212     public String JavaDoc 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 JavaDoc 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 JavaDoc getParameterValues()
243     {
244         if (idlNode == null) {
245             // no parameter information available.
246
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 // if (idlNode == null) {
256
// String xmlString = null;
257
// try {
258
// xmlString = eventDB.getParameterValues(tr.parametersKey);
259
// if (!xmlString.equals("")) {
260
// idlNode = XmlNode.getIdlNodeXml(xmlString);
261
// }
262
// } catch (Exception e) {
263
// System.out.println(xmlString);
264
// e.printStackTrace();
265
// }
266
// }
267
// return idlNode;
268
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 JavaDoc toXml(EventDataBase db)
282     {
283         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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 JavaDoc indent()
304     {
305         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("");
306         for (int i = 0; i < indent; i++)
307         {
308             sb.append(" ");
309         }
310         return sb.toString();
311     }
312 }
313
Popular Tags