@Override public void close() throws IOException { try { commitTransactions(); } finally { clearLock(); } }
/** * Since Lucene 4.7, method release() was renamed to close() * @deprecated use method close(). */ @Deprecated public void release() throws IOException { close(); }
@Override public void ensureValid() throws IOException { if (!isLocked()) { throw new IOException("This lock is no longer being held"); } }
@Override public boolean obtain() throws IOException { Object previousValue = noCacheStoreCache.putIfAbsent(keyOfLock, keyOfLock); if (previousValue == null) { if (trace) { log.tracef("Lock: %s acquired for index: %s", lockName, indexName); } // we own the lock: startTransaction(); return true; } else { if (trace) { log.tracef("Lock: %s not acquired for index: %s, was taken already.", lockName, indexName); } return false; } }
/** * Will clear the lock, eventually suspending a running transaction to make sure the * release is immediately taking effect. */ public void clearLockSuspending() { Transaction tx = null; try { // if there is an ongoing transaction we need to suspend it if ((tx = tm.getTransaction()) != null) { tm.suspend(); } clearLock(); } catch (Exception e) { log.errorSuspendingTransaction(e); } finally { if (tx != null) { try { tm.resume(tx); } catch (Exception e) { throw new CacheException("Unable to resume suspended transaction " + tx, e); } } } }
/** * {@inheritDoc} */ @Override public TransactionalSharedLuceneLock obtainLock(Directory dir, String lockName) throws IOException { if (!(dir instanceof DirectoryLucene)) { throw new UnsupportedOperationException("TransactionalSharedLuceneLock can only be used with DirectoryLucene, got: " + dir); } DirectoryLucene infinispanDirectory = (DirectoryLucene) dir; Cache cache = infinispanDirectory.getDistLockCache(); String indexName = infinispanDirectory.getIndexName(); TransactionManager tm = cache.getAdvancedCache().getTransactionManager(); if (tm == null) { ComponentStatus status = cache.getAdvancedCache().getComponentRegistry().getStatus(); if (status.equals(ComponentStatus.RUNNING)) { throw new CacheException( "Failed looking up TransactionManager. Check if any transaction manager is associated with Infinispan cache: \'" + cache.getName() + "\'"); } else { throw new CacheException("Failed looking up TransactionManager: the cache is not running"); } } TransactionalSharedLuceneLock lock = new TransactionalSharedLuceneLock(cache, indexName, lockName, tm); CommonLockObtainUtils.attemptObtain(lock); return lock; }
@Override public boolean obtain() throws IOException { Object previousValue = noCacheStoreCache.putIfAbsent(keyOfLock, keyOfLock); if (previousValue == null) { if (trace) { log.tracef("Lock: %s acquired for index: %s", lockName, indexName); } // we own the lock: startTransaction(); return true; } else { if (trace) { log.tracef("Lock: %s not acquired for index: %s, was taken already.", lockName, indexName); } return false; } }
/** * Will clear the lock, eventually suspending a running transaction to make sure the * release is immediately taking effect. */ public void clearLockSuspending() { Transaction tx = null; try { // if there is an ongoing transaction we need to suspend it if ((tx = tm.getTransaction()) != null) { tm.suspend(); } clearLock(); } catch (Exception e) { log.errorSuspendingTransaction(e); } finally { if (tx != null) { try { tm.resume(tx); } catch (Exception e) { throw new CacheException("Unable to resume suspended transaction " + tx, e); } } } }
/** * {@inheritDoc} */ @Override public TransactionalSharedLuceneLock obtainLock(Directory dir, String lockName) throws IOException { if (!(dir instanceof DirectoryLucene)) { throw new UnsupportedOperationException("TransactionalSharedLuceneLock can only be used with DirectoryLucene, got: " + dir); } DirectoryLucene infinispanDirectory = (DirectoryLucene) dir; Cache cache = infinispanDirectory.getDistLockCache(); String indexName = infinispanDirectory.getIndexName(); TransactionManager tm = cache.getAdvancedCache().getTransactionManager(); if (tm == null) { ComponentStatus status = cache.getAdvancedCache().getComponentRegistry().getStatus(); if (status.equals(ComponentStatus.RUNNING)) { throw new CacheException( "Failed looking up TransactionManager. Check if any transaction manager is associated with Infinispan cache: \'" + cache.getName() + "\'"); } else { throw new CacheException("Failed looking up TransactionManager: the cache is not running"); } } TransactionalSharedLuceneLock lock = new TransactionalSharedLuceneLock(cache, indexName, lockName, tm); CommonLockObtainUtils.attemptObtain(lock); return lock; }
@Override public void close() throws IOException { try { commitTransactions(); } finally { clearLock(); } }
/** * Since Lucene 4.7, method release() was renamed to close() * @deprecated use method close(). */ @Deprecated public void release() throws IOException { close(); }
@Override public void ensureValid() throws IOException { if (!isLocked()) { throw new IOException("This lock is no longer being held"); } }