KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > util > tracing > TracingServiceImpl


1 package org.jacorb.util.tracing;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import java.util.Hashtable JavaDoc;
24 import org.jacorb.util.tracing.TracingServicePackage.NoSuchRequestId;
25 import org.omg.CosNaming.NamingContextExt JavaDoc;
26 import org.omg.CosNaming.NamingContextExtHelper JavaDoc;
27
28 /**
29  * @author Gerald Brose
30  * @version $Id: TracingServiceImpl.java,v 1.9 2004/05/06 12:40:01 nicolas Exp $
31  */

32 public class TracingServiceImpl
33     extends TracingServicePOA
34 {
35     private int pointIds = 0;
36     private Hashtable JavaDoc traces = new Hashtable JavaDoc();
37
38     public synchronized int get_id()
39     {
40         return pointIds++;
41     }
42
43     public TraceData getTrace( Request source )
44         throws NoSuchRequestId
45     {
46         if( source.originator >= pointIds )
47         {
48             System.out.println(">>>>>>>>>EXCEPTION!!! - getTrace()");
49
50             throw new NoSuchRequestId();
51         }
52
53         System.out.println("getTrace for tracer: " + source.originator +
54                            ", rid: " + source.rid);
55
56
57         Long JavaDoc key = new Long JavaDoc( source.rid );
58
59         TraceTreeNode t = (TraceTreeNode) traces.get( key );
60
61         if ( t == null )
62         {
63             return new TraceData( new TraceData[0], 0, "", 0, 0 );
64         }
65
66
67         TraceData result = new TraceData( new TraceData[t.subtraces.size()],
68                                           t.tracer_id,
69                                           t.operation,
70                                           t.client_time,
71                                           t.server_time );
72
73         for( int i = 0; i < t.subtraces.size(); i++ )
74         {
75             Request r = (Request) t.subtraces.elementAt( i );
76             result.subtrace[i] = getTrace( r );
77         }
78
79         return result;
80     }
81
82     public void logTraceAtPoint( Request origin,
83                                  String JavaDoc operation,
84                                  long client_time,
85                                  long server_time)
86         throws NoSuchRequestId
87     {
88         if( origin.originator >= pointIds )
89         {
90             System.out.println(">>>>>>>>>EXCEPTION!!! - logTraceAtPoint()");
91
92
93             throw new NoSuchRequestId();
94         }
95
96         System.out.println("logTraceAtPoint for tracer: " +
97                            origin.originator +
98                            ", rid: " + origin.rid);
99
100
101         Long JavaDoc key = new Long JavaDoc( origin.rid );
102
103         TraceTreeNode t = (TraceTreeNode) traces.get( key );
104
105         if( t == null )
106         {
107             t = new TraceTreeNode( origin.originator );
108             traces.put( key, t );
109         }
110
111         t.operation = operation;
112         t.client_time = client_time;
113         t.server_time = server_time;
114     }
115
116     public void registerSubTrace(Request original, // original call
117
Request nested) // nested call
118
throws NoSuchRequestId
119     {
120
121         System.out.println("registerSubTrace for tracer: " +
122                            original.originator +
123                            ", rid: " + original.rid);
124
125         if( original.originator >= pointIds ||
126             nested.originator >= pointIds )
127         {
128             System.out.println(">>>>>>>>>EXCEPTION!!! - registerSubTrace()");
129             throw new NoSuchRequestId();
130         }
131
132         Long JavaDoc key = new Long JavaDoc( original.rid );
133
134         TraceTreeNode t = (TraceTreeNode) traces.get( key );
135
136         if( t == null )
137         {
138             t = new TraceTreeNode( original.originator );
139             traces.put( key, t );
140         }
141
142         t.subtraces.addElement( nested );
143     }
144
145
146
147     public static void main( String JavaDoc[] args )
148     {
149     org.omg.CORBA.ORB JavaDoc orb = org.omg.CORBA.ORB.init(args, null);
150     try
151     {
152             org.omg.PortableServer.POA JavaDoc poa =
153         org.omg.PortableServer.POAHelper.narrow(
154                                                         orb.resolve_initial_references("RootPOA"));
155
156         poa.the_POAManager().activate();
157
158         org.omg.CORBA.Object JavaDoc o =
159                 poa.servant_to_reference(new TracingServiceImpl());
160
161             NamingContextExt JavaDoc nc =
162                 NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
163             nc.bind( nc.to_name("tracing.service"), o);
164         poa.the_POAManager().activate();
165     }
166     catch ( Exception JavaDoc e )
167     {
168         e.printStackTrace();
169     }
170     orb.run();
171     }
172 }
173
174
175
176
177
178
179
180
181
182
183
184
185
Popular Tags