Пример #1
0
 public int releaseLock(UTF8 src, UTF8 holder) {
   TreeSet holders = (TreeSet) activeLocks.get(src);
   if (holders != null && holders.contains(holder)) {
     holders.remove(holder);
     if (holders.size() == 0) {
       activeLocks.remove(src);
     }
     return COMPLETE_SUCCESS;
   } else {
     return OPERATION_FAILED;
   }
 }
Пример #2
0
 public int obtainLock(UTF8 src, UTF8 holder, boolean exclusive) {
   TreeSet holders = (TreeSet) activeLocks.get(src);
   if (holders == null) {
     holders = new TreeSet();
     activeLocks.put(src, holders);
   }
   if (exclusive && holders.size() > 0) {
     return STILL_WAITING;
   } else {
     holders.add(holder);
     return COMPLETE_SUCCESS;
   }
 }
Пример #3
0
 /** Returns whether the given block is one pointed-to by a file. */
 public boolean isValidBlock(Block b) {
   synchronized (rootDir) {
     if (activeBlocks.contains(b)) {
       return true;
     } else {
       return false;
     }
   }
 }
Пример #4
0
 boolean unprotectedAddFile(UTF8 name, Block blocks[]) {
   synchronized (rootDir) {
     if (blocks != null) {
       // Add file->block mapping
       for (int i = 0; i < blocks.length; i++) {
         activeBlocks.add(blocks[i]);
       }
     }
     return (rootDir.addNode(name.toString(), blocks) != null);
   }
 }
Пример #5
0
 Block[] unprotectedDelete(UTF8 src) {
   synchronized (rootDir) {
     INode targetNode = rootDir.getNode(src.toString());
     if (targetNode == null) {
       return null;
     } else {
       //
       // Remove the node from the namespace and GC all
       // the blocks underneath the node.
       //
       if (!targetNode.removeNode()) {
         return null;
       } else {
         Vector v = new Vector();
         targetNode.collectSubtreeBlocks(v);
         for (Iterator it = v.iterator(); it.hasNext(); ) {
           Block b = (Block) it.next();
           activeBlocks.remove(b);
         }
         return (Block[]) v.toArray(new Block[v.size()]);
       }
     }
   }
 }