public void unlockAll(NodeSPI node) { // recursively visit node and all children, and release all locks held by a given owner. node.getLock().releaseAll(); }
public boolean ownsLock(NodeSPI node, Object owner) { return node != null && node.getLock().isOwner(owner); }
public void unlock(NodeSPI node, Object owner) { if (node == null) return; unlock(node.getLock(), owner); }
public void unlockAll(NodeSPI node, Object owner) { // recursively visit node and all children, and release all locks held by a given owner. node.getLock().releaseAll(owner); }
public Object getWriteOwner(NodeSPI node) { return node.getLock().getWriterOwner(); }
public boolean isLocked(NodeSPI n) { return n.getLock().isLocked(); }
public Collection<Object> getReadOwners(NodeSPI node) { return node.getLock().getReaderOwners(); }
private NodeLock acquireLock(NodeSPI node, LockType lockType, Object owner, long timeout) { if (node == null) return null; NodeLock lock = node.getLock(); boolean acquired = false; try { acquired = lock.acquire(owner, timeout, lockType); } catch (InterruptedException e) { // interrupted trying to acquire lock! } if (acquired) return lock; else return null; }
public String printLockInfo(NodeSPI node) { StringBuilder sb = new StringBuilder("\n"); int indent = 0; for (Object n : node.getChildrenDirect()) { ((NodeSPI) n).getLock().printLockInfo(sb, indent); sb.append("\n"); } return sb.toString(); }
/** * Locks all nodes, and returns the NodeLocks in a List. Returns null if the locks could not be acquired. * * @param node node to lock * @param lockType type of lock to acquire * @param owner lock owner * @param timeout timeout * @param excludeInternalFqns if true, internal Fqns are excluded. * @return list of locks acquired, or null. */ private List<NodeLock> lockAllNodes(NodeSPI node, LockType lockType, Object owner, long timeout, boolean excludeInternalFqns) { if (node == null) return null; List<NodeLock> locks = null; try { locks = new ArrayList<NodeLock>(node.getLock().acquireAll(owner, timeout, lockType, excludeInternalFqns)); } catch (InterruptedException e) { // interrupted } return locks; }
private void acquireNodeLock(InvocationContext ctx, NodeSPI node, Object owner, LockType lockType, long lockTimeout) throws LockingException, TimeoutException, InterruptedException { NodeLock lock = node.getLock(); boolean acquired = lock.acquire(owner, lockTimeout, lockType); // Record the lock for release on method return or tx commit/rollback if (acquired) ctx.addLock(lock); }
public void unlock(Fqn fqn, Object owner) { unlock(dataContainer.peek(fqn).getLock(), owner); }
public void releaseAll(Object owner) { for (NodeSPI n : node.getChildrenDirect()) { n.getLock().releaseAll(owner); } release(owner); }
public void printLockInfo(StringBuilder sb, int indent) { boolean locked = isLocked(); printIndent(sb, indent); sb.append(Fqn.SEPARATOR).append(node.getFqn().getLastElement()); if (locked) { sb.append("\t("); toString(sb); sb.append(")"); } for (NodeSPI n : node.getChildrenDirect()) { sb.append("\n"); n.getLock().printLockInfo(sb, indent + 4); } }
public Set<NodeLock> acquireAll(Object caller, long timeout, LockType lock_type, boolean excludeInternalFqns) throws LockingException, TimeoutException, InterruptedException { boolean acquired; if (lock_type == LockType.NONE || (excludeInternalFqns && node.getCache().getInternalFqns().contains(getFqn()))) { return Collections.emptySet(); } Set<NodeLock> retval = new HashSet<NodeLock>(); acquired = acquire(caller, timeout, lock_type); if (acquired) { retval.add(this); } for (NodeSPI n : node.getChildrenDirect()) { retval.addAll(n.getLock().acquireAll(caller, timeout, lock_type, excludeInternalFqns)); } return retval; }
public boolean ownsLock(Fqn fqn, LockType lockType, Object owner) { NodeSPI n = dataContainer.peek(fqn, true, true); if (n == null) return false; NodeLock lock = n.getLock(); switch (lockType) { case READ: return lock.isReadLocked() && lock.isOwner(owner); case WRITE: return lock.isWriteLocked() && lock.isOwner(owner); case NONE: default: return false; } }
currentNode.getLock().releaseAll(owner); if (parent == null || dataContainer.peek(parent.getFqn(), true, true) == null)