/** * {@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; }
/** * Force release of the lock in this directory. Make sure to understand the * consequences */ @Override public void forceUnlock(String lockName) { Cache<Object, Integer> lockCache = getDistLockCache().getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD); FileCacheKey fileCacheKey = new FileCacheKey(indexName, lockName, affinitySegmentId); Object previousValue = lockCache.remove(fileCacheKey); if (previousValue!=null && trace) { log.tracef("Lock forcibly removed for index: %s", indexName); } }
/** * Force release of the lock in this directory. Make sure to understand the * consequences */ @Override public void forceUnlock(String lockName) { Cache<Object, Integer> lockCache = getDistLockCache().getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD); FileCacheKey fileCacheKey = new FileCacheKey(indexName, lockName, affinitySegmentId); Object previousValue = lockCache.remove(fileCacheKey); if (previousValue!=null && trace) { log.tracef("Lock forcibly removed for index: %s", indexName); } }
/** * {@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; }
/** * {@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; }