1 package test.maxConnectionEnforcement; 2 3 import java.io.*; 4 import java.util.*; 5 6 import org.omg.CORBA.*; 7 import org.omg.PortableServer.*; 8 import org.omg.BiDirPolicy.*; 9 10 import org.jacorb.util.*; 11 12 public class Server 13 extends TestIfPOA 14 { 15 Random rnd = null; 16 17 public Server() 18 { 19 rnd = new Random(); 20 } 21 22 public void op() 23 { 24 System.out.println("op called"); 25 } 26 27 public void doCallback( CallbackIf callback ) 28 { 29 System.out.println("doCallback called"); 30 31 try 32 { 33 Thread.sleep( Math.abs( rnd.nextInt() ) % 100 ); 34 } 35 catch( Exception e ) 36 { 37 e.printStackTrace(); 38 } 39 40 System.out.println("\tslept"); 41 42 callback.opOnCallback(); 43 44 System.out.println("\treturned"); 45 } 46 47 public static void main(String [] args) 48 { 49 if( args.length != 2 ) 50 { 51 System.out.println( 52 "Usage: jaco test.maxConnectionEnforcement.Server <ior_file> <max transports>"); 53 System.exit( 1 ); 54 } 55 56 try 57 { 58 Properties props = new Properties(); 59 props.put( "jacorb.connection.max_server_connections", 60 args[1] ); 61 props.put( "jacorb.connection.selection_strategy_class", 62 "org.jacorb.orb.connection.LRUSelectionStrategyImpl" ); 63 props.put( "jacorb.connection.statistics_provider_class", 64 "org.jacorb.orb.connection.LRUStatisticsProviderImpl" ); 65 props.put( "org.omg.PortableInterceptor.ORBInitializerClass.bidir_init", 66 "org.jacorb.orb.connection.BiDirConnectionInitializer" ); 67 68 69 ORB orb = ORB.init( args, props ); 71 72 POA root_poa = 74 POAHelper.narrow( orb.resolve_initial_references( "RootPOA" )); 75 76 Any any = orb.create_any(); 77 BidirectionalPolicyValueHelper.insert( any, BOTH.value ); 78 79 Policy[] policies = new Policy[4]; 80 policies[0] = 81 root_poa.create_lifespan_policy(LifespanPolicyValue.TRANSIENT); 82 83 policies[1] = 84 root_poa.create_id_assignment_policy(IdAssignmentPolicyValue.SYSTEM_ID); 85 86 policies[2] = 87 root_poa.create_implicit_activation_policy( ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION ); 88 89 policies[3] = orb.create_policy( BIDIRECTIONAL_POLICY_TYPE.value, 90 any ); 91 92 POA bidir_poa = root_poa.create_POA( "BiDirPOA", 93 root_poa.the_POAManager(), 94 policies ); 95 bidir_poa.the_POAManager().activate(); 96 97 98 Server s = new Server(); 99 100 org.omg.CORBA.Object obj = 102 bidir_poa.servant_to_reference( s ); 103 104 PrintWriter pw = 105 new PrintWriter( new FileWriter( args[ 0 ] )); 106 107 pw.println( orb.object_to_string( obj )); 109 110 pw.flush(); 111 pw.close(); 112 113 orb.run(); 115 } 116 catch( Exception e ) 117 { 118 System.out.println( e ); 119 } 120 } 121 } 122 123 124 | Popular Tags |