KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > imr > Server


1 package test.imr;
2
3 import java.io.*;
4
5 import org.omg.CORBA.*;
6 import org.omg.PortableServer.*;
7
8 import org.jacorb.util.*;
9
10 public class Server
11     extends TestIfPOA
12 {
13     public Server()
14     {
15     }
16
17     public void op()
18     {
19         //todo: implement
20
}
21         
22     public static void main(String JavaDoc[] args)
23     {
24         if( args.length != 2 )
25     {
26             System.out.println(
27                 "Usage: jaco test.imr.Server <ior_file> <timeout in secs>");
28             System.exit( 1 );
29         }
30
31         System.setProperty( "jacorb.implname", "imr_test" );
32         System.setProperty( "jacorb.use_imr", "on" );
33
34         try
35         {
36             long timeout = Integer.parseInt( args[1] ) * 1000;
37             //init ORB
38
ORB orb = ORB.init( args, null );
39
40             org.omg.PortableServer.POA JavaDoc root_poa =
41         org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
42
43         root_poa.the_POAManager().activate();
44
45         org.omg.CORBA.Policy JavaDoc[] policies = new org.omg.CORBA.Policy JavaDoc[2];
46
47         policies[0] = root_poa.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
48         policies[1] = root_poa.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
49         POA test_poa = root_poa.create_POA( "ImRTestServerPOA",
50                                                 root_poa.the_POAManager(),
51                                                 policies );
52         for (int i=0; i<policies.length; i++)
53         policies[i].destroy();
54
55
56             Server s = new Server();
57
58             byte[] id = "imr_test".getBytes();
59
60             test_poa.activate_object_with_id( id, s );
61             
62             // create the object reference
63
org.omg.CORBA.Object JavaDoc obj =
64                 test_poa.servant_to_reference( s );
65
66             PrintWriter pw =
67                 new PrintWriter( new FileWriter( args[ 0 ] ));
68
69             // print stringified object reference to file
70
pw.println( orb.object_to_string( obj ));
71             
72             pw.flush();
73             pw.close();
74     
75             // wait for requests
76
Thread.sleep( timeout );
77
78             orb.shutdown( true );
79         }
80         catch( Exception JavaDoc e )
81         {
82             System.out.println( e );
83         }
84     }
85 }
86
87
88
Popular Tags