K
- the type of the keypublic class AsyncExecutionController<K> extends Object implements StateRequestHandler
It is responsible for:
MailboxExecutor.yield()
to pause current operations,
allowing for the execution of callbacks (mails in Mailbox).Constructor and Description |
---|
AsyncExecutionController(MailboxExecutor mailboxExecutor,
StateExecutor stateExecutor,
int maxParallelism,
int batchSize,
long bufferTimeout,
int maxInFlightRecords) |
Modifier and Type | Method and Description |
---|---|
RecordContext<K> |
buildContext(Object record,
K key)
Build a new context based on record and key.
|
void |
drainInflightRecords(int targetNum)
A helper function to drain in-flight records util
inFlightRecordNum within the limit
of given targetNum . |
int |
getInFlightRecordNum() |
<IN,OUT> InternalStateFuture<OUT> |
handleRequest(State state,
StateRequestType type,
IN payload)
Submit a
StateRequest to this AsyncExecutionController and trigger it if needed. |
void |
setCurrentContext(RecordContext<K> switchingContext)
Each time before a code segment (callback) is about to run in mailbox (task thread), this
method should be called to switch a context in AEC.
|
void |
setStateExecutor(StateExecutor stateExecutor) |
void |
syncPointRequestWithCallback(ThrowingRunnable<Exception> callback)
A helper to request a
StateRequestType.SYNC_POINT and run a callback if it finishes
(once the record is not blocked). |
public AsyncExecutionController(MailboxExecutor mailboxExecutor, StateExecutor stateExecutor, int maxParallelism, int batchSize, long bufferTimeout, int maxInFlightRecords)
public RecordContext<K> buildContext(Object record, K key)
KeyAccountingUnit
.record
- the given record.key
- the given key.public void setCurrentContext(RecordContext<K> switchingContext)
switchingContext
- the context to switch.public <IN,OUT> InternalStateFuture<OUT> handleRequest(@Nullable State state, StateRequestType type, @Nullable IN payload)
StateRequest
to this AsyncExecutionController and trigger it if needed.handleRequest
in interface StateRequestHandler
state
- the state to request. Could be null
if the type is StateRequestType.SYNC_POINT
.type
- the type of this request.payload
- the payload input for this request.public void syncPointRequestWithCallback(ThrowingRunnable<Exception> callback)
StateRequestType.SYNC_POINT
and run a callback if it finishes
(once the record is not blocked).callback
- the callback to run if it finishes (once the record is not blocked).public void drainInflightRecords(int targetNum)
inFlightRecordNum
within the limit
of given targetNum
.targetNum
- the target inFlightRecordNum
to achieve.@VisibleForTesting public void setStateExecutor(StateExecutor stateExecutor)
@VisibleForTesting public int getInFlightRecordNum()
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.