use of org.apache.jackrabbit.core.cluster.ClusterOperation in project jackrabbit by apache.
the class LockManagerImpl method internalUnlock.
/**
* Unlock a node (internal implementation)
* @param node node to unlock
* @throws LockException if the node can not be unlocked
* @throws RepositoryException if another error occurs
*/
boolean internalUnlock(NodeImpl node) throws LockException, RepositoryException {
ClusterOperation operation = null;
boolean successful = false;
if (eventChannel != null) {
operation = eventChannel.create(node.getNodeId());
}
acquire();
try {
SessionImpl session = (SessionImpl) node.getSession();
// check whether node is locked by this session
PathMap.Element<LockInfo> element = lockMap.map(getPath(session, node.getId()), true);
if (element == null) {
throw new LockException("Node not locked: " + node);
}
LockInfo info = element.get();
if (info == null) {
throw new LockException("Node not locked: " + node);
}
checkUnlock(info, session);
getSessionLockManager(session).lockTokenRemoved(info.getLockToken());
element.set(null);
info.setLive(false);
if (!info.isSessionScoped()) {
save();
successful = true;
}
return true;
} finally {
release();
if (operation != null) {
operation.ended(successful);
}
}
}
use of org.apache.jackrabbit.core.cluster.ClusterOperation in project jackrabbit by apache.
the class LockManagerImpl method internalLock.
/**
* Internal <code>lock</code> implementation that takes the same parameters
* as the public method.
*
* @param node node to lock
* @param isDeep whether the lock applies to this node only
* @param isSessionScoped whether the lock is session scoped
* @param timeoutHint
* @param ownerInfo
* @return lock
* @throws LockException if the node is already locked
* @throws RepositoryException if another error occurs
*/
LockInfo internalLock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timeoutHint, String ownerInfo) throws LockException, RepositoryException {
SessionImpl session = (SessionImpl) node.getSession();
String lockOwner = (ownerInfo != null) ? ownerInfo : session.getUserID();
InternalLockInfo info = new InternalLockInfo(node.getNodeId(), isSessionScoped, isDeep, lockOwner, timeoutHint);
ClusterOperation operation = null;
boolean successful = false;
// Cluster is only informed about open-scoped locks
if (eventChannel != null && !isSessionScoped) {
operation = eventChannel.create(node.getNodeId(), isDeep, lockOwner);
}
acquire();
try {
// check whether node is already locked
Path path = getPath(session, node.getId());
PathMap.Element<LockInfo> element = lockMap.map(path, false);
LockInfo other = element.get();
if (other != null) {
if (element.hasPath(path)) {
other.throwLockException("Node already locked: " + node, session);
} else if (other.isDeep()) {
other.throwLockException("Parent node has a deep lock: " + node, session);
}
}
if (info.isDeep() && element.hasPath(path) && element.getChildrenCount() > 0) {
info.throwLockException("Some child node is locked", session);
}
// create lock token
info.setLockHolder(session);
info.setLive(true);
session.addListener(info);
if (!info.isSessionScoped()) {
getSessionLockManager(session).lockTokenAdded(info.getLockToken());
}
lockMap.put(path, info);
if (!info.isSessionScoped()) {
save();
successful = true;
}
return info;
} finally {
release();
if (operation != null) {
operation.ended(successful);
}
}
}
Aggregations