@Test public void lockingDifferentDocumentsDoesNotDelay() throws ComponentLookupException { long start = System.currentTimeMillis(); this.lockManager.lock(this.docRef); this.lockManager.lock(new DocumentReference("xwiki", "data", "P0000002")); this.lockManager.lock(new DocumentReference("xwiki", "data", "P0000003")); long time = System.currentTimeMillis() - start; Assert.assertTrue(time < 5 * 1000); }
@Override public void lock(@Nonnull final DocumentReference document) { try { final Lock lock = this.locks.computeIfAbsent(document, k -> new StampedLock().asWriteLock()); final boolean cleanLock = lock.tryLock(10, TimeUnit.SECONDS); if (!cleanLock) { this.logger.debug("Timed out while waiting for lock on [{}], proceeding anyway", document); } } catch (InterruptedException ex) { this.logger.error("Unexpected interruption while waiting for lock: {}", ex.getMessage(), ex); } }
TimeoutDocumentLockManager implements DocumentLockManager { @Override public void lock(@Nonnull final DocumentReference document) { try { final Lock lock = this.locks.computeIfAbsent(document, k -> new StampedLock().asWriteLock()); final boolean cleanLock = lock.tryLock(10, TimeUnit.SECONDS); if (!cleanLock) { this.logger.debug("Timed out while waiting for lock on [{}], proceeding anyway", document); } } catch (InterruptedException ex) { this.logger.error("Unexpected interruption while waiting for lock: {}", ex.getMessage(), ex); } } }
TimeoutDocumentLockManager implements DocumentLockManager { @Override public void lock(@Nonnull final DocumentReference document) { try { final Lock lock = this.locks.computeIfAbsent(document, k -> new StampedLock().asWriteLock()); final boolean cleanLock = lock.tryLock(10, TimeUnit.SECONDS); if (!cleanLock) { this.logger.debug("Timed out while waiting for lock on [{}], proceeding anyway", document); } } catch (InterruptedException ex) { this.logger.error("Unexpected interruption while waiting for lock: {}", ex.getMessage(), ex); } }  }
TimeoutDocumentLockManager implements DocumentLockManager { @Override public void lock(@Nonnull final DocumentReference document) { try { final Lock lock = this.locks.computeIfAbsent(document, k -> new StampedLock().asWriteLock()); final boolean cleanLock = lock.tryLock(10, TimeUnit.SECONDS); if (!cleanLock) { this.logger.debug("Timed out while waiting for lock on [{}], proceeding anyway", document); } } catch (InterruptedException ex) { this.logger.error("Unexpected interruption while waiting for lock: {}", ex.getMessage(), ex); } }  @Override void lock(@Nonnull final DocumentReference document); @Override void unlock(@Nonnull final DocumentReference document); }
TimeoutDocumentLockManager implements DocumentLockManager { @Override public void lock(@Nonnull final DocumentReference document) { try { final Lock lock = this.locks.computeIfAbsent(document, k -> new StampedLock().asWriteLock()); final boolean cleanLock = lock.tryLock(10, TimeUnit.SECONDS); if (!cleanLock) { this.logger.debug("Timed out while waiting for lock on [{}], proceeding anyway", document); } } catch (InterruptedException ex) { this.logger.error("Unexpected interruption while waiting for lock: {}", ex.getMessage(), ex); } }  @Override void lock(@Nonnull final DocumentReference document); @Override void unlock(@Nonnull final DocumentReference document);  }