KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > ami > Client


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