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); }
private bool MaybeComputeNext() { state = ConsumerIteratorState.Failed; nextItem = MakeNext(); if (state == ConsumerIteratorState.Done) { return(false); } state = ConsumerIteratorState.Ready; return(true); }
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); }
private Message AllDone() { this.state = ConsumerIteratorState.Done; return(null); }
/// <summary> /// Resets the enumerator's state to NotReady. /// </summary> public void Reset() { state = ConsumerIteratorState.NotReady; }
private MessageAndOffset AllDone() { state = ConsumerIteratorState.Done; return(null); }
private TData AllDone() { state = ConsumerIteratorState.Done; return(default(TData)); }