示例#1
0
        public override FieldsConsumer FieldsConsumer(SegmentWriteState writeState)
        {
            int id = (int)nextID.GetAndIncrement();

            // TODO -- ok to do this up front instead of
            // on close....?  should be ok?
            // Write our ID:
            string      idFileName = IndexFileNames.SegmentFileName(writeState.SegmentInfo.Name, writeState.SegmentSuffix, ID_EXTENSION);
            IndexOutput @out       = writeState.Directory.CreateOutput(idFileName, writeState.Context);
            bool        success    = false;

            try
            {
                CodecUtil.WriteHeader(@out, RAM_ONLY_NAME, VERSION_LATEST);
                @out.WriteVInt32(id);
                success = true;
            }
            finally
            {
                if (!success)
                {
                    IOUtils.DisposeWhileHandlingException(@out);
                }
                else
                {
                    IOUtils.Dispose(@out);
                }
            }

            RAMPostings       postings = new RAMPostings();
            RAMFieldsConsumer consumer = new RAMFieldsConsumer(postings);

            UninterruptableMonitor.Enter(state);
            try
            {
                state[id] = postings;
            }
            finally
            {
                UninterruptableMonitor.Exit(state);
            }
            return(consumer);
        }
 public RAMFieldsConsumer(RAMPostings postings)
 {
     this.postings = postings;
 }