KickJava   Java API By Example, From Geeks To Geeks.

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


1 package test.load.imr;
2
3 import java.io.*;
4 import java.util.*;
5 import org.omg.CORBA.*;
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: jaco test.load.imr.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             BufferedReader br =
43                 new BufferedReader( new FileReader( f ));
44
45             // get object reference from command-line argument file
46
org.omg.CORBA.Object JavaDoc obj =
47                 orb.string_to_object( br.readLine() );
48
49             br.close();
50
51             // and narrow it to HelloWorld.GoodDay
52
// if this fails, a BAD_PARAM will be thrown
53
GoodDay goodDay = GoodDayHelper.narrow( obj );
54             
55             for( int i = 0; i < 40; i++ )
56             {
57                 Thread JavaDoc th = new Thread JavaDoc( new CallRunnable( goodDay, i ));
58                 th.start();
59             }
60         }
61         catch( Exception JavaDoc ex )
62     {
63             System.err.println( ex );
64         }
65     }
66     
67     private static class CallRunnable
68         implements Runnable JavaDoc
69     {
70         private int me = 0;
71         private GoodDay good_day = null;
72         private Random rnd = null;
73         
74         public CallRunnable( GoodDay good_day,
75                              int me )
76         {
77             this.good_day = good_day;
78             this.me = me;
79
80             rnd = new Random();
81         }
82
83         public void run()
84         {
85             try
86             {
87                 //while( true )
88
//{
89
good_day.hello_simple( me );
90                     
91                     //Thread.currentThread().sleep( Math.abs( rnd.nextInt() % 100));
92
//}
93
}
94             catch( Throwable JavaDoc th )
95             {
96                 th.printStackTrace();
97                 
98                 System.exit( -1 );
99             }
100         }
101     }
102 }
103
104
Popular Tags