/** * for admin purposes only. Release a lockentry directly. Use 'releaseLock' as method to release a * lock. * * @param lock release this lockentry */ @Override public void releaseLockEntry(final LockEntry lockEntry) { final String asset = lockEntry.getKey(); final OLATPrincipal releaseRequestor = lockEntry.getOwner(); // cluster:: change to useage with syncer, but we don't have the // olatresourceable yet pessimisticLockManager.findOrPersistPLock(asset); final LockImpl li = clusterLockManager.findLock(asset); if (li == null) { // do nothing - since this lock may have been one that was cleared // when restarting the vm } else { // check that entry was previously locked by the same user that now // wants to release the lock. final OLATPrincipal ownwer = li.getOwner(); if (releaseRequestor.equals(ownwer)) { // delete the lock clusterLockManager.deleteLock(li); } else { throw new AssertException( "cannot release lock since the requestor of the release (" + releaseRequestor.getName() + ") is not the owner (" + ownwer.getName() + ") of the lock (" + asset + ")"); } } }
/** * receives all sign on / sign off events so it can release locks of users which have or are * logged off */ @Override public void event(final Event event) { final SignOnOffEvent se = (SignOnOffEvent) event; if (!se.isSignOn() && se.isEventOnThisNode()) { // it is a "logout" event - we are only interested in logout events // and it is from our VM => only release all locks from within one // VM final String identName = se.getIdentityName(); // release all locks held by the identity that has just logged out. // (assuming one user has only one session (logged in with one // browser only): otherwise (as in singlevm, too) // since the lock is reentrant, a lock could be freed while a // session still is in a locked workflow (2x lock and then once // freed) try { clusterLockManager.releaseAllLocksFor(identName); } catch (final DBRuntimeException dbEx) { log.warn( "releaseAllLocksFor failed, close session and try it again for identName=" + identName); // TODO: 2010-04-23 Transactions [eglis]: OLAT-4318: this // rollback has possibly unwanted // side effects, as it rolls back any changes with this // transaction during this // event handling. Nicer would be to be done in the // outmost-possible place, e.g. dofire() DBFactory.getInstance().rollbackAndCloseSession(); // try again with new db-session log.info("try again to release all locks for identName=" + identName); clusterLockManager.releaseAllLocksFor(identName); log.info("Done, released all locks for identName=" + identName); } } }
@Override public List<LockEntry> adminOnlyGetLockEntries() { final List<LockImpl> li = clusterLockManager.getAllLocks(); final List<LockEntry> res = new ArrayList<LockEntry>(li.size()); for (final LockImpl impl : li) { res.add(new LockEntry(impl.getAsset(), impl.getCreationDate().getTime(), impl.getOwner())); } return res; }
/** * Delete any locks hold by this principal. * * @param principal */ public void releaseAllLocksForPrincipal(OLATPrincipal principal) { try { clusterLockManager.releaseAllLocksFor(principal.getName()); log.info( "Done, released all locks managed by the clusterLockManager for identName=" + principal.getName()); } catch (Exception e) { log.warn("releaseAllLocksFor failed, for identName=" + principal.getName()); } try { this.getPersistentLockManager().releaseAllLocksForPrincipal(principal); log.info( "Done, released all locks managed by the PersistentLockManager for identName=" + principal.getName()); } catch (Exception e) { log.warn("releaseAllLocksForPrincipal failed, for identName=" + principal.getName()); } }
@Override public boolean isLocked(final OLATResourceable ores, final String locksubkey) { final String asset = OresHelper.createStringRepresenting(ores, locksubkey); final LockImpl li = clusterLockManager.findLock(asset); return (li != null); }