コード例 #1
0
        /// <summary>
        /// Interprets a byte buffer as a set of lines and enqueues them as events.
        /// </summary>
        /// <param name="data">The buffer.</param>
        /// <param name="bytesRead">Size of the data in the buffer.</param>
        private void ProduceEvents(byte[] data, int bytesRead)
        {
            TEvent currentEvent = default(TEvent);

            // generate new lines from a buffer's worth of asynchronously read data
            IEnumerator <string> lines = this.ByteArrayToLines(data, bytesRead).GetEnumerator();

            // move to the first line, if there is one at all
            if (!lines.MoveNext())
            {
                return;
            }

            // each line corresponds to an event - enqueue them
            do
            {
                // account for empty lines (owing to possible \n as starting character)
                if (0 == lines.Current.Length)
                {
                    continue;
                }

                currentEvent = this.CreateEventFromLine(lines.Current);

                if (currentEvent == null)
                {
                    // something went wrong there
                    this.Cleanup();
                    return;
                }

                EnqueueOperationResult result = this.inputAdapter.Enqueue(ref currentEvent);

                if (EnqueueOperationResult.Full == result)
                {
                    this.inputAdapter.ReleaseEvent(ref currentEvent);

                    this.inputAdapter.Ready();

                    // wait to be resumed
                    this.readyToEnqueue.WaitOne();

                    return;
                }
            } while (lines.MoveNext());

            // kick off the next reading cycle
            this.AsyncReadEventData();
        }
コード例 #2
0
        /// <summary>
        /// Reads rows from the SQL source, and enqueues each row as an event into StreamInsight
        /// </summary>
        private void ProduceEvents()
        {
            while (true)
            {
                // if the engine asked the adapter to stop
                if (this.inputAdapter.AdapterState == AdapterState.Stopping)
                {
                    // cleanup state
                    this.Cleanup();

                    // inform the engine that the adapter has stopped
                    this.inputAdapter.Stopped();

                    // exit the worker thread
                    return;
                }

                // prepare the event - either saved from previous iteration, or a new one from the input
                if (this.currentEvent == null)
                {
                    // read a row
                    // IMPORTANT: If a runtime exception during Read inhibits a call to Cleanup(),
                    // resources will be released by Dispose() during adapter shutdown.
                    if (!this.dataReader.Read())
                    {
                        this.Cleanup();

                        // inform the engine that the adapter has stopped
                        this.inputAdapter.Stopped();

                        return;
                    }

                    // create an event from the row
                    this.currentEvent = this.CreateEventFromRow(this.dataReader);
                    if (this.currentEvent == null)
                    {
                        this.Cleanup();

                        // inform the engine that the adapter has stopped
                        this.inputAdapter.Stopped();

                        return;
                    }
                }

                // Enqueue the created event into the engine
                EnqueueOperationResult result = this.inputAdapter.Enqueue(ref this.currentEvent);

                // If the engine pushes back, the adapter is Suspended; so do this ..
                if (result == EnqueueOperationResult.Full)
                {
                    // retain the currentEvent to be handled in the next iteration

                    // inform the engine that the adapter is Ready to be Resumed
                    this.inputAdapter.Ready();

                    // exit the worker thread
                    return;
                }
            }
        }