01: package demo.ami;
02:
03: import java.io.*;
04: import org.omg.CORBA.*;
05: import org.omg.PortableServer.*;
06:
07: public class Client {
08: public static void main(String args[]) {
09: if (args.length != 1) {
10: System.out
11: .println("Usage: java demo.ami.Client <ior_file>");
12: System.exit(1);
13: }
14:
15: try {
16: File f = new File(args[0]);
17:
18: //check if file exists
19: if (!f.exists()) {
20: System.out.println("File " + args[0]
21: + " does not exist.");
22:
23: System.exit(-1);
24: }
25:
26: //check if args[0] points to a directory
27: if (f.isDirectory()) {
28: System.out.println("File " + args[0]
29: + " is a directory.");
30:
31: System.exit(-1);
32: }
33:
34: // initialize the ORB.
35: ORB orb = ORB.init(args, null);
36:
37: POA poa = POAHelper.narrow(orb
38: .resolve_initial_references("RootPOA"));
39: poa.the_POAManager().activate();
40:
41: BufferedReader br = new BufferedReader(new FileReader(f));
42:
43: // get object reference from command-line argument file
44: org.omg.CORBA.Object obj = orb.string_to_object(br
45: .readLine());
46: br.close();
47:
48: AsyncServer s = AsyncServerHelper.narrow(obj);
49: AMI_AsyncServerHandler h = new AMI_AsyncServerHandlerImpl()
50: ._this (orb);
51:
52: System.out.println("* sending async...");
53: ((_AsyncServerStub) s).sendc_op2(h, 2);
54: System.out.println("* ...done. Waiting for reply...");
55:
56: try {
57: Thread.currentThread().sleep(10000);
58: } catch (InterruptedException ex) {
59: }
60:
61: } catch (Exception ex) {
62: System.err.println(ex);
63: }
64: }
65: }
|