Package org.apache.lucene.store

Examples of org.apache.lucene.store.Lock


   *
   * @throws IOException
   */
  public boolean isCurrent() throws IOException {
    synchronized (directory) {                 // in- & inter-process sync
      Lock commitLock=directory.makeLock(IndexWriter.COMMIT_LOCK_NAME);
     
      boolean locked=false;
     
      try {
         locked=commitLock.obtain(IndexWriter.COMMIT_LOCK_TIMEOUT);
        
         return SegmentInfos.readCurrentVersion(directory) == segmentInfos.getVersion();
      } finally {
        if (locked) {
          commitLock.release();
        }
      }
    }
  }
View Full Code Here


  private void aquireWriteLock() throws IOException {
    if (stale)
      throw new IOException("IndexReader out of date and no longer valid for delete, undelete, or setNorm operations");

    if (writeLock == null) {
      Lock writeLock = directory.makeLock(IndexWriter.WRITE_LOCK_NAME);
      if (!writeLock.obtain(IndexWriter.WRITE_LOCK_TIMEOUT)) // obtain write lock
        throw new IOException("Index locked for write: " + writeLock);
      this.writeLock = writeLock;

      // we have to check whether index has changed since this reader was opened.
      // if so, this reader is no longer valid for deletion
View Full Code Here

    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) {
View Full Code Here

    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) {
View Full Code Here

     * @param name the name of the lock file.
     * @return a Lock object with the given name.
     */
    public Lock makeLock(String name) {
        final File lockFile = new File(directory, name);
        return new Lock() {
            public boolean obtain() throws IOException {
                if (DISABLE_LOCKS) {
                    return true;
                }
                return lockFile.createNewFile();
View Full Code Here

      ensureOpen();
      if (stale)
        throw new StaleReaderException("IndexReader out of date and no longer valid for delete, undelete, or setNorm operations");
 
      if (writeLock == null) {
        Lock writeLock = directory.makeLock(IndexWriter.WRITE_LOCK_NAME);
        if (!writeLock.obtain(IndexWriter.WRITE_LOCK_TIMEOUT)) // obtain write lock
          throw new LockObtainFailedException("Index locked for write: " + writeLock);
        this.writeLock = writeLock;
 
        // we have to check whether index has changed since this reader was opened.
        // if so, this reader is no longer valid for deletion
View Full Code Here

    if (create) {
      // Clear the write lock in case it's leftover:
      directory.clearLock(WRITE_LOCK_NAME);
    }

    Lock writeLock = directory.makeLock(WRITE_LOCK_NAME);
    if (!writeLock.obtain(writeLockTimeout)) // obtain write lock
      throw new LockObtainFailedException("Index locked for write: " + writeLock);
    this.writeLock = writeLock;                   // save it

    try {
      if (create) {
View Full Code Here

      ensureOpen();
      if (stale)
        throw new StaleReaderException("IndexReader out of date and no longer valid for delete, undelete, or setNorm operations");
 
      if (writeLock == null) {
        Lock writeLock = directory.makeLock(IndexWriter.WRITE_LOCK_NAME);
        if (!writeLock.obtain(IndexWriter.WRITE_LOCK_TIMEOUT)) // obtain write lock
          throw new LockObtainFailedException("Index locked for write: " + writeLock);
        this.writeLock = writeLock;
 
        // we have to check whether index has changed since this reader was opened.
        // if so, this reader is no longer valid for deletion
View Full Code Here

      ensureOpen();
      if (stale)
        throw new StaleReaderException("IndexReader out of date and no longer valid for delete, undelete, or setNorm operations");

      if (writeLock == null) {
        Lock writeLock = directory.makeLock(IndexWriter.WRITE_LOCK_NAME);
        if (!writeLock.obtain(IndexWriterConfig.WRITE_LOCK_TIMEOUT)) // obtain write lock
          throw new LockObtainFailedException("Index locked for write: " + writeLock);
        this.writeLock = writeLock;

        // we have to check whether index has changed since this reader was opened.
        // if so, this reader is no longer valid for
View Full Code Here

          String LOCK_FILE = "write.lock";
          String dicHome = p
              .getProperty("paoding.dic.home.absolute.path");
          FSLockFactory FileLockFactory = new NativeFSLockFactory(
              dicHome);
          Lock lock = FileLockFactory.makeLock(LOCK_FILE);

          boolean obtained = false;
          try {
            obtained = lock.obtain(90000);
            if (obtained) {
              // 编译词典-对词典进行可能的处理,以符合分词器的要求
              if (compiler.shouldCompile(p)) {
                Dictionaries dictionaries = readUnCompiledDictionaries(p);
                Paoding tempPaoding = createPaodingWithKnives(p);
                setDictionaries(tempPaoding, dictionaries);
                compiler.compile(dictionaries, tempPaoding, p);
              }

              // 使用编译后的词典
              final Dictionaries dictionaries = compiler
                  .readCompliedDictionaries(p);
              setDictionaries(finalPaoding, dictionaries);

              // 启动字典动态转载/卸载检测器
              // 侦测时间间隔(秒)。默认为60秒。如果设置为0或负数则表示不需要进行检测
              String intervalStr = getProperty(p,
                  Constants.DIC_DETECTOR_INTERVAL);
              int interval = Integer.parseInt(intervalStr);
              if (interval > 0) {
                dictionaries.startDetecting(interval,
                    new DifferenceListener() {
                      public void on(Difference diff)
                          throws Exception {
                        dictionaries.stopDetecting();
                       
                        // 此处调用run方法,以当检测到**编译后**的词典变更/删除/增加时,
                        // 重新编译源词典、重新创建并启动dictionaries自检测
                        run();
                      }
                    });
              }
            }
          } catch (LockObtainFailedException ex) {
            log.error("Obtain " + LOCK_FILE + " in " + dicHome
                + " failed:" + ex.getMessage());
            throw ex;
          } catch (IOException ex) {
            log.error("Obtain " + LOCK_FILE + " in " + dicHome
                + " failed:" + ex.getMessage());
            throw ex;
          } finally {
            if (obtained) {
              try {
                lock.release();
              } catch (Exception ex) {

              }
            }
          }
View Full Code Here

TOP

Related Classes of org.apache.lucene.store.Lock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.