import java.util.Properties;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import ejb3bankapp.ejb.sfsb.BankControl;

public class BankEJBClientSFSB {

   public static void main(String[] args) throws Exception {
      BankControl bankControlA = null;
      BankControl bankControlB = null;
      try {
         InitialContext initialContext = getInitialContext();
         bankControlA = (BankControl) initialContext.lookup("BankControlSFSBBean/remote");←(1)
         bankControlB = (BankControl) initialContext.lookup("BankControlSFSBBean/remote");←(1)

         bankControlA.createAccount(1000, 0, "ttazawa");←(2)
         bankControlB.createAccount(2000, 100000, "eyazawa");←(2)

         bankControlA.deposit(15000);

         System.out.println(bankControlA.getName() + ":" + bankControlA.getBalance());
         System.out.println(bankControlB.getName() + ":" + bankControlB.getBalance());

         bankControlA.withdraw(10000);←(3)
         bankControlB.deposit(10000);←(4)

         System.out.println(bankControlA.getName() + ":" + bankControlA.getBalance());
         System.out.println(bankControlB.getName() + ":" + bankControlB.getBalance());
      } catch (Exception e) {
         e.printStackTrace();
      } finally {
         bankControlA.destroy();←(5)
         bankControlB.destroy();←(6)
      }
   }

   private static InitialContext getInitialContext() throws NamingException {
      Properties properties = new Properties();
      properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      properties.put(javax.naming.Context.PROVIDER_URL, "jnp://localhost:1099");
      return new javax.naming.InitialContext(properties);
   }

}