Package aleph.dir

Examples of aleph.dir.DirectoryManager


        if(acquiredObjects.isEmpty()){
          Logger.debug(txnId + ": Empty Writeset.");
          return true;
        }
        Logger.debug("Backoff acquired objects :" + acquiredObjects.size());
        DirectoryManager locator = HyFlow.getLocator();
        for(AbstractDistinguishable distinguishable:acquiredObjects){
          if(incrementVersion)
            ((AbstractLoggableObject)distinguishable).__incVersion();
          ((AbstractLoggableObject)distinguishable).__release();
          locator.release(distinguishable);
          Logger.debug("Release :" + distinguishable.getId());
        }
      } finally {
        if(clear){
          Logger.debug(txnId + ": Remove from registery");
View Full Code Here


      int index = mask(hash, shift);
      String node = array[index];
      if (node == null) {
        return notFound;
      }
      DirectoryManager locator = HyFlow.getLocator();
      return ((DistributedImmutableHashMap) locator.open(node, "r")).find(shift+5, hash, key, notFound);
    }
View Full Code Here

      return ((DistributedImmutableHashMap) locator.open(node, "r")).find(shift+5, hash, key, notFound);
    }

    @Override
    public DistributedImmutableHashMap put(int shift, int hash, Object key, Object value, Box addedLeaf) {
      DirectoryManager locator = HyFlow.getLocator();
      int index = mask(hash, shift);
      String node = array[index];
      if (node == null) {  //If the index is currently empty
        locator.delete(this);
        return new ArrayNode(count+1, cloneAndSet(array, index, (String) (BitmapIndexedNode.EMPTY.put(shift+5, hash, key, value, addedLeaf)).getId()));
      }
      //Else add it later on in the tree
      final DistributedImmutableHashMap newNode = ((DistributedImmutableHashMap) locator.open(node, "r")).put(shift+5, hash, key, value, addedLeaf);
      if (newNode == null) {
        return this;
      }
      locator.delete(this);
      return new ArrayNode(count, cloneAndSet(array, index, (String) newNode.getId()));
    }
View Full Code Here

      int index = mask(hash, shift);
      String node = array[index];
      if (node == null) {
        return this;
      }
      DirectoryManager locator = HyFlow.getLocator();
      final DistributedImmutableHashMap n = ((DistributedImmutableHashMap) locator.open(node, "r")).remove(shift+5, hash, key, removedLeaf);
      if (n == null) {
        locator.delete(this);
        if (count <= 8) { //Shrink back to BitmapIndexedNode
          return pack(index);
        }
        return new ArrayNode(count-1, cloneAndSet(array, index, null));
      }
      final String nID = (String) n.getId();
      if (node.equals(nID)) {
        return this;
      }
      locator.delete(this);
      return new ArrayNode(count, cloneAndSet(array, index, nID));
    }
View Full Code Here

      }
      int index = index(bit);
      Object keyOrNull = array[2*index];
      Object valOrNode = array[2*index+1];
      if (keyOrNull == null) {  //index is another INode
        DirectoryManager locator = HyFlow.getLocator();
        return ((DistributedImmutableHashMap) locator.open((String)valOrNode, "r")).find(shift+5, hash, key, notFound);
      }
      if (key.equals(keyOrNull)) {
        return valOrNode;
      }
      return notFound;
View Full Code Here

    @Override
    public DistributedImmutableHashMap put(int shift, int hash, Object key, Object value, Box addedLeaf) {
      int bit = bitpos(hash, shift);
      int index = index(bit);
      DirectoryManager locator = HyFlow.getLocator();
      if ((bitmap & bit) != 0) {  //We check to see if the index of the hashCode in the bitmap is set
        Object keyOrNull = array[2*index];
        Object valOrNode = array[2*index+1];
        if (keyOrNull == null) {  //If null, then valOrNode is a INode
          final DistributedImmutableHashMap newNode = ((DistributedImmutableHashMap) locator.open((String)valOrNode, "r")).put(shift+5, hash, key, value, addedLeaf);
          final String newNodeID = (String) newNode.getId();
          if(valOrNode.equals(newNodeID)) {
            return this;
          }
          locator.delete(this);
          return new BitmapIndexedNode(bitmap, cloneAndSet(array, 2*index+1, newNodeID));
        }
        if (keyOrNull.equals(key)) {
          if (valOrNode.equals(value)) {  //If we the K-V pair is already in table
            return this;
          }
          //Else update value for key
          addedLeaf.value = valOrNode;  //Update value to traverse back to recursive call
          locator.delete(this);
          return new BitmapIndexedNode(bitmap, cloneAndSet(array, 2*index+1, value));
        }
        //trying to insert a key where a key is already at that index. Need to make a new node and check to see if HashCollisionNode is needed
        locator.delete(this);
        return new BitmapIndexedNode(bitmap, cloneAndSet(array, 2*index, null, 2*index+1, (String)(createNode(shift + 5, keyOrNull, valOrNode, hash, key, value)).getId()));
      }
      else {
        int bitCount = Integer.bitCount(bitmap);
        if (bitCount >= 16) {  //16 bits set means 16 K-V pairs, need to upgrade to ArrayNode
          String[] nodes = new String[32];
          //Find where in the new ArrayNode the BitmapIndexedNode will go
          int jdex = mask(hash, shift);
          nodes[jdex] = (String) (BitmapIndexedNode.EMPTY.put(shift + 5, hash, key, value, addedLeaf)).getId();
          int j = 0;
          for (int i = 0; i < 32; i++) {
            if (((bitmap >>> i) & 1) != 0) {  //Shift to next entry, and check to see if it's set
              if (array[j] == null//Copy over INode ID
                nodes[i] = (String) array[j+1];
              else //Copy over K-V in new BitmapIndexNode
                nodes[i] = (String) (BitmapIndexedNode.EMPTY.put(shift + 5, array[j].hashCode(), array[j], array[j+1], addedLeaf)).getId();
              }
              j += 2;
            }
          }
          locator.delete(this);
          return new ArrayNode(bitCount+1, nodes);
        }
        else {
          //Allocate more room in the array for the new K-V pair
          Object[] newArray = new Object[2*(bitCount+1)];
          System.arraycopy(array, 0, newArray, 0, 2*index);
          newArray[2*index] = key;
          newArray[2*index+1] = value;
          System.arraycopy(array, 2*index, newArray, 2*(index+1), 2*(bitCount-index));
          locator.delete(this);
          return new BitmapIndexedNode(bitmap | bit, newArray)//Update that bitmapindexednode
        }
      }
    }
View Full Code Here

    }

    @Override
    public DistributedImmutableHashMap remove(int shift, int hash, Object key, Box removedLeaf) {
      int bit = bitpos(hash, shift);
      DirectoryManager locator = HyFlow.getLocator();
      if ((bitmap & bit) == 0) {  //If not in map
        return this;
      }
      int index = index(bit);
      Object keyOrNull = array[2*index];
      Object valOrNode = array[2*index+1];
      if (keyOrNull == null) {  //Removing from another INode
        final DistributedImmutableHashMap n = ((DistributedImmutableHashMap) locator.open((String)valOrNode, "r")).remove(shift+5, hash, key, removedLeaf);
        if (n != null) {
          final String nID = (String) n.getId();
          if (valOrNode.equals(nID)) {
            return this;
          }
          locator.delete(this);
          return new BitmapIndexedNode(bitmap, cloneAndSet(array, 2*index+1, nID));
        }
        locator.delete(this);
        if (bitmap == bit) {  //If removing last node
          return null;
        }
        //If index is null but not the last element, shrink the array
        return new BitmapIndexedNode(bitmap ^ bit, removePair(array, index));
      }
      if (keyOrNull.equals(key)) {
        removedLeaf.value = valOrNode;
        locator.delete(this);
        if (bitmap == bit) {  //If removing last node
          return null;
        }
        return new BitmapIndexedNode(bitmap ^ bit, removePair(array, index));
      }
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();
    HashSet<E> set = (HashSet<E>) locator.open(setID, "w");
    return set.add(value);
  }
View Full Code Here

   * @see edu.vt.rt.datastructures.lang.DistributedSet#contains(java.io.Serializable)
   */
  @Atomic
  @Override
  public boolean contains(E value) {
    DirectoryManager locator = HyFlow.getLocator();
    HashSet<E> set = (HashSet<E>) locator.open(setID, "r");
    return set.contains(value);
  }
View Full Code Here

   * @see edu.vt.rt.datastructures.lang.DistributedSet#remove(java.io.Serializable)
   */
  @Atomic
  @Override
  public boolean remove(E value) {
    DirectoryManager locator = HyFlow.getLocator();
    HashSet<E> set = (HashSet<E>) locator.open(setID, "w");
    return set.remove(value);
  }
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.