Package aleph.dir

Examples of aleph.dir.DirectoryManager


      deposit(loan)// add the loaned amount to my money
      amount -= loan;
    }
  }
  public static void borrow(String id, List<String> accountNums, int amount){
    DirectoryManager locator = HyFlow.getLocator();
    Map<String, LoanAccount> opened = new HashMap<String, LoanAccount>();
    while(true){
      try {
        opened.clear();
        opened.put(id, (LoanAccount)locator.open(id, "w"));
        for(String accNum : accountNums)
          opened.put(accNum, (LoanAccount)locator.open(accNum, "w"));
        break;
      } catch (TimeoutException e) {
        Logger.debug("Timeout!");
        for(LoanAccount acc : opened.values()){
          locator.release(acc);
          Logger.debug("Release " + acc);
        }
      }
    }
   
    opened.get(id).borrow(accountNums, BRANCHING, true, amount, opened);
    try {
      edu.vt.rt.hyflow.benchmark.Benchmark.processingDelay();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   
    for(LoanAccount acc : opened.values()){
      locator.release(acc);
      Logger.debug("Release " + acc);
    }
  }
View Full Code Here


    amount = amount - dollars;
    return amount >= 0;
  }

  public static long getTotalBalance(String subAccountNum1, String subAccountNum2) {
    DirectoryManager locator = HyFlow.getLocator();
    BankAccount subAccount1 = null;
    BankAccount subAccount2 = null;
    while(true){
      boolean locked = false;
      try {
        subAccount1 = (BankAccount) locator.open(subAccountNum1, "r");
        locked = true;
        Logger.debug("Lock " + subAccountNum1);
        subAccount2 = (BankAccount) locator.open(subAccountNum2, "r");
        Logger.debug("Lock " + subAccountNum2);
        break;
      } catch (TimeoutException e) {
        Logger.debug("Timeout!");
        if(locked){
          locator.release(subAccount1);
          Logger.debug("Release " + subAccountNum1);
        }
      }
    }
    try {
      long balance = 0;
     
      for(int i=0; i<Benchmark.calls; i++)
        balance += subAccount1.checkBalance();
     
      edu.vt.rt.hyflow.benchmark.Benchmark.processingDelay();
     
      for(int i=0; i<Benchmark.calls; i++)
        balance += subAccount2.checkBalance();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally{   
      locator.release(subAccount1);
      Logger.debug("Release " + subAccountNum1);
      locator.release(subAccount2);
      Logger.debug("Release " + subAccountNum2);
    }
    return 0;
  }
View Full Code Here

      sum += account.sum(accountNums, branching, opened);
    }
    return sum;
  }
  public static void sum(String id, List<String> accountNums){
    DirectoryManager locator = HyFlow.getLocator();
    Map<String, LoanAccount> opened = new HashMap<String, LoanAccount>();
    while(true){
      try {
        opened.clear();
        opened.put(id, (LoanAccount)locator.open(id, "r"));
        for(String accNum : accountNums)
          opened.put(accNum, (LoanAccount)locator.open(accNum, "r"));
        break;
      } catch (TimeoutException e) {
        Logger.debug("Timeout!");
        for(LoanAccount acc : opened.values()){
          locator.release(acc);
          Logger.debug("Release " + acc);
        }
      }
    }

    opened.get(id).sum(accountNums, BRANCHING, opened);
    try {
      edu.vt.rt.hyflow.benchmark.Benchmark.processingDelay();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   
    for(LoanAccount acc : opened.values()){
      locator.release(acc);
      Logger.debug("Release " + acc);
    }
  }
View Full Code Here

  }
 
  public static boolean transfer(String accountNum1, String accountNum2, int amount) {
    BankAccount account1 = null;
    BankAccount account2 = null;   
    DirectoryManager locator = HyFlow.getLocator();
    while(true){
      boolean locked = false;
      try {
        account1 = (BankAccount) locator.open(accountNum1);
        locked = true;
        Logger.debug("Lock " + accountNum1);
        account2 = (BankAccount) locator.open(accountNum2);
        Logger.debug("Lock " + accountNum2);
        break;
      } catch (TimeoutException e) {
        Logger.debug("Timeout");
        if(locked){
          locator.release(account1);
          Logger.debug("Release " + accountNum1);
        }
      }
    }
    try {
      for(int i=0; i<Benchmark.calls; i++)
        account1.withdraw(amount);
     
      edu.vt.rt.hyflow.benchmark.Benchmark.processingDelay();
     
      try {
        for(int i=0; i<Benchmark.calls; i++)
          account2.deposit(amount);
      }catch(TransactionException e){
        throw e;
      } catch (Throwable e) {
        e.printStackTrace();
      }
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally{   
      locator.release(account1);
      Logger.debug("Release " + accountNum1);
      locator.release(account2);
      Logger.debug("Release " + accountNum2);
    }
   
    return true;
  }
View Full Code Here

  }

  @Atomic
  private long sumAssests(int node){
    long balance = 0;
    DirectoryManager locator = HyFlow.getLocator();
    for(int i=0; i<localObjectsCount; i++){
      for(int j=0;j<node;j++){
        if(i%node==j){
          try {
            balance+=((LoanAccount) locator.open(j + "-" + i,"r")).checkBalance();
          } catch (Throwable e) {
            e.printStackTrace();
         
        }
      }
View Full Code Here

    return id;
  }

  public DistributedImmutableList<E> remove(E value) {
    Stack<DistributedImmutableList<E>> stack = new Stack<DistributedImmutableList<E>>();
    DirectoryManager locator = HyFlow.getLocator();
    for (DistributedImmutableList<E> iter = this; ; iter = (DistributedImmutableList<E>) locator.open(iter.tailID, "r")) {
      if (iter.value.equals(value)) {
        String next = iter.tailID;
        while (!stack.empty()) {
          DistributedImmutableList<E> deletedNode = stack.pop();
          iter = new DistributedImmutableList<E>(deletedNode.value, next);
          next = (String) iter.getId();
          locator.delete(deletedNode);
        }
        return iter;
      }
      else if (iter.tailID == null) {  //Item isn't in list, no changes made
        return this;
View Full Code Here

    int comparison = this.data.compareTo(item);
    if (comparison < 0) {  //Go right
      if (this.rightID == null) {     
        return new DistributedImmutableBST<E>(this.data, this.leftID, (String) new DistributedImmutableBST<E>(item).getId());
      }
      DirectoryManager locator = HyFlow.getLocator();
      final DistributedImmutableBST<E> right = (DistributedImmutableBST<E>) locator.open(this.rightID, "r");
      final DistributedImmutableBST<E> newRight = right.add(item);
      if (right.equals(newRight)) {
        return this;
      }
      return new DistributedImmutableBST<E>(this.data, this.leftID, (String) newRight.getId());
    }
    else if (comparison > 0) {  //Go left
      if (this.leftID == null) {
        return new DistributedImmutableBST<E>(this.data, (String) new DistributedImmutableBST<E>(item).getId(), this.rightID);
      }
      DirectoryManager locator = HyFlow.getLocator();
      final DistributedImmutableBST<E> left = (DistributedImmutableBST<E>) locator.open(this.leftID, "r");
      final DistributedImmutableBST<E> newLeft = left.add(item);
      if (left.equals(newLeft)) {
        return this;
      }
      return new DistributedImmutableBST<E>(this.data, (String) newLeft.getId(), this.rightID);
View Full Code Here

    int comparison = this.data.compareTo(value);
    if (comparison < 0) {
      if (this.rightID == null) {
        return false;
      }
      DirectoryManager locator = HyFlow.getLocator();
      return ((DistributedImmutableBST<E>) locator.open(this.rightID, "r")).contains(value);
    }
    else if (comparison > 0) {
      if (this.leftID == null) {
        return false;
      }
      DirectoryManager locator = HyFlow.getLocator();
      return ((DistributedImmutableBST<E>) locator.open(this.leftID, "r")).contains(value);
    }
    else {
      return true;
    }
  }
View Full Code Here

  public Object getId() {
    return id;
  }

  public DistributedImmutableBST<E> remove(E value) {
    DirectoryManager locator = HyFlow.getLocator();
    int comparison = this.data.compareTo(value);
    if (comparison < 0) {
      if (this.rightID == null) {
        return this;
      }
      final DistributedImmutableBST<E> right = (DistributedImmutableBST<E>) locator.open(this.rightID, "r");     
      final DistributedImmutableBST<E> newRight = right.remove(value);
      if (right.equals(newRight)) {
        return this;
      }
      return new DistributedImmutableBST<E>(this.data, this.leftID, (newRight == null) ? null : (String) newRight.getId());
    }
    else if (comparison > 0) {
      if (this.leftID == null) {
        return this;
      }
      final DistributedImmutableBST<E> left = (DistributedImmutableBST<E>) locator.open(this.leftID, "r");     
      final DistributedImmutableBST<E> newLeft = left.remove(value);
      if (left.equals(newLeft)) {
        return this;
      }
      return new DistributedImmutableBST<E>(this.data, (newLeft == null) ? null : (String) newLeft.getId(), this.rightID);
    }
    else {
      locator.delete(this);
      if (this.leftID == null && this.rightID == null) {  //0 Children
        return null;
      }
      if (this.leftID == null || this.rightID == null) {  //1 Child
        return (DistributedImmutableBST<E>)((this.leftID != null) ? locator.open(this.leftID, "r") : locator.open(this.rightID, "r"));
      }
      else //2 Children
        //Find Right Child's left most node
        Stack<DistributedImmutableBST<E>> stack = new Stack<DistributedImmutableBST<E>>();
        DistributedImmutableBST<E> iter = (DistributedImmutableBST<E>) locator.open(this.rightID, "r");
        while (iter.leftID != null) {
          stack.push(iter);
          iter = (DistributedImmutableBST<E>) locator.open(iter.leftID, "r");
        }
        E newValue = iter.data;
        iter = (DistributedImmutableBST<E>) locator.open(iter.rightID, "r")//Don't lose left most child's right nodes
        while (!stack.empty()) {
          DistributedImmutableBST<E> node = stack.pop();
          iter = new DistributedImmutableBST<E>(node.data, (String) iter.getId(), node.rightID);
          locator.delete(node);
        }
        //Remove node by replacing it's value
        return new DistributedImmutableBST<E>(newValue, this.leftID, (String) iter.getId());
      }
    }
View Full Code Here

   * @see edu.vt.rt.datastructures.lang.DistributedSet#add(java.io.Serializable)
   */
  @Atomic
  @Override
  public boolean add(E value) {
    DirectoryManager locator = HyFlow.getLocator();
    IDContainer<ImmutableList<E>> container = (IDContainer<ImmutableList<E>>) locator.open(containerID, "r");
    final ImmutableList<E> list = container.getItem();
    if (list == null) {  //List is empty
      container.setItem(new ImmutableList<E>(value));
      return true;
    }
    final ImmutableList<E> newList = list.add(value);
    if (newList == list) {
      return false;
    }
    container = (IDContainer<ImmutableList<E>>) locator.open(containerID, "w");
    container.setItem(newList);
    return true;
  }
View Full Code Here

TOP

Related Classes of aleph.dir.DirectoryManager

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.