public static void attemptObtain(ObtainableLock lock) throws IOException { int attempts = 0; while (!lock.obtain()) { //we could fail immediately, but being Infinispan a bit latency sensitive we give a bit of grace here if (attempts++ > MAX_LOCK_ACQUIRE_MILLISECONDS) failLockAcquire(); if (Thread.currentThread().isInterrupted()) failLockAcquire(); try { Thread.sleep(1); } catch (InterruptedException e) { Thread.currentThread().interrupt(); failLockAcquire(); } } }
/** * {@inheritDoc} */ @Override public BaseLuceneLock obtainLock(Directory dir, String lockName) throws IOException { if (!(dir instanceof DirectoryLucene)) { throw new UnsupportedOperationException("BaseLuceneLock can only be used with DirectoryLucene, got: " + dir); } DirectoryLucene infinispanDirectory = (DirectoryLucene) dir; int affinitySegmentId = infinispanDirectory.getAffinitySegmentId(); Cache distLockCache = infinispanDirectory.getDistLockCache(); String indexName = infinispanDirectory.getIndexName(); BaseLuceneLock lock = new BaseLuceneLock(distLockCache, indexName, lockName, affinitySegmentId); CommonLockObtainUtils.attemptObtain(lock); return lock; }
/** * {@inheritDoc} */ @Override public BaseLuceneLock obtainLock(Directory dir, String lockName) throws IOException { if (!(dir instanceof DirectoryLucene)) { throw new UnsupportedOperationException("BaseLuceneLock can only be used with DirectoryLucene, got: " + dir); } DirectoryLucene infinispanDirectory = (DirectoryLucene) dir; int affinitySegmentId = infinispanDirectory.getAffinitySegmentId(); Cache distLockCache = infinispanDirectory.getDistLockCache(); String indexName = infinispanDirectory.getIndexName(); BaseLuceneLock lock = new BaseLuceneLock(distLockCache, indexName, lockName, affinitySegmentId); CommonLockObtainUtils.attemptObtain(lock); return lock; }
/** * {@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; }
public static void attemptObtain(ObtainableLock lock) throws IOException { int attempts = 0; while (!lock.obtain()) { //we could fail immediately, but being Infinispan a bit latency sensitive we give a bit of grace here if (attempts++ > MAX_LOCK_ACQUIRE_MILLISECONDS) failLockAcquire(); if (Thread.currentThread().isInterrupted()) failLockAcquire(); try { Thread.sleep(1); } catch (InterruptedException e) { Thread.currentThread().interrupt(); failLockAcquire(); } } }
/** * {@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; }