Java Code Examples for org.apache.lucene.store.Lock#obtain()

The following examples show how to use org.apache.lucene.store.Lock#obtain() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: right_IndexWriter_1.3.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
/** 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();
   }
 }
 
Example 2
Source File: left_IndexWriter_1.2.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
/** 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();
   }
 }
 
Example 3
Source File: right_IndexWriter_1.22.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
/** 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();
  }
}
 
Example 4
Source File: left_IndexWriter_1.21.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
/** 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();
  }
}
 
Example 5
Source File: right_IndexWriter_1.42.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example 6
Source File: left_IndexWriter_1.41.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example 7
Source File: RecordOwnerLockFactoryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 8
Source File: RecordOwnerLockFactoryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 9
Source File: RecordOwnerLockFactoryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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());
}