1 package org.jacorb.util.tracing; 2 3 22 23 import java.util.Hashtable ; 24 import org.jacorb.util.tracing.TracingServicePackage.NoSuchRequestId; 25 import org.omg.CosNaming.NamingContextExt ; 26 import org.omg.CosNaming.NamingContextExtHelper ; 27 28 32 public class TracingServiceImpl 33 extends TracingServicePOA 34 { 35 private int pointIds = 0; 36 private Hashtable traces = new Hashtable (); 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 key = new Long ( 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 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 key = new Long ( 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, Request nested) 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 key = new Long ( 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 [] args ) 148 { 149 org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null); 150 try 151 { 152 org.omg.PortableServer.POA 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 o = 159 poa.servant_to_reference(new TracingServiceImpl()); 160 161 NamingContextExt 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 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 |