Package aleph.dir

Examples of aleph.dir.DirectoryManager


    }
    throw new TransactionException("Failed to commit the transaction in the defined retries.");
  }
  public boolean delete(Integer value, Context __transactionContext__){
    try{
      DirectoryManager locator = HyFlow.getLocator();
      String next = HEAD;
      String prev = null;
      do// find the last node
        Node node = (Node)locator.open(next, "r");
        if(value.equals(node.getValue(__transactionContext__))){
          Node deletedNode = (Node)locator.open(next)//reopen for write to be deleted
          Node prevNode = (Node)locator.open(prev);    //open previous node for write
          prevNode.setNext(deletedNode.getNext(__transactionContext__), __transactionContext__);
          locator.delete(deletedNode);
          System.out.println("<" + node.getId() + "> " + node.getValue(__transactionContext__) + "  DELETED....");
          return true;
        }
        prev = next;
        next = node.getNext(__transactionContext__);
View Full Code Here


  @Remote
  public void borrow(List<String> accountNums, int branching, boolean initiator, int amount) {
    if(!initiator)
      withdraw(amount)// provide the loan request
    DirectoryManager locator = HyFlow.getLocator();
    accountNums = (List<String>)((LinkedList<String>)accountNums).clone();
    for(int i=0; i<branching && !accountNums.isEmpty(); i++){
      _LoanAccount account = (_LoanAccount) locator.open(accountNums.remove(0), "w");
      boolean last = (i==branching-1 || accountNums.isEmpty())// is the last one?
      int loan = last ? amount : (int)(Math.random()*amount);    // randomly have a loan amount from neighbor 
      account.borrow(accountNums, branching, false, loan);    // borrow from others
      deposit(loan)// add the loaned amount to my money
      amount -= loan;
View Full Code Here

    throw new TransactionException("Failed to commit the transaction in the defined retries.");
  }
  public void add(Integer value, Context __transactionContext__){
    try{
//      System.err.println("\nadd " + value);
      DirectoryManager locator = HyFlow.getLocator();
      String next = HEAD;
      String prev = null;
      boolean right = true;
      do
        Node node = (Node)locator.open(next, "r");
        if(value >= node.getValue(__transactionContext__)){
          prev = next;
          next = node.getRightChild(__transactionContext__);
          right = true;
        }else{
          prev = next;
          next = node.getLeftChild(__transactionContext__);
          right = false;
        }
      }while(next!=null);
     
      Node prevNode = (Node)locator.open(prev);    //open previous node for write
     
      String newNodeId =  Network.getInstance().getID() + "-" + Math.random()// generate random id
      new Node(newNodeId, value)// create the node
     
      if(right)
View Full Code Here

    ((_LoanAccount)HyFlow.getLocator().open(id, "w")).borrow(accountNums, BRANCHING, true, amount);
  }
 
  @Remote
  public int sum(List<String> accountNums, int branching) {
    DirectoryManager locator = HyFlow.getLocator();
    int sum = checkBalance();
    accountNums = (List<String>)((LinkedList<String>)accountNums).clone();
    for(int i=0; i<branching && !accountNums.isEmpty(); i++){
      _LoanAccount account = (_LoanAccount) locator.open(accountNums.remove(0), "r");
      sum += account.sum(accountNums, branching);
    }
    return sum;
  }
View Full Code Here

    throw new TransactionException("Failed to commit the transaction in the defined retries.");
  }
  public boolean delete(Integer value, Context __transactionContext__){
    try{
//      System.err.println("\ndelete " + value);
      DirectoryManager locator = HyFlow.getLocator();
      String next = HEAD;
      String prev = null;
      boolean right = true;
      do{
        Node node = (Node)locator.open(next, "r");
        if(value > node.getValue(__transactionContext__)){
          prev = next;
          next = node.getRightChild(__transactionContext__);
          right = true;
        }else if(value < node.getValue(__transactionContext__)){
          prev = next;
          next = node.getLeftChild(__transactionContext__);
          right = false;
        }else{
          Node prevNode = (Node)locator.open(prev);    //open previous node for write
          Node deletedNode = (Node)locator.open(next)//reopen for write to be deleted
          String replacement;
          if(deletedNode.getLeftChild(__transactionContext__)==null){
  //          System.err.println("replace with right child");
            replacement = deletedNode.getRightChild(__transactionContext__);
          }else if(deletedNode.getRightChild(__transactionContext__)==null){
  //          System.err.println("replace with left child");
            replacement = deletedNode.getLeftChild(__transactionContext__);
          }else// get left most in right tree
  //          System.err.println("replace with left most in right tree");
            String next2 = deletedNode.getRightChild(__transactionContext__);
            Node currNode2 = null;
            Node prevNode2 = null;
            do{
              prevNode2 = currNode2;
              replacement = next2;
             
              currNode2 = (Node)locator.open(next2, "r");
              next2 = currNode2.getLeftChild(__transactionContext__);
            }while(next2!=null);
            if(prevNode2!=null){  // disconnect replacement node from its parent
              Node prevNode2w = (Node)locator.open(prevNode2.getId())//open previous node for write
              prevNode2w.setLeftChild(currNode2.getRightChild(__transactionContext__), __transactionContext__);
            }
            Node currNode2w = (Node)locator.open(replacement)//replace
            currNode2w.setLeftChild(node.getLeftChild(__transactionContext__), __transactionContext__);
            if(!replacement.equals(node.getRightChild(__transactionContext__)))
              currNode2w.setRightChild(node.getRightChild(__transactionContext__), __transactionContext__);
          }
          if(right)
            prevNode.setRightChild(replacement, __transactionContext__);
          else
            prevNode.setLeftChild(replacement, __transactionContext__);
          locator.delete(deletedNode);
          return true;
        }
      }while(next!=null);
  //    System.err.println("Nothing to Delete....");
      return false;
View Full Code Here

    }
    throw new TransactionException("Failed to commit the transaction in the defined retries.");
  }
  public boolean find(Integer value, Context __transactionContext__){
    try{
      DirectoryManager locator = HyFlow.getLocator();
      String next = HEAD;
      do// find the last node
        Node node = (Node)locator.open(next, "r");
        if(value.equals(node.getValue(__transactionContext__))){
          System.out.println("Found!");
          return true;
        }
        next = node.getNext(__transactionContext__);
View Full Code Here

    }
    throw new TransactionException("Failed to commit the transaction in the defined retries.");
  }
  public int sum(Context __transactionContext__){
    try{
      DirectoryManager locator = HyFlow.getLocator();
      String next = HEAD;
      int sum = 1// to avoid -1 value of head sentential node
      do// find the last node
        Node node = (Node)locator.open(next, "r");
        next = node.getNext(__transactionContext__);
        sum += node.getValue(__transactionContext__);
      }while(next!=null);
      return sum;
    } finally{
View Full Code Here

    }
    throw new TransactionException("Failed to commit the transaction in the defined retries.");
  }
  public boolean find(Integer value, Context __transactionContext__){
    try{
      DirectoryManager locator = HyFlow.getLocator();
      String next = HEAD;
      do
        Node node = (Node)locator.open(next, "r");
        if(value > node.getValue(__transactionContext__)){
          next = node.getRightChild(__transactionContext__);
        }else if(value < node.getValue(__transactionContext__)){
          next = node.getLeftChild(__transactionContext__);
        }else{
View Full Code Here

    }
    throw new TransactionException("Failed to commit the transaction in the defined retries.");
  }
  public int sum(Context __transactionContext__){
    try{
      DirectoryManager locator = HyFlow.getLocator();
      return sum((Node)locator.open(HEAD), __transactionContext__) + 1;
    } finally{
      try {
        edu.vt.rt.hyflow.benchmark.Benchmark.processingDelay();
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
View Full Code Here

    }
  }
 
  private int sum(Node node, Context __transactionContext__){
    int sum = node.getValue(__transactionContext__);
    DirectoryManager locator = HyFlow.getLocator();
    if(node.getLeftChild(__transactionContext__)!=null)
      sum += sum((Node)locator.open(node.getLeftChild(__transactionContext__)), __transactionContext__);
    if(node.getRightChild(__transactionContext__)!=null)
      sum += sum((Node)locator.open(node.getRightChild(__transactionContext__)), __transactionContext__);
    return sum;
  }
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.