Ejemplo n.º 1
0
        /// <summary>
        /// Do not call this method directly; it is implemented for DDMConnection to call.
        ///
        /// </summary>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public final void newRecord(final DDMCallbackEvent event, final DDMDataBuffer buffer)
        public void newRecord(DDMCallbackEvent @event, DDMDataBuffer buffer)
        {
            buffer.startProcessing();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final DDMFile file = event.getFile();
            DDMFile file = @event.File;

            if (file == file_)
            {
                DDMDataBuffer nextBuffer = file.NextDataBuffer;
                // Wait to use the next buffer until our background thread is done with it.
                while (nextBuffer.Processing)         // Uses volatile variable, faster than synchronization, at the cost of a CPU loop here.
                {
                    file.nextBuffer();                // Advance.
                    nextBuffer = file.NextDataBuffer; // Check the next one.
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a multi-threaded reader to process data being read from the specified file
        /// using the specified record format. </summary>
        /// <param name="format"> The record format to copy and give to each thread for it to pass to <seealso cref="#process process()"/>. </param>
        /// <param name="file"> The file being read. </param>
        /// <param name="numThreads"> The number of threads to use. This number is capped by the number of buffers in the file object, so
        /// that each thread always has at least one buffer to process, to avoid contention. Having more than one buffer per thread is fine.
        ///  </param>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public DDMThreadedReader(final DDMRecordFormat format, final DDMFile file, int numThreads)
        public DDMThreadedReader(DDMRecordFormat format, DDMFile file, int numThreads)
        {
            file_ = file;
            done_ = false;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int numBuffers = file.getBufferCount();
            int numBuffers = file.BufferCount;

            if (numThreads > numBuffers)
            {
                numThreads = numBuffers;
            }
            runners_ = new DDMReaderRunner[numThreads];
            threads_ = new Thread[numThreads];
            for (int i = 0; i < numThreads; ++i)
            {
                runners_[i] = new DDMReaderRunner(this, format, i, numThreads, numBuffers);
                threads_[i] = new Thread(runners_[i], "DDMThreadedReader-" + i);
                threads_[i].Start();
            }
        }