예제 #1
0
        private bool MaybeComputeNext()
        {
            state = ConsumerIteratorState.Failed;
            makeNextSemaphore.Wait();
            try
            {
                nextItem = this.MakeNext();
            }
            catch (OperationCanceledException)
            {
                state = ConsumerIteratorState.Done;
                return(false);
            }
            finally
            {
                makeNextSemaphore.Release();
            }

            if (state == ConsumerIteratorState.Done)
            {
                return(false);
            }

            state = ConsumerIteratorState.Ready;
            return(true);
        }
예제 #2
0
 private bool MaybeComputeNext()
 {
     state    = ConsumerIteratorState.Failed;
     nextItem = MakeNext();
     if (state == ConsumerIteratorState.Done)
     {
         return(false);
     }
     state = ConsumerIteratorState.Ready;
     return(true);
 }
예제 #3
0
        private Message MakeNext()
        {
            if (current == null || !current.MoveNext())
            {
                Logger.Debug("Getting new FetchedDataChunk...");
                if (consumerTimeoutMs < 0)
                {
                    currentDataChunk = this.channel.Take(cancellationToken);
                }
                else
                {
                    bool done = channel.TryTake(out currentDataChunk, consumerTimeoutMs, cancellationToken);
                    if (!done)
                    {
                        Logger.Debug("Consumer iterator timing out...");
                        state = ConsumerIteratorState.NotReady;
                        throw new ConsumerTimeoutException();
                    }
                }

                if (currentDataChunk.Equals(ZookeeperConsumerConnector.ShutdownCommand))
                {
                    Logger.Debug("Received the shutdown command");
                    channel.Add(currentDataChunk);
                    return(this.AllDone());
                }

                currentTopicInfo = currentDataChunk.TopicInfo;
                Logger.DebugFormat("CurrentTopicInfo: ConsumedOffset({0}), FetchOffset({1})",
                                   currentTopicInfo.GetConsumeOffset(), currentTopicInfo.GetFetchOffset());
                if (currentTopicInfo.GetConsumeOffset() != currentDataChunk.FetchOffset)
                {
                    Logger.ErrorFormat(
                        CultureInfo.CurrentCulture,
                        "consumed offset: {0} doesn't match fetch offset: {1} for {2}; consumer may lose data",
                        currentTopicInfo.GetConsumeOffset(),
                        currentDataChunk.FetchOffset,
                        currentTopicInfo);
                    currentTopicInfo.ResetConsumeOffset(currentDataChunk.FetchOffset);
                }

                current = currentDataChunk.Messages.GetEnumerator();
                current.MoveNext();
            }

            var item = current.Current;

            consumedOffset = item.Offset;
            return(item.Message);
        }
예제 #4
0
 private Message AllDone()
 {
     this.state = ConsumerIteratorState.Done;
     return(null);
 }
예제 #5
0
 /// <summary>
 /// Resets the enumerator's state to NotReady.
 /// </summary>
 public void Reset()
 {
     state = ConsumerIteratorState.NotReady;
 }
 private MessageAndOffset AllDone()
 {
     state = ConsumerIteratorState.Done;
     return(null);
 }
예제 #7
0
 private TData AllDone()
 {
     state = ConsumerIteratorState.Done;
     return(default(TData));
 }