import java.io.*; import java.net.*; import org.omg.CORBA.*; //import org.omg.PortableServer.*; /* This is the client application which needs to use the services of a BeepGenerator sever * server object. It operates by reading in a reference to a BeepGenerator object from * an exernal file and making an invocation on that reference. */ public class AccountClient { static org.omg.CORBA.ORB orb = null; //ORB //variable holding the requested number of beeps from the server //holds a reference to the servant object private Account accountServer = null; public void startClient() { try { BufferedReader in = new BufferedReader( new FileReader( "account.objid" )); String ref = in.readLine(); int cheque = 100; in.close(); org.omg.CORBA.Object obj = orb.string_to_object(ref); //Account accountServer = null; //Obtain reference to the Account server object by reading in reference from a file accountServer = AccountHelper.narrow(obj); OnewayReqDepositCheque onewayReq = new OnewayReqDepositCheque(accountServer, cheque); onewayReq.start(); Thread.currentThread().sleep(1000); System.out.println("The cheque was deposited and the balance now is: "+accountServer.balance()); } catch(java.lang.InterruptedException ex){ ex.printStackTrace(System.out); } catch( IOException ex ) { System.out.println( "Could not open file 'account.objid'" ); System.exit( -1 ); } catch(Exception ex) { System.out.println("Unexpected CORBA exception: " + ex); ex.printStackTrace(System.out); } } public static void main (String argc[]) { // Initialise the ORB and the root naming context orb = ORB.init(argc, null); AccountClient accountClient = new AccountClient(); accountClient.startClient(); // Ensure that the ORB is properly shutdown and cleaned up. try { orb.shutdown(true); } catch (Exception ex) {} return; } }