1 package demo.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 SomeIfPOA 12 { 13 public Server() 14 { 15 } 16 17 public void op() 18 { 19 System.out.println("Server: Received call from client"); 20 } 21 22 public static void main(String [] args) 23 { 24 if( args.length != 2 ) 25 { 26 System.out.println( 27 "Usage: jaco demo.imr.Server <ior_file> <timeout in secs>"); 28 System.exit( 1 ); 29 } 30 31 System.setProperty( "jacorb.implname", "imr_demo" ); 32 System.setProperty( "jacorb.use_imr", "on" ); 33 34 try 35 { 36 long timeout = Integer.parseInt( args[1] ) * 1000; 37 ORB orb = ORB.init( args, null ); 39 40 org.omg.PortableServer.POA root_poa = 42 org.omg.PortableServer.POAHelper.narrow( 43 orb.resolve_initial_references("RootPOA")); 44 45 org.omg.CORBA.Policy [] policies = new org.omg.CORBA.Policy [2]; 47 48 policies[0] = root_poa.create_lifespan_policy(LifespanPolicyValue.PERSISTENT); 49 policies[1] = root_poa.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID); 50 51 POA demo_poa = root_poa.create_POA( "ImRDemoServerPOA", 53 root_poa.the_POAManager(), 54 policies ); 55 56 for (int i=0; i<policies.length; i++) 58 policies[i].destroy(); 59 60 Server s = new Server(); 62 63 byte[] id = "imr_demo".getBytes(); 65 66 demo_poa.activate_object_with_id( id, s ); 68 69 root_poa.the_POAManager().activate(); 71 72 73 org.omg.CORBA.Object obj = 75 demo_poa.servant_to_reference( s ); 76 77 PrintWriter pw = 78 new PrintWriter( new FileWriter( args[ 0 ] )); 79 80 pw.println( orb.object_to_string( obj )); 82 83 pw.flush(); 84 pw.close(); 85 86 Thread.sleep( timeout ); 88 89 orb.shutdown( true ); 90 } 91 catch( Exception e ) 92 { 93 System.out.println( e ); 94 } 95 } 96 } 97 98 99 | Popular Tags |