Package edu.vt.rt.hyflow.benchmark.realtimermi.bank.rw

Examples of edu.vt.rt.hyflow.benchmark.realtimermi.bank.rw.IBankAccount


    } catch (InterruptedException e) {
      e.printStackTrace();
    }
   
    long balance = 0;
    IBankAccount account = null;
    int node = Network.getInstance().nodesCount();
    for(int i=0; i<localObjectsCount; i++){
      for(int j=0;j<node;j++){
        if(i%node==j){
          try {
            Address server1 = (Address) Network.getAddress(Benchmark.getServerId(j+"-"+i));
            account = (IBankAccount)LocateRegistry.getRegistry(server1.inetAddress.getHostAddress(), server1.port).lookup(j+"-"+i);
            account.rLock();
            balance+=account.checkBalance();
            account.rUnlock();
          } catch (RemoteException e) {
            e.printStackTrace();
          } catch (NotBoundException e) {
            e.printStackTrace();
          } catch (InterruptedException e) {
View Full Code Here


    try {
      UnicastRemoteObject.unexportObject(this, true);
    } catch (Exception e) {
      Logger.sysout("RMI unexporting");
    }
    IBankAccount stub = (IBankAccount) UnicastRemoteObject.exportObject(this, 0);

    // Bind the remote object's stub in the registry
    Registry registry = LocateRegistry.getRegistry(Network.getInstance().getPort());
    registry.rebind(this.id, stub);
    }
View Full Code Here

    ChronosScheduler.endSegment(Priorities.TASK_CLEANUP.getNativeId());
  }
 
  public static long getTotalBalance(String subAccountNum1, String subAccountNum2) {
    IBankAccount subAccount1 = null;
    IBankAccount subAccount2 = null;
    Address server1 = null, server2 = null;
    try {
      while(true){
        boolean locked1 = false;
        try {
          server1 = (Address) Network.getAddress(Benchmark.getServerId(subAccountNum1));
          subAccount1 = (IBankAccount)LocateRegistry.getRegistry(server1.inetAddress.getHostAddress(), server1.port).lookup(subAccountNum1);
          Network.linkDelay(true, server1);
          subAccount1.rLock();
          locked1 = true;
          server2 = (Address) Network.getAddress(Benchmark.getServerId(subAccountNum2));
          subAccount2 = (IBankAccount)LocateRegistry.getRegistry(server2.inetAddress.getHostAddress(), server2.port).lookup(subAccountNum2);
          Network.linkDelay(true, server2);
          subAccount2.rLock();
          break;
        } catch (InterruptedException e) {
          if(locked1){
            Network.linkDelay(true, server1);
            subAccount1.rUnlock();
          }
        }
      }
     
      Logger.debug("In");
      long balance = 0;
     
      for(int i=0; i<Benchmark.calls; i++){
        Network.linkDelay(true, server1);
        subAccount1.checkBalance();
      }
     
      edu.vt.rt.hyflow.benchmark.Benchmark.processingDelay();
     
      for(int i=0; i<Benchmark.calls; i++){
        Network.linkDelay(true, server2);
        balance += subAccount2.checkBalance();
      }
      Logger.debug("Out");
     
      return balance;
    } catch (AccessException e) {
      e.printStackTrace();
    } catch (RemoteException e) {
      e.printStackTrace();
    } catch (NotBoundException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally{
      if(subAccount1!=null)
        try {
          Network.linkDelay(true, server1);
          subAccount1.rUnlock();
        } catch (RemoteException e) {
          e.printStackTrace();
        }
      if(subAccount2!=null)
        try {
          Network.linkDelay(true, server2);
          subAccount2.rUnlock();
        } catch (RemoteException e) {
          e.printStackTrace();
        }
    }
    return Long.MIN_VALUE;
View Full Code Here

    }
    return Long.MIN_VALUE;
  }
 
  public static long getTotalBalance(Timespec deadline, Timespec period_ts, String[] lockedAccounts, String subAccountNum1, String subAccountNum2) {
    IBankAccount subAccount1 = null;
    IBankAccount subAccount2  = null;
    Address server1 = null, server2 = null;
    //Timespec currenttime = new Timespec();
    char num1 = subAccountNum1.split("-")[1].charAt(0);
    char num2 = subAccountNum2.split("-")[1].charAt(0);
    boolean locked1 = false;
    //boolean locked2 = false;
    String strAccount1, strAccount2;

    if((int)num1 > (int)num2) {
      strAccount1 = subAccountNum2;
      strAccount2 = subAccountNum1;
    } else {
      strAccount1 = subAccountNum1;
      strAccount2 = subAccountNum2;
    }

    try {

      try {
        server1 = (Address) Network.getAddress(Benchmark.getServerId(strAccount1));
        subAccount1 = (IBankAccount)LocateRegistry.getRegistry(server1.inetAddress.getHostAddress(), server1.port).lookup(strAccount1);
        Network.linkDelay(true, server1);
        subAccount1.rLock(deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
        locked1 = true;
        lockedAccounts[0] = strAccount1;
        server2 = (Address) Network.getAddress(Benchmark.getServerId(strAccount2));
        subAccount2 = (IBankAccount)LocateRegistry.getRegistry(server2.inetAddress.getHostAddress(), server2.port).lookup(strAccount2);
        Network.linkDelay(true, server2);
        subAccount2.rLock(deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
        lockedAccounts[1] = strAccount2;
      } catch (InterruptedException e) {
        System.out.println("IE-1");
        if(locked1){
          Network.linkDelay(true, server1);
          subAccount1.rUnlock();
          lockedAccounts[0] = null;
        }
        return Long.MIN_VALUE;
      }catch (NotBoundException e) {
        if(locked1){
          Network.linkDelay(true, server1);
          subAccount1.rUnlock();
          lockedAccounts[0] = null;
        }
        return Long.MIN_VALUE;
      }

     
      Logger.debug("In");
      long balance = 0;
      if(subAccount1 == null) {
        System.out.println("Ac1Null");
        if (subAccount2 == null) {
          System.out.println("Ac2Null");
          return Long.MIN_VALUE;
        }
        return Long.MIN_VALUE;
      }
      if (subAccount2 == null) {
        System.out.println("Ac2Null");
        return Long.MIN_VALUE;
      }
     
      for(int i=0; i<Benchmark.calls; i++){
        Network.linkDelay(true, server1);
        subAccount1.checkBalance(deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
      }
     
      edu.vt.rt.hyflow.benchmark.Benchmark.processingDelay();
     
      for(int i=0; i<Benchmark.calls; i++){
        Network.linkDelay(true, server2);
        balance += subAccount2.checkBalance(deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
      }

      Logger.debug("Out");
      //Logger.fetal("Succeeded [" + subAccountNum1 + ", " +subAccountNum2 + "]");
      return balance;
    } catch (AccessException e) {
      System.out.println("AE2"); //e.printStackTrace();
    } catch (RemoteException e) {
      System.out.println("RE2"); //e.printStackTrace();
    } catch (NullPointerException e) {
      System.out.println("NPE2"); //e.printStackTrace();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally{
      if(subAccount1!=null)
        try {
          Network.linkDelay(true, server1);
          subAccount1.rUnlock();
        } catch (RemoteException e) {
          e.printStackTrace();
        }

      if(subAccount2!=null)
        try {
          Network.linkDelay(true, server2);
          subAccount2.rUnlock();
        } catch (RemoteException e) {
          e.printStackTrace();
        }
    }   
    return Long.MIN_VALUE;
View Full Code Here

   
    /**************************************/
  }
 
  public static boolean transfer(String subAccountNum1, String subAccountNum2, int amount) {
    IBankAccount account1 = null;
    IBankAccount account2 = null;
    Address server1 = null, server2 = null;
    try {
      while(true){
        boolean locked1 = false;
        try {
          server1 = (Address) Network.getAddress(Benchmark.getServerId(subAccountNum1));
          account1 = (IBankAccount)LocateRegistry.getRegistry(server1.inetAddress.getHostAddress(), server1.port).lookup(subAccountNum1);
          Network.linkDelay(true, server1);
          account1.wLock();
          locked1 = true;
          server2 = (Address) Network.getAddress(Benchmark.getServerId(subAccountNum2));
          account2 = (IBankAccount)LocateRegistry.getRegistry(server2.inetAddress.getHostAddress(), server2.port).lookup(subAccountNum2);
          Network.linkDelay(true, server2);
          account2.wLock();
          break;
        } catch (InterruptedException e) {
          if(locked1){
            Network.linkDelay(true, server1);
            account1.wUnlock();
          }
        }
      }
     
      Logger.debug("In");
      for(int i=0; i<Benchmark.calls; i++){
        Network.linkDelay(true, server1);
        account1.withdraw(amount);
      }
     
      edu.vt.rt.hyflow.benchmark.Benchmark.processingDelay();
     
      for(int i=0; i<Benchmark.calls; i++){
        Network.linkDelay(true, server2);
        account2.deposit(amount);
      }
      Logger.debug("Out");
     
      return true;
    } catch (AccessException e) {
      e.printStackTrace();
    } catch (RemoteException e) {
      e.printStackTrace();
    } catch (NotBoundException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally{
      if(account1!=null)
        try {
          Network.linkDelay(true, server1);
          account1.wUnlock();
        } catch (RemoteException e) {
          e.printStackTrace();
        }
      if(account2!=null)
        try {
          Network.linkDelay(true, server2);
          account2.wUnlock();
        } catch (RemoteException e) {
          e.printStackTrace();
        }
    }
    return false;
View Full Code Here

    return false;
  }

  public static boolean transfer(Timespec deadline, Timespec period_ts, String[] lockedAccounts, String subAccountNum1, String subAccountNum2, int amount) {

    IBankAccount subAccount1 = null;
    IBankAccount subAccount2  = null;
    Address server1 = null, server2 = null;
    Timespec currenttime = new Timespec();
    char num1 = subAccountNum1.split("-")[1].charAt(0);
    char num2 = subAccountNum2.split("-")[1].charAt(0);
    boolean locked1 = false;
    boolean locked2 = false;
    String strAccount1, strAccount2;

    if((int)num1 > (int)num2) {
      strAccount1 = subAccountNum2;
      strAccount2 = subAccountNum1;
    } else {
      strAccount1 = subAccountNum1;
      strAccount2 = subAccountNum2;
    }
   
    try {

      try {
        server1 = (Address) Network.getAddress(Benchmark.getServerId(strAccount1));
        subAccount1 = (IBankAccount)LocateRegistry.getRegistry(server1.inetAddress.getHostAddress(), server1.port).lookup(subAccountNum1);
        Network.linkDelay(true, server1);
        subAccount1.wLock(deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
        locked1 = true;
        lockedAccounts[0] = strAccount1;
        server2 = (Address) Network.getAddress(Benchmark.getServerId(strAccount2));
        subAccount2 = (IBankAccount)LocateRegistry.getRegistry(server2.inetAddress.getHostAddress(), server2.port).lookup(strAccount2);
        Network.linkDelay(true, server2);
        subAccount2.wLock(deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
        lockedAccounts[1] = strAccount2;
      } catch (InterruptedException e) {
        if(locked1){
          Network.linkDelay(true, server1);
          subAccount1.wUnlock();
          lockedAccounts[0] = null;
        }
        return false;

      }catch (NotBoundException e) {
        if(locked1){
          Network.linkDelay(true, server1);
          subAccount1.wUnlock();
          lockedAccounts[0] = null;
        }
        return false;
      }

      Logger.debug("In");
      if(subAccount1 == null) {
        System.out.println("Ac1Null");
        return false;
      }
      else if (subAccount2 == null) {
        System.out.println("Ac2Null");
        return false;
      }
     
      if((int)num1 > (int)num2) {
        for(int i=0; i<Benchmark.calls; i++){
          Network.linkDelay(true, server1);
          subAccount2.deposit(amount, deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
        }
       
        edu.vt.rt.hyflow.benchmark.Benchmark.processingDelay();
       
        for(int i=0; i<Benchmark.calls; i++){
          Network.linkDelay(true, server2);
          subAccount1.withdraw(amount, deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
        }
      } else {
        for(int i=0; i<Benchmark.calls; i++){
          Network.linkDelay(true, server1);
          subAccount1.deposit(amount, deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
        }
       
        edu.vt.rt.hyflow.benchmark.Benchmark.processingDelay();
       
        for(int i=0; i<Benchmark.calls; i++){
          Network.linkDelay(true, server2);
          subAccount2.withdraw(amount, deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
        }       
      }

      Logger.debug("Out");
      //Logger.fetal("Succeeded [" + subAccountNum1 + ", " +subAccountNum2 + "]");
      return true;
    } catch (AccessException e) {
      e.printStackTrace();
    } catch (RemoteException e) {
      e.printStackTrace();
    } catch (NullPointerException e) {
      System.out.println("NPE2"); //e.printStackTrace();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally{
      if(subAccount1!=null)
        try {
          Network.linkDelay(true, server1);
          subAccount1.wUnlock();
        } catch (RemoteException e) {
          e.printStackTrace();
        }

      if(subAccount2!=null)
        try {
          Network.linkDelay(true, server2);
          subAccount2.wUnlock();
        } catch (RemoteException e) {
          e.printStackTrace();
        }
    }   
   
View Full Code Here

TOP

Related Classes of edu.vt.rt.hyflow.benchmark.realtimermi.bank.rw.IBankAccount

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.