KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > load > imr > Client2


1 package test.load.imr;
2
3 import java.io.*;
4 import java.util.*;
5 import org.omg.CORBA.*;
6
7 public class Client2
8 {
9     private static ORB orb = null;
10
11     public static void main( String JavaDoc args[] )
12     {
13         if( args.length != 1 )
14     {
15             System.out.println( "Usage: jaco test.load.imr.Client <ior_file>" );
16             System.exit( 1 );
17         }
18
19         try
20     {
21             File f = new File( args[ 0 ] );
22
23             //check if file exists
24
if( ! f.exists() )
25             {
26                 System.out.println("File " + args[0] +
27                                    " does not exist.");
28                 
29                 System.exit( -1 );
30             }
31             
32             //check if args[0] points to a directory
33
if( f.isDirectory() )
34             {
35                 System.out.println("File " + args[0] +
36                                    " is a directory.");
37                 
38                 System.exit( -1 );
39             }
40
41             // initialize the ORB.
42
orb = ORB.init( args, null );
43
44             BufferedReader br =
45                 new BufferedReader( new FileReader( f ));
46
47             // get object reference from command-line argument file
48

49             String JavaDoc ior = br.readLine();
50             br.close();
51             
52             for( int i = 0; i < 20; i++ )
53             {
54                 Thread JavaDoc th = new Thread JavaDoc( new CallRunnable( ior, i ));
55                 th.start();
56             }
57         }
58         catch( Exception JavaDoc ex )
59     {
60             System.err.println( ex );
61         }
62     }
63     
64     private static class CallRunnable
65         implements Runnable JavaDoc
66     {
67         private int me = 0;
68         private String JavaDoc ior = null;
69         private Random rnd = null;
70         
71         public CallRunnable( String JavaDoc ior,
72                              int me )
73         {
74             this.ior = ior;
75             this.me = me;
76
77             rnd = new Random();
78         }
79
80         public void run()
81         {
82             try
83             {
84                 while( true )
85                 {
86                     org.omg.CORBA.Object JavaDoc obj =
87                         orb.string_to_object( ior );
88
89                     // and narrow it to HelloWorld.GoodDay
90
// if this fails, a BAD_PARAM will be thrown
91
GoodDay goodDay = GoodDayHelper.narrow( obj );
92
93                     goodDay.hello_simple( me );
94                     
95                     //Thread.currentThread().sleep( Math.abs( rnd.nextInt() % 100));
96
}
97             }
98             catch( Throwable JavaDoc th )
99             {
100                 th.printStackTrace();
101                 
102                 System.exit( -1 );
103             }
104         }
105     }
106 }
107
108
Popular Tags