本文整理汇总了Java中org.apache.lucene.store.Lock.obtain方法的典型用法代码示例。如果您正苦于以下问题:Java Lock.obtain方法的具体用法?Java Lock.obtain怎么用?Java Lock.obtain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.store.Lock
的用法示例。
在下文中一共展示了Lock.obtain方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: acquireWriteLocks
import org.apache.lucene.store.Lock; //导入方法依赖的package包/类
/** Acquires write locks on all the directories; be sure
* to match with a call to {@link IOUtils#close} in a
* finally clause. */
private List<Lock> acquireWriteLocks(Directory... dirs) throws IOException {
List<Lock> locks = new ArrayList<>();
for(int i=0;i<dirs.length;i++) {
boolean success = false;
try {
Lock lock = dirs[i].makeLock(WRITE_LOCK_NAME);
locks.add(lock);
lock.obtain(config.getWriteLockTimeout());
success = true;
} finally {
if (success == false) {
// Release all previously acquired locks:
IOUtils.closeWhileHandlingException(locks);
}
}
}
return locks;
}
示例2: testBasic
import org.apache.lucene.store.Lock; //导入方法依赖的package包/类
@Test
public void testBasic() throws IOException {
URI uri = dfsCluster.getURI();
Path lockPath = new Path(uri.toString(), "/basedir/lock");
HdfsLockFactory lockFactory = new HdfsLockFactory(lockPath, new Configuration());
Lock lock = lockFactory.makeLock("testlock");
boolean success = lock.obtain();
assertTrue("We could not get the lock when it should be available", success);
success = lock.obtain();
assertFalse("We got the lock but it should be unavailble", success);
lock.close();
success = lock.obtain();
assertTrue("We could not get the lock when it should be available", success);
success = lock.obtain();
assertFalse("We got the lock but it should be unavailble", success);
}
示例3: IndexWriter
import org.apache.lucene.store.Lock; //导入方法依赖的package包/类
/** Constructs an IndexWriter for the index in <code>d</code>. Text will be
analyzed with <code>a</code>. If <code>create</code> is true, then a new,
empty index will be created in <code>d</code>, replacing the index already
there, if any. */
public IndexWriter(Directory d, Analyzer a, final boolean create)
throws IOException {
directory = d;
analyzer = a;
Lock writeLock = directory.makeLock("write.lock");
if (!writeLock.obtain()) // obtain write lock
throw new IOException("Index locked for write: " + writeLock);
synchronized (directory) { // in- & inter-process sync
new Lock.With(directory.makeLock("commit.lock")) {
public Object doBody() throws IOException {
if (create)
segmentInfos.write(directory);
else
segmentInfos.read(directory);
return null;
}
}.run();
}
}
示例4: IndexWriter
import org.apache.lucene.store.Lock; //导入方法依赖的package包/类
/** Constructs an IndexWriter for the index in <code>d</code>. Text will be
analyzed with <code>a</code>. If <code>create</code> is true, then a new,
empty index will be created in <code>d</code>, replacing the index already
there, if any. */
public IndexWriter(Directory d, Analyzer a, final boolean create)
throws IOException {
directory = d;
analyzer = a;
Lock writeLock = directory.makeLock(IndexWriter.WRITE_LOCK_NAME);
if (!writeLock.obtain(WRITE_LOCK_TIMEOUT)) // obtain write lock
throw new IOException("Index locked for write: " + writeLock);
this.writeLock = writeLock; // save it
synchronized (directory) { // in- & inter-process sync
new Lock.With(directory.makeLock(IndexWriter.COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT) {
public Object doBody() throws IOException {
if (create)
segmentInfos.write(directory);
else
segmentInfos.read(directory);
return null;
}
}.run();
}
}
示例5: IndexWriter
import org.apache.lucene.store.Lock; //导入方法依赖的package包/类
private IndexWriter(Directory d, Analyzer a, final boolean create, boolean closeDir)
throws IOException {
this.closeDir = closeDir;
directory = d;
analyzer = a;
Lock writeLock = directory.makeLock(IndexWriter.WRITE_LOCK_NAME);
if (!writeLock.obtain(WRITE_LOCK_TIMEOUT)) // obtain write lock
throw new IOException("Index locked for write: " + writeLock);
this.writeLock = writeLock; // save it
synchronized (directory) { // in- & inter-process sync
new Lock.With(directory.makeLock(IndexWriter.COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT) {
public Object doBody() throws IOException {
if (create)
segmentInfos.write(directory);
else
segmentInfos.read(directory);
return null;
}
}.run();
}
}
示例6: acquireWriteLocks
import org.apache.lucene.store.Lock; //导入方法依赖的package包/类
/** Acquires write locks on all the directories; be sure
* to match with a call to {@link IOUtils#close} in a
* finally clause. */
private List<Lock> acquireWriteLocks(Directory... dirs) throws IOException {
List<Lock> locks = new ArrayList<Lock>();
for(int i=0;i<dirs.length;i++) {
boolean success = false;
try {
Lock lock = dirs[i].makeLock(WRITE_LOCK_NAME);
locks.add(lock);
lock.obtain(config.getWriteLockTimeout());
success = true;
} finally {
if (success == false) {
// Release all previously acquired locks:
IOUtils.closeWhileHandlingException(locks);
}
}
}
return locks;
}
示例7: testLock
import org.apache.lucene.store.Lock; //导入方法依赖的package包/类
public void testLock() throws IOException {
final Lock lock = lockFactory.makeLock("test"); //NOI18N
assertFalse(lock.isLocked());
lock.obtain();
assertTrue(lock.isLocked());
lock.release();
assertFalse(lock.isLocked());
}
示例8: testLockInstances
import org.apache.lucene.store.Lock; //导入方法依赖的package包/类
public void testLockInstances() throws IOException {
final Lock lock1 = lockFactory.makeLock("test"); //NOI18N
final Lock lock2 = lockFactory.makeLock("test"); //NOI18N
assertFalse(lock1.isLocked());
assertFalse(lock2.isLocked());
lock1.obtain();
assertTrue(lock1.isLocked());
assertTrue(lock2.isLocked());
lock2.release();
assertFalse(lock1.isLocked());
assertFalse(lock2.isLocked());
}
示例9: testClearLock
import org.apache.lucene.store.Lock; //导入方法依赖的package包/类
public void testClearLock() throws IOException {
Lock lock = lockFactory.makeLock("test"); //NOI18N
assertFalse(lock.isLocked());
lock.obtain();
assertTrue(lock.isLocked());
lockFactory.clearLock("test"); //NOI18N
assertFalse(lock.isLocked());
}