Class ApplicationEventHandler
java.lang.Object
org.apache.kafka.clients.consumer.internals.events.ApplicationEventHandler
- All Implemented Interfaces:
Closeable,AutoCloseable
An event handler that receives
application events from the application thread which
are then readable from the ApplicationEventProcessor in the network thread.-
Constructor Summary
ConstructorsConstructorDescriptionApplicationEventHandler(org.apache.kafka.common.utils.LogContext logContext, org.apache.kafka.common.utils.Time time, BlockingQueue<ApplicationEvent> applicationEventQueue, Supplier<ApplicationEventProcessor> applicationEventProcessorSupplier, Supplier<NetworkClientDelegate> networkClientDelegateSupplier, Supplier<RequestManagers> requestManagersSupplier) -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(ApplicationEvent event) Add anApplicationEventto the handler and then internally invokewakeupNetworkThread()to alert the network I/O thread that it has something to process.<T> TaddAndGet(CompletableApplicationEvent<T> event, org.apache.kafka.common.utils.Timer timer) Add aCompletableApplicationEventto the handler.voidclose()voidlongReturns the delay for which the application thread can safely wait before it should be responsive to results from the request managers.voidWakeup thenetwork I/O threadto pull the next event(s) from the queue.
-
Constructor Details
-
ApplicationEventHandler
public ApplicationEventHandler(org.apache.kafka.common.utils.LogContext logContext, org.apache.kafka.common.utils.Time time, BlockingQueue<ApplicationEvent> applicationEventQueue, Supplier<ApplicationEventProcessor> applicationEventProcessorSupplier, Supplier<NetworkClientDelegate> networkClientDelegateSupplier, Supplier<RequestManagers> requestManagersSupplier)
-
-
Method Details
-
add
Add anApplicationEventto the handler and then internally invokewakeupNetworkThread()to alert the network I/O thread that it has something to process.- Parameters:
event- AnApplicationEventcreated by the application thread
-
wakeupNetworkThread
public void wakeupNetworkThread()Wakeup thenetwork I/O threadto pull the next event(s) from the queue. -
maximumTimeToWait
public long maximumTimeToWait()Returns the delay for which the application thread can safely wait before it should be responsive to results from the request managers. For example, the subscription state can change when heartbeats are sent, so blocking for longer than the heartbeat interval might mean the application thread is not responsive to changes.- Returns:
- The maximum delay in milliseconds
-
addAndGet
public <T> T addAndGet(CompletableApplicationEvent<T> event, org.apache.kafka.common.utils.Timer timer) Add aCompletableApplicationEventto the handler. The method blocks waiting for the result, and will return the result value upon successful completion; otherwise throws an error. SeeCompletableApplicationEvent.get(Timer)andFuture.get(long, TimeUnit)for more details.- Type Parameters:
T- Type of return value of the event- Parameters:
event- ACompletableApplicationEventcreated by the polling threadtimer- Timer for which to wait for the event to complete- Returns:
- Value that is the result of the event
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
close
-