コード例 #1
0
ファイル: IndexReader.cs プロジェクト: raj581/Marvin
        /// <summary> Trys to acquire the WriteLock on this directory.
        /// this method is only valid if this IndexReader is directory owner.
        ///
        /// </summary>
        /// <throws>  IOException If WriteLock cannot be acquired. </throws>
        private void  AquireWriteLock()
        {
            if (stale)
            {
                throw new System.IO.IOException("IndexReader out of date and no longer valid for delete, undelete, or setNorm operations");
            }

            if (this.writeLock == null)
            {
                Lock writeLock = directory.MakeLock(IndexWriter.WRITE_LOCK_NAME);
                if (!writeLock.Obtain(IndexWriter.WRITE_LOCK_TIMEOUT))
                // obtain write lock
                {
                    throw new System.IO.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
                if (SegmentInfos.ReadCurrentVersion(directory) > segmentInfos.GetVersion())
                {
                    stale = true;
                    this.writeLock.Release();
                    this.writeLock = null;
                    throw new System.IO.IOException("IndexReader out of date and no longer valid for delete, undelete, or setNorm operations");
                }
            }
        }
コード例 #2
0
        private IndexWriter(Directory d, Analyzer a, bool create, bool closeDir)
        {
            InitBlock();
            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 System.IO.IOException("Index locked for write: " + writeLock);
            }
            this.writeLock = writeLock; // save it

            lock (directory)
            {
                // in- & inter-process sync
                new AnonymousClassWith(create, this, directory.MakeLock(IndexWriter.COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT).Run();
            }
        }