1 package demo.policies; 2 3 import java.io.*; 4 import org.omg.CORBA.*; 5 import org.omg.Messaging.*; 6 7 14 15 public class Client 16 { 17 public static final int MSEC_FACTOR = 10000; 18 public static final int ONE_SECOND = 1000 * MSEC_FACTOR; 19 20 public static void main( String args[] ) 21 { 22 if( args.length != 1 ) 23 { 24 System.out.println( "Usage: jaco demo.policies.Client <ior_file>" ); 25 System.exit( 1 ); 26 } 27 28 try 29 { 30 File f = new File( args[ 0 ] ); 32 if( ! f.exists() ) 33 { 34 System.out.println("File " + args[0] + 35 " does not exist."); 36 System.exit( -1 ); 37 } 38 39 if( f.isDirectory() ) 41 { 42 System.out.println("File " + args[0] + 43 " is a directory."); 44 System.exit( -1 ); 45 } 46 BufferedReader br = 47 new BufferedReader( new FileReader( f )); 48 49 ORB orb = ORB.init( args, null ); 51 52 org.omg.CORBA.Object obj = 54 orb.string_to_object( br.readLine() ); 55 56 br.close(); 57 58 GoodDay goodDay = GoodDayHelper.narrow( obj ); 61 62 64 PolicyManager policyManager = 65 PolicyManagerHelper.narrow( orb.resolve_initial_references("ORBPolicyManager")); 66 67 Any rrtPolicyAny = orb.create_any(); 71 rrtPolicyAny.insert_ulonglong( ONE_SECOND ); 72 73 Policy rrtPolicy = 76 orb.create_policy( RELATIVE_RT_TIMEOUT_POLICY_TYPE.value, 77 rrtPolicyAny ); 78 79 policyManager.set_policy_overrides( new Policy[] {rrtPolicy}, 80 SetOverrideType.ADD_OVERRIDE); 81 82 Any syncPolicyAny = orb.create_any(); 84 syncPolicyAny.insert_short( SYNC_WITH_SERVER.value ); 85 Policy syncPolicy = 86 orb.create_policy( SYNC_SCOPE_POLICY_TYPE.value, syncPolicyAny ); 87 88 goodDay._set_policy_override( new Policy[] {syncPolicy}, 90 SetOverrideType.ADD_OVERRIDE); 91 92 System.out.println( "Should see a TIMEOUT exception soon..."); 96 try 97 { 98 System.out.println( goodDay.hello( 2000 ) ); 99 System.out.println( "... should not be here, no exception!"); 100 } 101 catch ( org.omg.CORBA.TIMEOUT t ) 102 { 103 System.out.println( "here it is: " + t.getMessage()); 104 } 105 106 Any objRrtPolicyAny = orb.create_any(); 108 objRrtPolicyAny.insert_ulonglong( 4 * ONE_SECOND ); 109 110 Policy objRrtPolicy = 111 orb.create_policy( RELATIVE_RT_TIMEOUT_POLICY_TYPE.value, 112 objRrtPolicyAny ); 113 114 goodDay._set_policy_override( new Policy[] {objRrtPolicy}, 115 SetOverrideType.ADD_OVERRIDE); 116 117 Policy objPol = 119 goodDay._get_policy( RELATIVE_RT_TIMEOUT_POLICY_TYPE.value ); 120 121 if ( objPol != null) 122 { 123 long timoutValue = ((RelativeRoundtripTimeoutPolicy)objPol).relative_expiry(); 124 System.out.println("Object-level timeout is " + timoutValue + " timesteps (100ns)"); 125 126 System.out.println( goodDay.hello( 100 )); 130 } 131 else 132 { 133 System.out.println("ERROR, no Object-level timeout found"); 134 } 135 } 136 catch( Exception ex ) 137 { 138 ex.printStackTrace(); 139 } 140 } 141 } 142 143 | Popular Tags |