org.apache.lucene.store.Lock类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(175)

本文整理了Java中org.apache.lucene.store.Lock类的一些代码示例,展示了Lock类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lock类的具体详情如下:
包路径:org.apache.lucene.store.Lock
类名称:Lock

Lock介绍

[英]An interprocess mutex lock.

Typical use might look like:

try (final Lock lock = directory.obtainLock("my.lock")) { 
// ... code to execute while locked ... 
}

[中]进程间互斥锁。
典型用法可能如下所示:

try (final Lock lock = directory.obtainLock("my.lock")) { 
// ... code to execute while locked ... 
}

代码示例

代码示例来源:origin: org.apache.lucene/lucene-core

@Override
public void ensureValid() throws IOException {
 lock.ensureValid();
}

代码示例来源:origin: lucene/lucene

/** Calls {@link #doBody} while <i>lock</i> is obtained.  Blocks if lock
  * cannot be obtained immediately.  Retries to obtain lock once per second
  * until it is obtained, or until it has tried ten times. Lock is released when
  * {@link #doBody} exits. */
 public Object run() throws IOException {
  boolean locked = false;
  try {
    locked = lock.obtain(lockWaitTimeout);
    return doBody();
  } finally {
   if (locked)
    lock.release();
  }
 }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public void close() {
  if (closed.compareAndSet(false, true) && locks != null) {
    for (Lock lock : locks) {
      try {
        logger.trace("releasing lock [{}]", lock);
        lock.close();
      } catch (IOException e) {
        logger.trace(() -> new ParameterizedMessage("failed to release lock [{}]", lock), e);
      }
    }
  }
}

代码示例来源:origin: lucene/lucene

/** Release the write lock, if needed. */
protected void finalize() throws IOException {
 if (writeLock != null) {
  writeLock.release();                        // release write lock
  writeLock = null;
 }
}

代码示例来源:origin: org.compass-project/compass

public boolean isLocked() {
    return lock.isLocked();
  }
}

代码示例来源:origin: org.apache.lucene/lucene-core-jfrog

public synchronized boolean obtain()
 throws LockObtainFailedException, IOException {
 return lock.obtain();
}

代码示例来源:origin: org.infinispan/infinispan-lucene-directory

@Test
public void testLuceneIndexLocking() throws IOException {
 assertFalse(isLocked(directory1));
 Lock obtainedLock = directory1.obtainLock(IndexWriter.WRITE_LOCK_NAME);
 assertTrue(isLocked(directory1));
 assertTrue(isLocked(directory2));
 assertFalse(isLocked(directory3));
 obtainedLock.ensureValid(); //will throw an exception on failure
 obtainedLock.close();
 assertFalse(isLocked(directory1));
 assertFalse(isLocked(directory2));
 assertFalse(isLocked(directory3));
}

代码示例来源:origin: org.dspace.dependencies.solr/dspace-solr-core

directoryName = "snapshot." + fmt.format(new Date());
lock = lockFactory.makeLock(directoryName + ".lock");
if (lock.isLocked()) return;
snapShotDir = new File(snapDir, directoryName);
if (!snapShotDir.mkdir()) {
if (lock != null) {
 try {
  lock.release();
 } catch (IOException e) {
  LOG.error("Unable to release snapshoot lock: " + directoryName + ".lock");

代码示例来源:origin: org.apache.lucene/lucene-core-jfrog

private void acquireTestLock() throws IOException {
 String randomLockName = "lucene-" + Long.toString(new Random().nextInt(), Character.MAX_RADIX) + "-test.lock";
 
 Lock l = makeLock(randomLockName);
 try {
  l.obtain();
 } catch (IOException e) {
  IOException e2 = new IOException("Failed to acquire random test lock; please verify filesystem for lock directory '" + lockDir + "' supports locking");
  e2.initCause(e);
  throw e2;
 }
 l.release();
}

代码示例来源:origin: org.apache.maven.indexer/indexer-core

@Override
public void close()
  throws IOException
{
  try
  {
    delegate.close();
  }
  finally
  {
    emittedLocks.remove( this );
  }
}

代码示例来源:origin: lucene/lucene

/** Release the write lock, if needed. */
protected final void finalize() throws IOException {
 if (writeLock != null) {
  writeLock.release();                        // release write lock
  writeLock = null;
 }
}

代码示例来源:origin: gncloud/fastcatsearch

@Override
public synchronized boolean isLocked() throws IOException {
 return lock.isLocked();
}

代码示例来源:origin: gncloud/fastcatsearch

@Override
public synchronized boolean obtain() throws IOException {
 return lock.obtain();
}

代码示例来源:origin: org.apache.lucene/lucene-core

@Override
public void copyFrom(Directory from, String src, String dest, IOContext context) throws IOException {
 writeLock.ensureValid();
 in.copyFrom(from, src, dest, context);
}

代码示例来源:origin: org.apache.lucene/com.springsource.org.apache.lucene

private void acquireTestLock() throws IOException {
 String randomLockName = "lucene-" + Long.toString(new Random().nextInt(), Character.MAX_RADIX) + "-test.lock";
 
 Lock l = makeLock(randomLockName);
 try {
  l.obtain();
 } catch (IOException e) {
  IOException e2 = new IOException("Failed to acquire random test lock; please verify filesystem for lock directory '" + lockDir + "' supports locking");
  e2.initCause(e);
  throw e2;
 }
 l.release();
}

代码示例来源:origin: apache/maven-indexer

@Override
public void close()
  throws IOException
{
  try
  {
    delegate.close();
  }
  finally
  {
    emittedLocks.remove( this );
  }
}

代码示例来源:origin: org.compass-project/compass

@Override
public void release() throws IOException {
  lock.release();
}

代码示例来源:origin: org.apache.lucene/com.springsource.org.apache.lucene

public synchronized boolean isLocked() {
 return lock.isLocked();
}

代码示例来源:origin: org.apache.lucene/com.springsource.org.apache.lucene

public synchronized boolean obtain()
 throws LockObtainFailedException, IOException {
 return lock.obtain();
}

代码示例来源:origin: org.apache.lucene/lucene-core

@Override
public void close() throws IOException {
 try (Lock l = lock) {
  l.ensureValid();
  verify((byte) 0);
 }
}

相关文章

微信公众号

最新文章

更多