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.service.pi; 26 27 import org.omg.CORBA.*; 28 import org.omg.IOP.*; 29 import org.omg.IOP.CodecPackage.*; 30 import org.omg.PortableInterceptor.*; 31 import java.util.Hashtable ; 32 import org.omg.PortableInterceptor.Current ; 33 import org.coach.tracing.api.*; 34 import org.coach.tracing.api.pi.*; 35 import org.coach.tracing.service.*; 36 import org.coach.util.IorPrinter; 37 import org.omg.Dynamic.Parameter ; 38 import org.omg.PortableServer.*; 39 40 public class TracingServiceInterceptor extends LocalObject implements ClientRequestInterceptor, ServerRequestInterceptor 41 { 42 private int slotId; 43 private Codec codec; 44 private Current piCurrent; 45 private static boolean ready; 46 private static Sender sender; 47 private static ORB orb; 48 private static Hashtable requestContextTable = new Hashtable (); 49 50 private static final int serviceContextId = 100; 51 52 public TracingServiceInterceptor(int slotId) 53 { 54 this.slotId = slotId; 55 } 57 58 void init(Current piCurrent, Codec codec) 59 { 60 this.piCurrent = piCurrent; 61 this.codec = codec; 62 } 63 64 public static void init() 65 { 66 if (sender == null && !Sender.isInitializing()) 67 { 68 try 69 { 70 orb = org.objectweb.openccm.corba.TheORB.getORB(); 71 if (orb != null) 72 { 73 sender = Sender.createSender(orb); 74 ready = true; 75 } 76 } 77 catch (Throwable e) 78 { 79 } 80 } 81 } 82 83 87 public String name() 88 { 89 return "TracingServiceInterceptor"; 90 } 91 92 public void destroy() 93 { 94 } 95 96 public void send_request(ClientRequestInfo ri) 100 { 101 if (ready && !ri.operation().equals("receiveEvent")) 103 { 104 try 105 { 106 Any any = ri.get_slot(slotId); 109 if (any != null && any.type().kind().equals(TCKind.tk_string)) 110 { 111 String key = any.extract_string(); 112 String ior = orb.object_to_string(ri.effective_target()); 113 IorPrinter iorPrinter = new IorPrinter(ior); 114 String id = iorPrinter.getTypeId(); 115 116 ThreadContext tc = ThreadContext.getThreadContext(key); 120 tc.setObjectInstanceId("Stub_" + ri.effective_target().hashCode()); 121 tc.setObjectRepositoryId(id); 122 if (ri.response_expected()) 123 { 124 Integer rid = new Integer (ri.request_id()); 125 tc.setCurrentOperation(ri.operation()); 126 requestContextTable.put(rid, tc); 127 } 128 String name = tc.getThreadId(); 129 sender.stubPreInvoke(tc, ri.operation(), null, null, !ri.response_expected()); 131 132 any = orb.create_any(); 134 PropagationContext pc = tc.getPropagationContext(); 135 PropagationContextHelper.insert(any, pc); 136 byte[] serviceContextData = codec.encode(any); 138 ServiceContext serviceContext = new ServiceContext(serviceContextId, serviceContextData); 139 140 ri.add_request_service_context(serviceContext, true); 142 if (ri.response_expected()) 143 { 144 tc.pushRequestContext(); 145 } 146 } 148 } 149 catch (InvalidSlot e) 150 { 151 } 152 catch (Exception e) 153 { 154 e.printStackTrace(); 155 } 156 } 157 } 158 159 public void send_poll(ClientRequestInfo ri) 160 { 161 } 163 164 public void receive_reply(ClientRequestInfo ri) 165 { 166 ThreadContext tc = (ThreadContext)requestContextTable.remove(new Integer (ri.request_id())); 167 if (tc != null) 168 { 169 try 170 { 171 tc.popRequestContext(); 172 173 sender.stubPostInvoke(tc, ri.operation(), null, null, false, false); 175 } 176 catch (Exception e) 177 { 178 } 179 } 180 } 181 182 public void receive_exception(ClientRequestInfo ri) 183 { 184 } 186 187 public void receive_other(ClientRequestInfo ri) 188 { 189 } 191 192 public void receive_request_service_contexts(ServerRequestInfo ri) 196 { 197 init(); 198 200 if (ready && !ri.operation().equals("receiveEvent")) 201 { 202 try 204 { 205 ServiceContext serviceContext = ri.get_request_service_context(serviceContextId); 207 Any any = codec.decode(serviceContext.context_data); 208 if (any.type().equal(PropagationContextHelper.type())) 209 { 210 ri.set_slot(slotId, any); 213 } 217 } 218 catch (Exception e) 219 { 220 } 222 } 223 } 224 225 public void receive_request(ServerRequestInfo ri) 226 { 227 229 if (ready && !ri.operation().equals("receiveEvent")) 233 { 234 try 236 { 237 Any tsc = ri.get_slot(slotId); 238 PropagationContext pc = null; 239 if (tsc != null && tsc.type().equal(PropagationContextHelper.type())) 240 { 241 try 246 { 247 pc = PropagationContextHelper.extract(tsc); 248 249 ThreadContext tc = ThreadContext.getCurrentThreadContext(); 250 String id = ri.target_most_derived_interface(); 251 tc.setCurrentInterfaceId(id); 252 String key = tc.getThreadId(); 253 tc.setComponentName("CCM_Component_" + id.hashCode()); 257 tc.setComponentType(id); 258 259 tc.setObjectInstanceId("Poa_" + id); 260 tc.setObjectRepositoryId(id); 261 tc.setPropagationContext(pc); 262 263 sender.poaPreInvoke(tc, ri.operation(), null, null, !ri.response_expected()); 265 266 if (ri.response_expected()) 268 { 269 Integer rid = new Integer (ri.request_id()); 270 tc.setCurrentOperation(ri.operation()); 271 requestContextTable.put(rid, tc); 272 } 273 274 Any any = orb.create_any(); 275 any.insert_string(key); 276 ri.set_slot(slotId, any); 277 } 278 catch (Exception ex) 279 { 280 ex.printStackTrace(); 281 } 282 } 283 } 284 catch (Exception e) 285 { 286 e.printStackTrace(); 287 } 288 } 289 } 290 291 public void send_reply(ServerRequestInfo ri) 292 { 293 ThreadContext tc = (ThreadContext)requestContextTable.remove(new Integer (ri.request_id())); 296 if (tc != null) 297 { 298 try 299 { 300 sender.poaPostInvoke(tc, ri.operation(), null, null); 302 } 303 catch (Exception e) 304 { 305 e.printStackTrace(); 306 } 307 } 308 } 309 310 public void send_exception(ServerRequestInfo ri) 311 { 312 } 315 316 public void send_other(ServerRequestInfo ri) 317 { 318 } 320 } 321 | Popular Tags |