NodeSPI parent = null;
NodeSPI subtreeRoot = null;
boolean parentLocked = false;
boolean subtreeLocked = false;
NodeLock parentLock = null;
NodeLock subtreeLock = null;
try
{
// Record that this fqn is in status change, so can't provide state
activationChangeNodes.add(fqn);
if (!isInactive(fqn))
{
deactivate(fqn);
}
// Create a list with the Fqn in the main cache and any buddy backup trees
BuddyManager buddyManager = cache.getBuddyManager();
ArrayList<Fqn> list = new ArrayList<Fqn>();
list.add(fqn);
if (buddyManager != null)
{
Set buddies = cache.peek(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, false, false).getChildrenNames();
if (buddies != null)
{
for (Iterator it = buddies.iterator(); it.hasNext();)
{
Fqn base = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, it.next());
list.add(new Fqn(base, fqn));
}
}
}
long stateFetchTimeout = cache.getConfiguration().getLockAcquisitionTimeout() + 5000;
// Remove the subtree from the main cache and any buddy backup trees
for (Iterator<Fqn> it = list.iterator(); it.hasNext();)
{
Fqn subtree = it.next();
subtreeRoot = cache.peek(subtree, false, false);
if (subtreeRoot != null)
{
// Acquire locks
Object owner = getOwnerForLock();
subtreeLock = subtreeRoot.getLock();
subtreeLock.acquireAll(owner, stateFetchTimeout, NodeLock.LockType.WRITE);
subtreeLocked = true;
// Lock the parent, as we're about to write to it
parent = subtreeRoot.getParent();
if (parent != null)
{
parentLock = parent.getLock();
parentLock.acquire(owner, stateFetchTimeout, NodeLock.LockType.WRITE);
parentLocked = true;
}
// Remove the subtree
cache.evict(subtree, true);
//cache._evictSubtree(subtree);
// Release locks
if (parent != null)
{
log.debug("forcing release of locks in parent");
parentLock.releaseAll();
}
parentLocked = false;
log.debug("forcing release of all locks in subtree");
subtreeLock.releaseAll();
subtreeLocked = false;
}
}
}
catch (InterruptedException ie)
{
throw new CacheException("Interrupted while acquiring lock", ie);
}
finally
{
// If we didn't succeed, undo the marshalling change
// NO. Since we inactivated, we may have missed changes
//if (!success && !inactive)
// marshaller_.activate(subtreeFqn);
// If necessary, release locks
if (parentLocked)
{
log.debug("forcing release of locks in parent");
try
{
parentLock.releaseAll();
}
catch (Throwable t)
{
log.error("failed releasing locks", t);
}
}
if (subtreeLocked)
{
log.debug("forcing release of all locks in subtree");
try
{
subtreeLock.releaseAll();
}
catch (Throwable t)
{
log.error("failed releasing locks", t);
}