@Override public void addLockToken( String lockToken ) throws LockException { CheckArg.isNotNull(lockToken, "lockToken"); if (lockTokens.contains(lockToken)) { // We already hold the token ... return; } // Change the lock to be held by a session ... try { if (!lockManager.setHeldBySession(session, lockToken, true)) { throw new LockException(JcrI18n.lockTokenAlreadyHeld.text(lockToken)); } lockTokens.add(lockToken); } catch (LockException e) { lockTokens.remove(lockToken); throw e; } }
@Override public void addLockToken( String lockToken ) throws LockException { CheckArg.isNotNull(lockToken, "lockToken"); if (lockTokens.contains(lockToken)) { // We already hold the token ... return; } // Change the lock to be held by a session ... try { if (!lockManager.setHeldBySession(session, lockToken, true)) { throw new LockException(JcrI18n.lockTokenAlreadyHeld.text(lockToken)); } lockTokens.add(lockToken); } catch (LockException e) { lockTokens.remove(lockToken); throw e; } }
/** * Unlocks all locks corresponding to the tokens held by the supplied session. * * @throws RepositoryException if the session is not live */ final void cleanLocks() throws RepositoryException { // clean the session-scoped locks: unlock all the nodes and remove the lock tokens from the system area Set<String> cleanedTokens = lockManager.cleanLocks(session); if (lockTokens.isEmpty()) { return; } // clean all open-scoped locks created via this session for (String lockToken : lockTokens) { if (!cleanedTokens.contains(lockToken)) { ModeShapeLock lock = lockManager.findLockByToken(lockToken); if (lock == null) { // there is no existing lock for this token (it must've been removed from somewhere else) continue; } // this is an open-scoped lock created via this session for which we'll have to update the 'held' flag if (!lockManager.setHeldBySession(session, lockToken, false)) { // Generally not expected, because if the lock exists we can always change the lock-held value to false // even when it is already false ... throw new LockException(JcrI18n.invalidLockToken.text(lockToken)); } } } // always clean our internal map of tokens lockTokens.clear(); }
/** * Unlocks all locks corresponding to the tokens held by the supplied session. * * @throws RepositoryException if the session is not live */ final void cleanLocks() throws RepositoryException { // clean the session-scoped locks: unlock all the nodes and remove the lock tokens from the system area Set<String> cleanedTokens = lockManager.cleanLocks(session); if (lockTokens.isEmpty()) { return; } // clean all open-scoped locks created via this session for (String lockToken : lockTokens) { if (!cleanedTokens.contains(lockToken)) { ModeShapeLock lock = lockManager.findLockByToken(lockToken); if (lock == null) { // there is no existing lock for this token (it must've been removed from somewhere else) continue; } // this is an open-scoped lock created via this session for which we'll have to update the 'held' flag if (!lockManager.setHeldBySession(session, lockToken, false)) { // Generally not expected, because if the lock exists we can always change the lock-held value to false // even when it is already false ... throw new LockException(JcrI18n.invalidLockToken.text(lockToken)); } } } // always clean our internal map of tokens lockTokens.clear(); }
@Override public void removeLockToken( String lockToken ) throws LockException { CheckArg.isNotNull(lockToken, "lockToken"); // Trivial case of giving a token back to ourself if (!lockTokens.contains(lockToken)) { // We don't already hold the token ... throw new LockException(JcrI18n.invalidLockToken.text(lockToken)); } // Change the lock to be no longer held by a session ... try { if (!lockManager.setHeldBySession(session, lockToken, false)) { // Generally not expected, because if the lock exists we can always change the lock-held value to false // even when it is already false ... throw new LockException(JcrI18n.invalidLockToken.text(lockToken)); } // Now remove the tokens from our session ... lockTokens.remove(lockToken); } catch (LockFailureException e) { lockTokens.remove(lockToken); throw new LockException(JcrI18n.invalidLockToken.text(lockToken)); } }
@Override public void removeLockToken( String lockToken ) throws LockException { CheckArg.isNotNull(lockToken, "lockToken"); // Trivial case of giving a token back to ourself if (!lockTokens.contains(lockToken)) { // We don't already hold the token ... throw new LockException(JcrI18n.invalidLockToken.text(lockToken)); } // Change the lock to be no longer held by a session ... try { if (!lockManager.setHeldBySession(session, lockToken, false)) { // Generally not expected, because if the lock exists we can always change the lock-held value to false // even when it is already false ... throw new LockException(JcrI18n.invalidLockToken.text(lockToken)); } // Now remove the tokens from our session ... lockTokens.remove(lockToken); } catch (LockFailureException e) { lockTokens.remove(lockToken); throw new LockException(JcrI18n.invalidLockToken.text(lockToken)); } }