1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 package org.coach.tracing.server; 23 24 import org.coach.tracing.api.*; 25 import org.omg.CORBA.*; 26 import java.io.*; 27 import java.util.*; 28 import java.net.*; 29 30 public class ServerTest 31 { 32 private i_Trace connection; 33 private org.omg.CORBA.ORB orb; 34 private int event_counter = 0; 36 private String appl_id; 37 38 public ServerTest () 39 { 40 } 41 42 47 void init (String args[]) 48 { 49 try 50 { 51 args = org.objectweb.openccm.corba.TheORB.initialize(args); 52 53 orb = org.objectweb.openccm.corba.TheORB.getORB(); 54 55 org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService"); 56 57 org.omg.CosNaming.NamingContext nc = org.omg.CosNaming.NamingContextHelper.narrow(obj); 58 59 org.omg.CosNaming.NameComponent [] ncomp = new org.omg.CosNaming.NameComponent [1]; 60 61 ncomp[0] = new org.omg.CosNaming.NameComponent ("COACH_TracingServer", ""); 62 63 obj = nc.resolve(ncomp); 64 65 connection = i_TraceHelper.narrow (obj); 66 67 java.io.File tmp = java.io.File.createTempFile("tmp", ""); 68 69 tmp.deleteOnExit(); 70 71 appl_id = tmp.getName().substring(3); 72 } 73 catch (Exception _ex) 74 { 75 _ex.printStackTrace(); 76 77 System.exit(-1); 78 } 79 } 80 81 86 public static void main(String [] args) 87 { 88 ServerTest application = new ServerTest(); 89 90 application.init(args); 91 92 94 if ( args.length == 0 ) 95 application.send_invocations(1); 96 else 97 application.send_invocations(Integer.parseInt(args[0])); 98 } 99 100 public void send_invocations(int cnt) 101 { 102 IdentityDescriptor cmp1 = createObject (appl_id, "Container_A", "Component_1", "Hello_A"); 103 IdentityDescriptor cmp2 = createObject (appl_id, "Container_A", "Component_2", "Hello_B"); 104 IdentityDescriptor cmp3 = createObject (appl_id, "Container_B", "Component_1", "Hello_C"); 105 IdentityDescriptor cmp4 = createObject (appl_id, "Container_C", "Component_1", "Hello_D"); 106 107 109 Parameter[] parameter = new Parameter[] { 110 new Parameter("in", "string", "v1") 111 }; 112 113 Any[] value = new Any[1]; 114 115 value[0] = orb.create_any(); 116 value[0].insert_string("Hello World"); 117 118 System.out.println ("Coach Tracing Server Test, n = " + cnt); 119 120 for (int i = 0; i < cnt; i++) 121 { 122 invocation ("hello_world", cmp1, cmp2, parameter, value, true); invocation ("hi_there", cmp2, cmp3, parameter, value, false); 124 invocation ("how_are_you", cmp3, cmp4, parameter, value, false); 125 invocation ("I'm_fine", cmp3, cmp2, parameter, value, false); 126 invocation ("thank_you", cmp2, cmp1, parameter, value, false); 127 } 128 } 129 130 public void invocation (String operation_name, 131 IdentityDescriptor from, 132 IdentityDescriptor to, 133 Parameter[] parameters, 134 Any[] values, 135 boolean oneway) 136 { 137 139 140 String exec_thread = ""; 141 142 try 143 { 144 exec_thread = Thread.currentThread().getName() + "_" + InetAddress.getLocalHost().getHostName(); 145 } 146 catch (Exception _ex) 147 { 148 _ex.printStackTrace(); 149 } 150 151 152 153 String trail_id = new Integer (event_counter).toString(); 154 155 String message_id = trail_id + "_" + event_counter + "_"; 156 158 166 TraceEvent stub_out_event = new TraceEvent ( 167 System.currentTimeMillis(), 168 oneway ? InteractionPoint.ONEWAY_STUB_OUT : 169 InteractionPoint.STUB_OUT, 170 "", 173 message_id + "F", 174 exec_thread, 175 trail_id, 176 event_counter++, 177 operation_name, 178 from, 179 parameters, 180 values); 181 182 184 TraceEvent poa_in_event = new TraceEvent ( 185 System.currentTimeMillis(), 186 oneway ? InteractionPoint.ONEWAY_POA_IN : 187 InteractionPoint.POA_IN, 188 "", 191 message_id + "F", 192 exec_thread, 194 trail_id, 195 event_counter++, 196 operation_name, 197 to, 198 parameters, 199 values); 200 201 if ( oneway ) 202 { 203 205 TraceEvent[] events = new TraceEvent[2]; 206 207 events[0] = stub_out_event; 208 events[1] = poa_in_event; 209 210 connection.receiveEvent(events); 211 212 return; 213 } 214 215 217 TraceEvent poa_out_event = new TraceEvent ( 218 System.currentTimeMillis(), 219 InteractionPoint.POA_OUT, 220 "", 223 message_id + "B", 224 exec_thread, 226 trail_id, 227 event_counter++, 228 operation_name, 229 to, 230 parameters, 231 values); 232 233 235 TraceEvent stub_in_event = new TraceEvent ( 236 System.currentTimeMillis(), 237 InteractionPoint.STUB_IN, 238 "", 241 message_id + "B", 242 exec_thread, 244 trail_id, 245 event_counter++, 246 operation_name, 247 from, 248 parameters, 249 values); 250 251 TraceEvent[] events = new TraceEvent[4]; 252 253 events[0] = stub_out_event; 254 events[1] = poa_in_event; 255 events[2] = poa_out_event; 256 events[3] = stub_in_event; 257 258 connection.receiveEvent(events); 259 } 260 261 262 public IdentityDescriptor createObject( String process_id, 263 String container_name, 264 String component_name, 265 String object_name) 266 { 267 269 IdentityDescriptor identity = new IdentityDescriptor(); 270 271 try 272 { 273 identity.process_id = process_id; 274 identity.node_name = InetAddress.getLocalHost().getHostName(); 275 identity.node_ip = InetAddress.getLocalHost().getHostAddress(); 276 identity.object_instance_id = object_name; 277 identity.object_repository_id = "facet"; 278 identity.cmp_name = component_name; 279 identity.cmp_type = "component"; 280 identity.cnt_name = container_name; 281 identity.cnt_type = "container"; 282 } 283 catch (Exception _ex) 284 { 285 _ex.printStackTrace(); 286 } 287 288 return identity; 289 } 290 } 291 292 | Popular Tags |