Class AbstractParallelEoSStreamProcessor<K,V>
- All Implemented Interfaces:
DrainingCloseable
,ParallelConsumer<K,
,V> Closeable
,AutoCloseable
,org.apache.kafka.clients.consumer.ConsumerRebalanceListener
- Direct Known Subclasses:
ExternalEngine
,ParallelEoSStreamProcessor
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.confluent.parallelconsumer.internal.DrainingCloseable
DrainingCloseable.DrainingMode
Nested classes/interfaces inherited from interface io.confluent.parallelconsumer.ParallelConsumer
ParallelConsumer.Tuple<L,
R> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DynamicLoadFactor
Multiple ofParallelConsumerOptions.getMaxConcurrency()
to have in our processing queue, in order to make sure threads always have work to do.static final String
protected final ParallelConsumerOptions
protected final WorkManager<K,
V> protected final ThreadPoolExecutor
The pool which is used for running the users' supplied functionFields inherited from interface io.confluent.parallelconsumer.internal.DrainingCloseable
DEFAULT_TIMEOUT
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractParallelEoSStreamProcessor
(ParallelConsumerOptions<K, V> newOptions) protected
AbstractParallelEoSStreamProcessor
(ParallelConsumerOptions<K, V> newOptions, PCModule<K, V> module) Construct the AsyncConsumer by wrapping this passed in conusmer and producer, which can be configured any which way as per normal. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Plugin a function to run at the end of each main loop.protected void
addToMailbox
(PollContextInternal<K, V> pollContext, WorkContainer<K, V> wc) protected void
addToMailBoxOnUserFunctionSuccess
(PollContextInternal<K, V> context, WorkContainer<K, V> wc, List<?> resultsFromUserFunction) protected int
protected void
Checks the system has enough pressure in the pipeline of work, if not attempts to step up the load factor.void
close()
Close the system, without draining.void
close
(Duration timeout, DrainingCloseable.DrainingMode drainMode) Close the consumer.protected void
Visible for testingprotected <R> void
controlLoop
(Function<PollContextInternal<K, V>, List<R>> userFunction, Consumer<R> callback) Main control loopgetMyId()
Optional ID of this instance.int
protected ParallelConsumerOptions
protected Optional<ProducerManager<K,
V>> protected int
protected int
Deprecated.getWm()
protected BlockingQueue<io.confluent.parallelconsumer.internal.AbstractParallelEoSStreamProcessor.ControllerEventMessage<K,
V>> Collection of work waiting to beboolean
protected boolean
void
Early notify of work arrived.void
onPartitionsAssigned
(Collection<org.apache.kafka.common.TopicPartition> partitions) Delegate toWorkManager
void
onPartitionsLost
(Collection<org.apache.kafka.common.TopicPartition> partitions) Cannot commit any offsets for partitions that have been `lost` (as opposed to revoked).void
onPartitionsRevoked
(Collection<org.apache.kafka.common.TopicPartition> partitions) Commit our offsetsprotected void
onUserFunctionSuccess
(WorkContainer<K, V> wc, List<?> resultsFromUserFunction) void
Pause this consumer (i.e.protected void
processWorkCompleteMailBox
(Duration timeToBlockFor) Check the work queue for work to be done, potentially blocking.void
registerWork
(EpochAndRecordsMap<K, V> polledRecords) void
Request a commit as soon as possible (ASAP), overriding other constraints.void
Resume this consumer (i.e.protected <R> List<ParallelConsumer.Tuple<org.apache.kafka.clients.consumer.ConsumerRecord<K,
V>, R>> runUserFunction
(Function<PollContextInternal<K, V>, List<R>> usersFunction, Consumer<R> callback, List<WorkContainer<K, V>> workContainerBatch) Run the supplied function.void
setLongPollTimeout
(Duration ofMillis) void
Optional ID of this instance.void
The run state of the controller.void
setTimeBetweenCommits
(Duration timeBetweenCommits) Deprecated.protected ThreadPoolExecutor
setupWorkerPool
(int poolSize) protected <R> void
submitWorkToPool
(Function<PollContextInternal<K, V>, List<R>> usersFunction, Consumer<R> callback, List<WorkContainer<K, V>> workToProcess) Submit a piece of work to the processing pool.void
subscribe
(Collection<String> topics) void
subscribe
(Collection<String> topics, org.apache.kafka.clients.consumer.ConsumerRebalanceListener callback) void
void
protected <R> void
supervisorLoop
(Function<PollContextInternal<K, V>, List<R>> userFunctionWrapped, Consumer<R> callback) Kicks off the control loop in the executor, with supervision and returns.void
waitForProcessedNotCommitted
(Duration timeout) Deprecated.no longer used, will be removed in next versionlong
Of the records consumed from the broker, how many do we have remaining in our local queuesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.confluent.parallelconsumer.internal.DrainingCloseable
closeDontDrainFirst, closeDontDrainFirst, closeDrainFirst, closeDrainFirst
-
Field Details
-
MDC_INSTANCE_ID
- See Also:
-
options
-
workerThreadPool
The pool which is used for running the users' supplied function -
wm
-
dynamicExtraLoadFactor
Multiple ofParallelConsumerOptions.getMaxConcurrency()
to have in our processing queue, in order to make sure threads always have work to do.
-
-
Constructor Details
-
AbstractParallelEoSStreamProcessor
-
AbstractParallelEoSStreamProcessor
protected AbstractParallelEoSStreamProcessor(ParallelConsumerOptions<K, V> newOptions, PCModule<K, V> module) Construct the AsyncConsumer by wrapping this passed in conusmer and producer, which can be configured any which way as per normal.- See Also:
-
-
Method Details
-
setTimeBetweenCommits
Deprecated.useParallelConsumerOptions.ParallelConsumerOptionsBuilder.commitInterval(java.time.Duration)
} instead. This will be deleted in the next major version.Sets the time between commits. Using a higher frequency will put more load on the brokers. -
getTimeBetweenCommits
Deprecated.useParallelConsumerOptions.setCommitInterval(java.time.Duration)
instead. This will be deleted in the next major version.Gets the time between commits. -
isClosedOrFailed
public boolean isClosedOrFailed() -
getFailureCause
- Returns:
- if the system failed, returns the recorded reason.
-
setupWorkerPool
-
subscribe
- Specified by:
subscribe
in interfaceParallelConsumer<K,
V> - See Also:
-
KafkaConsumer.subscribe(Collection)
-
subscribe
- Specified by:
subscribe
in interfaceParallelConsumer<K,
V> - See Also:
-
KafkaConsumer.subscribe(Pattern)
-
subscribe
public void subscribe(Collection<String> topics, org.apache.kafka.clients.consumer.ConsumerRebalanceListener callback) - Specified by:
subscribe
in interfaceParallelConsumer<K,
V> - See Also:
-
KafkaConsumer.subscribe(Collection, ConsumerRebalanceListener)
-
subscribe
public void subscribe(Pattern pattern, org.apache.kafka.clients.consumer.ConsumerRebalanceListener callback) - Specified by:
subscribe
in interfaceParallelConsumer<K,
V> - See Also:
-
KafkaConsumer.subscribe(Pattern, ConsumerRebalanceListener)
-
onPartitionsRevoked
Commit our offsetsMake sure the calling thread is the thread which performs commit - i.e. is the
OffsetCommitter
.- Specified by:
onPartitionsRevoked
in interfaceorg.apache.kafka.clients.consumer.ConsumerRebalanceListener
-
onPartitionsAssigned
Delegate toWorkManager
- Specified by:
onPartitionsAssigned
in interfaceorg.apache.kafka.clients.consumer.ConsumerRebalanceListener
- See Also:
-
onPartitionsLost
Cannot commit any offsets for partitions that have been `lost` (as opposed to revoked). Just delegate toWorkManager
for truncation.- Specified by:
onPartitionsLost
in interfaceorg.apache.kafka.clients.consumer.ConsumerRebalanceListener
- See Also:
-
close
public void close()Close the system, without draining.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceDrainingCloseable
- See Also:
-
close
Description copied from interface:DrainingCloseable
Close the consumer.- Specified by:
close
in interfaceDrainingCloseable
- Parameters:
timeout
- how long to wait before giving updrainMode
- wait for messages already consumed from the broker to be processed before closing
-
waitForProcessedNotCommitted
Deprecated.no longer used, will be removed in next versionBlock the calling thread until no more messages are being processed.Used for testing.
-
supervisorLoop
protected <R> void supervisorLoop(Function<PollContextInternal<K, V>, List<R>> userFunctionWrapped, Consumer<R> callback) Kicks off the control loop in the executor, with supervision and returns.- See Also:
-
controlLoop
protected <R> void controlLoop(Function<PollContextInternal<K, V>, throws TimeoutException, ExecutionException, InterruptedExceptionList<R>> userFunction, Consumer<R> callback) Main control loop -
submitWorkToPool
protected <R> void submitWorkToPool(Function<PollContextInternal<K, V>, List<R>> usersFunction, Consumer<R> callback, List<WorkContainer<K, V>> workToProcess) Submit a piece of work to the processing pool.- Parameters:
workToProcess
- the polled records to process
-
calculateQuantityToRequest
protected int calculateQuantityToRequest()- Returns:
- number of
WorkContainer
to try to get
-
getTargetOutForProcessing
protected int getTargetOutForProcessing() -
getQueueTargetLoaded
protected int getQueueTargetLoaded() -
checkPipelinePressure
protected void checkPipelinePressure()Checks the system has enough pressure in the pipeline of work, if not attempts to step up the load factor. -
processWorkCompleteMailBox
Check the work queue for work to be done, potentially blocking.Can be interrupted if something else needs doing.
Visible for testing.
-
isTimeToCommitNow
protected boolean isTimeToCommitNow() -
commitOffsetsThatAreReady
Visible for testing- Throws:
TimeoutException
InterruptedException
-
runUserFunction
protected <R> List<ParallelConsumer.Tuple<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>, runUserFunctionR>> (Function<PollContextInternal<K, V>, List<R>> usersFunction, Consumer<R> callback, List<WorkContainer<K, V>> workContainerBatch) Run the supplied function. -
addToMailBoxOnUserFunctionSuccess
protected void addToMailBoxOnUserFunctionSuccess(PollContextInternal<K, V> context, WorkContainer<K, V> wc, List<?> resultsFromUserFunction) -
onUserFunctionSuccess
-
addToMailbox
-
registerWork
-
notifySomethingToDo
public void notifySomethingToDo()Early notify of work arrived.Only wake up the thread if it's sleeping while polling the mail box.
- See Also:
-
processWorkCompleteMailBox(java.time.Duration)
blockableControlThread
-
workRemaining
public long workRemaining()Description copied from interface:DrainingCloseable
Of the records consumed from the broker, how many do we have remaining in our local queues- Specified by:
workRemaining
in interfaceDrainingCloseable
- Returns:
- the number of consumed but outstanding records to process
-
addLoopEndCallBack
Plugin a function to run at the end of each main loop.Useful for testing and controlling loop progression.
-
setLongPollTimeout
-
requestCommitAsap
public void requestCommitAsap()Request a commit as soon as possible (ASAP), overriding other constraints. -
pauseIfRunning
public void pauseIfRunning()Description copied from interface:ParallelConsumer
Pause this consumer (i.e. stop processing of messages).This operation only has an effect if the consumer is currently running. In all other cases calling this method will be silent a no-op.
Once the consumer is paused, the system will stop submitting work to the processing pool. Already submitted in flight work however will be finished. This includes work that is currently being processed inside a user function as well as work that has already been submitted to the processing pool but has not been picked up by a free worker yet.
General remarks:
- A paused consumer may still keep polling for new work until internal buffers are filled.
- This operation does not actively pause the subscription on the underlying Kafka Broker (compared to
KafkaConsumer#pause
). - Pending offset commits will still be performed when the consumer is paused.
- Specified by:
pauseIfRunning
in interfaceParallelConsumer<K,
V>
-
resumeIfPaused
public void resumeIfPaused()Description copied from interface:ParallelConsumer
Resume this consumer (i.e. continue processing of messages).This operation only has an effect if the consumer is currently paused. In all other cases calling this method will be a silent no-op.
- Specified by:
resumeIfPaused
in interfaceParallelConsumer<K,
V>
-
getOptions
-
getProducerManager
-
getWm
-
getWorkMailBox
protected BlockingQueue<io.confluent.parallelconsumer.internal.AbstractParallelEoSStreamProcessor.ControllerEventMessage<K,V>> getWorkMailBox()Collection of work waiting to be -
setState
The run state of the controller.- See Also:
-
getNumberOfAssignedPartitions
public int getNumberOfAssignedPartitions() -
setMyId
Optional ID of this instance. Useful for testing. -
getMyId
Optional ID of this instance. Useful for testing.
-
ParallelConsumerOptions.setCommitInterval(java.time.Duration)
instead.