Package aleph.dir

Examples of aleph.dir.DirectoryManager


 
  public void createQueue() {
    new _Node(FRONT, -1)// create the front node
    new _Node(END, -1);    // create the end node
   
    DirectoryManager locator = HyFlow.getLocator();
    _Node front = (_Node)locator.open(FRONT);
    _Node end = (_Node)locator.open(FRONT);
    front.setNext(END);
    end.setNext(FRONT);
  }
View Full Code Here


    end.setNext(FRONT);
  }

  @Atomic
  public void add(Integer value){
    DirectoryManager locator = HyFlow.getLocator();
    String lastId = null, lastNextId= null;
    _Node end = (_Node)locator.open(END);
    lastId = end.getNext();
    _Node last = (_Node)locator.open(lastId);
    lastNextId = last.getNext();

    String newNodeId =  Network.getInstance().getID() + "-" + Math.random()// generate random id
    _Node newNode = new _Node(newNodeId, value);
    last.setNext(newNodeId);
View Full Code Here

    end.setNext(newNodeId);
  }

  @Atomic
  public Integer delete(){
    DirectoryManager locator = HyFlow.getLocator();
    _Node front = (_Node)locator.open(FRONT);
    _Node deleteNode;
    String oldNext = front.getNext();
    if(oldNext == END){
      System.out.println("Queue is Empty!!");
      return null;
    }   
    else{
      deleteNode = (_Node)locator.open(oldNext);
      String newNext = deleteNode.getNext();
      front.setNext(newNext);
      String id = (String) deleteNode.getId();
      Integer value  = deleteNode.getValue();
      locator.delete(deleteNode);
      System.out.println("<" + id + "> " + value + "  DELETED....");
      return value;
    }
  }
View Full Code Here

    new _Node(HEAD, -1)// create the head node
  }

  @Atomic
  public void add(Integer 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()){
        prev = next;
        next = node.getRightChild();
        right = true;
      }else{
        prev = next;
        next = node.getLeftChild();
        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

      prevNode.setLeftChild(newNodeId);
  }

  @Atomic
  public boolean delete(Integer 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()){
        prev = next;
        next = node.getRightChild();
        right = true;
      }else if(value < node.getValue()){
        prev = next;
        next = node.getLeftChild();
        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()==null){
          replacement = deletedNode.getRightChild();
        }else if(deletedNode.getRightChild()==null){
          replacement = deletedNode.getLeftChild();
        }else// get left most in right tree
          String next2 = deletedNode.getRightChild();
          _Node currNode2 = null;
          _Node prevNode2 = null;
          do{
            prevNode2 = currNode2;
            replacement = next2;
           
            currNode2 = (_Node)locator.open(next2, "r");
            next2 = currNode2.getLeftChild();
          }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(null);
          }
        }
        if(right)
          prevNode.setRightChild(replacement);
        else
          prevNode.setLeftChild(replacement);
        locator.delete(deletedNode);
        return true;
      }
    }while(next!=null);
    return false;
  }
View Full Code Here

    }
  }

  @Atomic
  public boolean find(Integer value){
    DirectoryManager locator = HyFlow.getLocator();
    String next = FRONT;
    do// find the last node
      _Node node = (_Node)locator.open(next, "r");
      if(value.equals(node.getValue())){
        System.out.println("Found!");
        return true;
      }
      next = node.getNext();
View Full Code Here

    return false;
  }
 
  @Atomic
  public int sum(){
    DirectoryManager locator = HyFlow.getLocator();
    String next = FRONT;
    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();
      sum += node.getValue();
    }while(next!=END);
    return sum;
  }
View Full Code Here

    return (Integer)ContextDelegator.onReadAccess(this, amount, amount__ADDRESS__, __transactionContext__);
 
 
  public static long totalBalance(String accountNum1, String accountNum2, Context context){
    try{
      DirectoryManager locator = HyFlow.getLocator();
      BankAccount account1 = (BankAccount) locator.open(accountNum1);
      ContextDelegator.beforeReadAccess(account1, 0, context);
      BankAccount account2 = (BankAccount) locator.open(accountNum2);
     
      long balance = 0;
      for(int i=0; i<Benchmark.calls; i++)
        balance += account1.checkBalance(context);
     
View Full Code Here

    return false;
  }

  @Atomic
  public boolean find(Integer value){
    DirectoryManager locator = HyFlow.getLocator();
    String next = HEAD;
    do
      _Node node = (_Node)locator.open(next, "r");
      if(value > node.getValue()){
        next = node.getRightChild();
      }else if(value < node.getValue()){
        next = node.getLeftChild();
      }else{
View Full Code Here

    return false;
  }
 
  @Atomic
  public int sum(){
    DirectoryManager locator = HyFlow.getLocator();
    return sum((_Node)locator.open(HEAD)) + 1;
  }
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.