1
10package client;
11
12import javax.naming.Context;
13import echo.EchoHome;
14import echo.Echo;
15
16public class Client {
17 private static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory";
18 public static void main(String[] args) throws Exception {
20 int count = 1;
21 if (args.length < 1){
22 System.out.println("Usage:: java client.Client <url>");
23 return;
24 }
25 String url = args[0];
26 if (args.length > 1){
27 count = Integer.parseInt(args[1]);
28 }
29
30 java.util.Properties h = new java.util.Properties();
31 h.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
32
33 h.put(Context.PROVIDER_URL, url);
34 Context ctx = new javax.naming.InitialContext(h);
35
36 Object home = ctx.lookup("ex1-echo-EchoHome");
37 EchoHome ehome = (EchoHome)narrow(home, EchoHome.class);
38 Echo estub = (Echo)narrow(ehome.create(), Echo.class);
39
40 String msg = "Hello, World!!";
41 System.out.println("Calling Echo.echo(\"" + msg + "\") ...");
42 String resp = null;
43 long ts = System.currentTimeMillis();
44 for (int i = 0; i < count; ++i){
45 resp = estub.echo(msg);
46 }
47 long et = System.currentTimeMillis() - ts;
48 System.out.println("... Echo.echo(\"" + msg + "\") = " + resp);
49
50 if (count > 1){
51 System.out.println("Elapsed Time for " + count + " invocations: " + et + " Milli Secs.");
52 }
53
54 System.out.println("Echo Client Executed successfully.");
55 }
56
57 private static Object narrow(Object o, Class c){
58 return javax.rmi.PortableRemoteObject.narrow(o, c);
59 }
60}
61