当前位置: 首页>>代码示例>>Java>>正文


Java Lock.obtain方法代码示例

本文整理汇总了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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:IndexWriter.java

示例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);
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:HdfsLockFactoryTest.java

示例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();
   }
 }
 
开发者ID:SpoonLabs,项目名称:gumtree-spoon-ast-diff,代码行数:26,代码来源:right_IndexWriter_1.3.java

示例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();
  }
}
 
开发者ID:SpoonLabs,项目名称:gumtree-spoon-ast-diff,代码行数:27,代码来源:right_IndexWriter_1.22.java

示例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();
    }
}
 
开发者ID:SpoonLabs,项目名称:gumtree-spoon-ast-diff,代码行数:24,代码来源:right_IndexWriter_1.42.java

示例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;
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:22,代码来源:IndexWriter.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:RecordOwnerLockFactoryTest.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:RecordOwnerLockFactoryTest.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:RecordOwnerLockFactoryTest.java


注:本文中的org.apache.lucene.store.Lock.obtain方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。