Class AbstractFetch
java.lang.Object
org.apache.kafka.clients.consumer.internals.AbstractFetch
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
Fetcher,FetchRequestManager
AbstractFetch represents the basic state and logic for record fetching processing.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceDefines the contract for handling fetch responses from brokers. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.kafka.common.utils.BufferSupplierprotected final FetchBufferprotected final FetchConfigprotected final org.apache.kafka.common.utils.LogContextprotected final ConsumerMetadataprotected final FetchMetricsManagerprotected final SubscriptionStateprotected final org.apache.kafka.common.utils.Time -
Constructor Summary
ConstructorsConstructorDescriptionAbstractFetch(org.apache.kafka.common.utils.LogContext logContext, ConsumerMetadata metadata, SubscriptionState subscriptions, FetchConfig fetchConfig, FetchBuffer fetchBuffer, FetchMetricsManager metricsManager, org.apache.kafka.common.utils.Time time, org.apache.kafka.clients.ApiVersions apiVersions) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidclose(org.apache.kafka.common.utils.Timer timer) protected voidcloseInternal(org.apache.kafka.common.utils.Timer timer) This method is called byclose(Timer)which is guarded by theIdempotentCloser) such as to only be executed once the first time that any of theclose()methods are called.protected org.apache.kafka.common.requests.FetchRequest.BuildercreateFetchRequest(org.apache.kafka.common.Node fetchTarget, org.apache.kafka.clients.FetchSessionHandler.FetchRequestData requestData) Creates a newfetch requestin preparation for sending to the Kafka cluster.voidhandleCloseFetchSessionFailure(org.apache.kafka.common.Node fetchTarget, org.apache.kafka.clients.FetchSessionHandler.FetchRequestData data, Throwable t) protected voidhandleCloseFetchSessionSuccess(org.apache.kafka.common.Node fetchTarget, org.apache.kafka.clients.FetchSessionHandler.FetchRequestData data, org.apache.kafka.clients.ClientResponse ignored) protected voidhandleFetchFailure(org.apache.kafka.common.Node fetchTarget, org.apache.kafka.clients.FetchSessionHandler.FetchRequestData data, Throwable t) Implements the core logic for a failed fetch response.protected voidhandleFetchSuccess(org.apache.kafka.common.Node fetchTarget, org.apache.kafka.clients.FetchSessionHandler.FetchRequestData data, org.apache.kafka.clients.ClientResponse resp) Implements the core logic for a successful fetch response.booleanReturn whether we have any completed fetches that are fetchable.protected abstract booleanisUnavailable(org.apache.kafka.common.Node node) Check if the node is disconnected and unavailable for immediate reconnection (i.e.protected abstract voidmaybeThrowAuthFailure(org.apache.kafka.common.Node node) Checks for an authentication error on a given node and throws the exception if it exists.protected Map<org.apache.kafka.common.Node, org.apache.kafka.clients.FetchSessionHandler.FetchRequestData> protected Map<org.apache.kafka.common.Node, org.apache.kafka.clients.FetchSessionHandler.FetchRequestData> Create fetch requests for all nodes for which we have assigned partitions that have no existing requests in flight.protected org.apache.kafka.clients.FetchSessionHandlersessionHandler(int node)
-
Field Details
-
logContext
protected final org.apache.kafka.common.utils.LogContext logContext -
metadata
-
subscriptions
-
fetchConfig
-
time
protected final org.apache.kafka.common.utils.Time time -
metricsManager
-
fetchBuffer
-
decompressionBufferSupplier
protected final org.apache.kafka.common.utils.BufferSupplier decompressionBufferSupplier -
nodesWithPendingFetchRequests
-
-
Constructor Details
-
AbstractFetch
public AbstractFetch(org.apache.kafka.common.utils.LogContext logContext, ConsumerMetadata metadata, SubscriptionState subscriptions, FetchConfig fetchConfig, FetchBuffer fetchBuffer, FetchMetricsManager metricsManager, org.apache.kafka.common.utils.Time time, org.apache.kafka.clients.ApiVersions apiVersions)
-
-
Method Details
-
maybeThrowAuthFailure
protected abstract void maybeThrowAuthFailure(org.apache.kafka.common.Node node) Checks for an authentication error on a given node and throws the exception if it exists.- Parameters:
node-Nodeto check for a previousAuthenticationException; if found it is thrown- See Also:
-
hasAvailableFetches
public boolean hasAvailableFetches()Return whether we have any completed fetches that are fetchable. This method is thread-safe.- Returns:
- true if there are completed fetches that can be returned, false otherwise
-
handleFetchSuccess
protected void handleFetchSuccess(org.apache.kafka.common.Node fetchTarget, org.apache.kafka.clients.FetchSessionHandler.FetchRequestData data, org.apache.kafka.clients.ClientResponse resp) Implements the core logic for a successful fetch response.- Parameters:
fetchTarget-Nodefrom which the fetch data was requesteddata-FetchSessionHandler.FetchRequestDatathat represents the session dataresp-ClientResponsefrom which theFetchResponsewill be retrieved
-
handleFetchFailure
protected void handleFetchFailure(org.apache.kafka.common.Node fetchTarget, org.apache.kafka.clients.FetchSessionHandler.FetchRequestData data, Throwable t) Implements the core logic for a failed fetch response.- Parameters:
fetchTarget-Nodefrom which the fetch data was requesteddata-FetchSessionHandler.FetchRequestDatafrom requestt-Throwablerepresenting the error that resulted in the failure
-
handleCloseFetchSessionSuccess
protected void handleCloseFetchSessionSuccess(org.apache.kafka.common.Node fetchTarget, org.apache.kafka.clients.FetchSessionHandler.FetchRequestData data, org.apache.kafka.clients.ClientResponse ignored) -
handleCloseFetchSessionFailure
public void handleCloseFetchSessionFailure(org.apache.kafka.common.Node fetchTarget, org.apache.kafka.clients.FetchSessionHandler.FetchRequestData data, Throwable t) -
createFetchRequest
protected org.apache.kafka.common.requests.FetchRequest.Builder createFetchRequest(org.apache.kafka.common.Node fetchTarget, org.apache.kafka.clients.FetchSessionHandler.FetchRequestData requestData) Creates a newfetch requestin preparation for sending to the Kafka cluster.- Parameters:
fetchTarget-Nodefrom which the fetch data will be requestedrequestData-FetchSessionHandler.FetchRequestDatathat represents the session data- Returns:
FetchRequest.Builderthat can be submitted to the broker
-
prepareCloseFetchSessionRequests
protected Map<org.apache.kafka.common.Node,org.apache.kafka.clients.FetchSessionHandler.FetchRequestData> prepareCloseFetchSessionRequests() -
prepareFetchRequests
protected Map<org.apache.kafka.common.Node,org.apache.kafka.clients.FetchSessionHandler.FetchRequestData> prepareFetchRequests()Create fetch requests for all nodes for which we have assigned partitions that have no existing requests in flight. -
sessionHandler
protected org.apache.kafka.clients.FetchSessionHandler sessionHandler(int node) -
closeInternal
protected void closeInternal(org.apache.kafka.common.utils.Timer timer) This method is called byclose(Timer)which is guarded by theIdempotentCloser) such as to only be executed once the first time that any of theclose()methods are called. Subclasses can override this method without the need for extra synchronization at the instance level.- Parameters:
timer- Timer to enforce time limit
-
close
public void close(org.apache.kafka.common.utils.Timer timer) -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable