Class AbstractParallelEoSStreamProcessor<K,V>
java.lang.Object
io.confluent.parallelconsumer.internal.AbstractParallelEoSStreamProcessor<K,V>
- All Implemented Interfaces:
DrainingCloseable,ParallelConsumer<K,V>,Closeable,AutoCloseable,org.apache.kafka.clients.consumer.ConsumerRebalanceListener
- Direct Known Subclasses:
ExternalEngine,ParallelEoSStreamProcessor
public abstract class AbstractParallelEoSStreamProcessor<K,V> extends Object implements ParallelConsumer<K,V>, org.apache.kafka.clients.consumer.ConsumerRebalanceListener, Closeable
- See Also:
ParallelConsumer
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.confluent.parallelconsumer.internal.DrainingCloseable
DrainingCloseable.DrainingModeNested classes/interfaces inherited from interface io.confluent.parallelconsumer.ParallelConsumer
ParallelConsumer.Tuple<L,R> -
Field Summary
Fields Modifier and Type Field Description protected DynamicLoadFactordynamicExtraLoadFactorMultiple ofParallelConsumerOptions.getMaxConcurrency()to have in our processing queue, in order to make sure threads always have work to do.static StringMDC_INSTANCE_IDstatic StringMDC_OFFSET_MARKERprotected ParallelConsumerOptionsoptionsprotected WorkManager<K,V>wmprotected ThreadPoolExecutorworkerThreadPoolThe pool which is used for running the users's supplied functionFields inherited from interface io.confluent.parallelconsumer.internal.DrainingCloseable
DEFAULT_TIMEOUT -
Constructor Summary
Constructors Constructor Description AbstractParallelEoSStreamProcessor(ParallelConsumerOptions<K,V> newOptions)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 Type Method Description voidaddLoopEndCallBack(Runnable r)Plugin a function to run at the end of each main loop.protected voidaddToMailbox(WorkContainer<K,V> wc)protected voidaddToMailBoxOnUserFunctionSuccess(WorkContainer<K,V> wc, List<?> resultsFromUserFunction)protected intcalculateQuantityToRequest()protected voidcheckPipelinePressure()Checks the system has enough pressure in the pipeline of work, if not attempts to step up the load factor.voidclose()Close the system, without draining.voidclose(Duration timeout, DrainingCloseable.DrainingMode drainMode)Close the consumer.ExceptiongetFailureCause()Optional<String>getMyId()Optional ID of this instance.intgetNumberOfAssignedPartitions()protected ParallelConsumerOptionsgetOptions()protected Optional<ProducerManager<K,V>>getProducerManager()protected intgetQueueTargetLoaded()protected intgetTargetOutForProcessing()DurationgetTimeBetweenCommits()Time between commits.WorkManager<K,V>getWm()protected BlockingQueue<io.confluent.parallelconsumer.internal.AbstractParallelEoSStreamProcessor.ControllerEventMessage<K,V>>getWorkMailBox()Collection of work waiting to bebooleanisClosedOrFailed()voidnotifySomethingToDo()Early notify of work arrived.voidonPartitionsAssigned(Collection<org.apache.kafka.common.TopicPartition> partitions)Delegate toWorkManagervoidonPartitionsLost(Collection<org.apache.kafka.common.TopicPartition> partitions)Delegate toWorkManagervoidonPartitionsRevoked(Collection<org.apache.kafka.common.TopicPartition> partitions)Commit our offsetsprotected voidonUserFunctionSuccess(WorkContainer<K,V> wc, List<?> resultsFromUserFunction)voidregisterWork(EpochAndRecordsMap<K,V> polledRecords)voidrequestCommitAsap()Request a commit as soon as possible (ASAP), overriding other constraints.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.voidsetLongPollTimeout(Duration ofMillis)voidsetMyId(Optional<String> myId)Optional ID of this instance.voidsetTimeBetweenCommits(Duration timeBetweenCommits)Time between commits.protected ThreadPoolExecutorsetupWorkerPool(int poolSize)protected <R> voidsubmitWorkToPool(Function<PollContextInternal<K,V>,List<R>> usersFunction, Consumer<R> callback, List<WorkContainer<K,V>> workToProcess)Submit a piece of work to the processing pool.voidsubscribe(Collection<String> topics)voidsubscribe(Collection<String> topics, org.apache.kafka.clients.consumer.ConsumerRebalanceListener callback)voidsubscribe(Pattern pattern)voidsubscribe(Pattern pattern, org.apache.kafka.clients.consumer.ConsumerRebalanceListener callback)protected <R> voidsupervisorLoop(Function<PollContextInternal<K,V>,List<R>> userFunctionWrapped, Consumer<R> callback)Supervisor loop for the main loop.voidwaitForProcessedNotCommitted(Duration timeout)Deprecated.no longer used, will be removed in next versionlongworkRemaining()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, waitMethods inherited from interface io.confluent.parallelconsumer.internal.DrainingCloseable
closeDontDrainFirst, closeDontDrainFirst, closeDrainFirst, closeDrainFirst
-
Field Details
-
MDC_INSTANCE_ID
- See Also:
- Constant Field Values
-
MDC_OFFSET_MARKER
- See Also:
- Constant Field Values
-
options
-
workerThreadPool
The pool which is used for running the users's 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
Construct the AsyncConsumer by wrapping this passed in conusmer and producer, which can be configured any which way as per normal.- See Also:
ParallelConsumerOptions
-
-
Method Details
-
isClosedOrFailed
public boolean isClosedOrFailed() -
getFailureCause
- Returns:
- if the system failed, returns the recorded reason.
-
setupWorkerPool
-
subscribe
- Specified by:
subscribein interfaceParallelConsumer<K,V>- See Also:
KafkaConsumer.subscribe(Collection)
-
subscribe
- Specified by:
subscribein interfaceParallelConsumer<K,V>- See Also:
KafkaConsumer.subscribe(Pattern)
-
subscribe
public void subscribe(Collection<String> topics, org.apache.kafka.clients.consumer.ConsumerRebalanceListener callback)- Specified by:
subscribein interfaceParallelConsumer<K,V>- See Also:
KafkaConsumer.subscribe(Collection, ConsumerRebalanceListener)
-
subscribe
public void subscribe(Pattern pattern, org.apache.kafka.clients.consumer.ConsumerRebalanceListener callback)- Specified by:
subscribein 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:
onPartitionsRevokedin interfaceorg.apache.kafka.clients.consumer.ConsumerRebalanceListener
-
onPartitionsAssigned
Delegate toWorkManager- Specified by:
onPartitionsAssignedin interfaceorg.apache.kafka.clients.consumer.ConsumerRebalanceListener- See Also:
WorkManager.onPartitionsAssigned(java.util.Collection<org.apache.kafka.common.TopicPartition>)
-
onPartitionsLost
Delegate toWorkManager- Specified by:
onPartitionsLostin interfaceorg.apache.kafka.clients.consumer.ConsumerRebalanceListener- See Also:
WorkManager.onPartitionsAssigned(java.util.Collection<org.apache.kafka.common.TopicPartition>)
-
close
public void close()Close the system, without draining.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceDrainingCloseable- See Also:
State.draining
-
close
Description copied from interface:DrainingCloseableClose the consumer.- Specified by:
closein 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)Supervisor loop for the main loop.- See Also:
supervisorLoop(Function, Consumer)
-
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
WorkContainerto 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. -
runUserFunction
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. -
addToMailBoxOnUserFunctionSuccess
protected void addToMailBoxOnUserFunctionSuccess(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(),blockableControlThread
-
workRemaining
public long workRemaining()Description copied from interface:DrainingCloseableOf the records consumed from the broker, how many do we have remaining in our local queues- Specified by:
workRemainingin 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. -
getOptions
-
setTimeBetweenCommits
Time between commits. Using a higher frequency will put more load on the brokers. -
getTimeBetweenCommits
Time between commits. Using a higher frequency will put more load on the brokers. -
getProducerManager
-
getWm
-
getWorkMailBox
protected BlockingQueue<io.confluent.parallelconsumer.internal.AbstractParallelEoSStreamProcessor.ControllerEventMessage<K,V>> getWorkMailBox()Collection of work waiting to be -
getNumberOfAssignedPartitions
public int getNumberOfAssignedPartitions() -
setMyId
Optional ID of this instance. Useful for testing. -
getMyId
Optional ID of this instance. Useful for testing.
-