Class ListenerUtils
java.lang.Object
org.springframework.kafka.listener.ListenerUtils
Listener utilities.
- Since:
- 2.0
- Author:
- Gary Russell, Francois Rosiere, Antonio Tomac, Wang Zhiyang
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
conditionalSleep
(Supplier<Boolean> shouldSleepCondition, long interval) Sleep for the desired timeout, as long as shouldSleepCondition supplies true.static org.apache.kafka.clients.consumer.OffsetAndMetadata
createOffsetAndMetadata
(MessageListenerContainer container, long offset) Create a newOffsetAndMetadata
using the given container and offset.static ListenerType
determineListenerType
(Object listener) Determine the type of the listener.static void
stoppableSleep
(MessageListenerContainer container, long interval) Sleep for the desired timeout, as long as the container continues to run.static void
unrecoverableBackOff
(BackOff backOff, ThreadLocal<BackOffExecution> executions, ThreadLocal<Long> lastIntervals, MessageListenerContainer container) Deprecated, for removal: This API element is subject to removal in a future version.static void
unrecoverableBackOff
(BackOff backOff, Map<Thread, BackOffExecution> executions, Map<Thread, Long> lastIntervals, MessageListenerContainer container) Sleep according to theBackOff
; when theBackOffExecution
returnsBackOffExecution.STOP
sleep for the previous backOff.
-
Method Details
-
determineListenerType
Determine the type of the listener.- Parameters:
listener
- the listener.- Returns:
- the
ListenerType
.
-
unrecoverableBackOff
@Deprecated(since="3.1", forRemoval=true) public static void unrecoverableBackOff(BackOff backOff, ThreadLocal<BackOffExecution> executions, ThreadLocal<Long> lastIntervals, MessageListenerContainer container) throws InterruptedException Deprecated, for removal: This API element is subject to removal in a future version.Sleep according to theBackOff
; when theBackOffExecution
returnsBackOffExecution.STOP
sleep for the previous backOff.- Parameters:
backOff
- theBackOff
to create a newBackOffExecution
.executions
- a thread local containing theBackOffExecution
for this thread.lastIntervals
- a thread local containing the previousBackOff
interval for this thread.container
- the container or parent container.- Throws:
InterruptedException
- if the thread is interrupted.- Since:
- 2.7
-
unrecoverableBackOff
public static void unrecoverableBackOff(BackOff backOff, Map<Thread, BackOffExecution> executions, Map<Thread, throws InterruptedExceptionLong> lastIntervals, MessageListenerContainer container) Sleep according to theBackOff
; when theBackOffExecution
returnsBackOffExecution.STOP
sleep for the previous backOff.- Parameters:
backOff
- theBackOff
to create a newBackOffExecution
.executions
- a thread local containing theBackOffExecution
for this thread.lastIntervals
- a thread local containing the previousBackOff
interval for this thread.container
- the container or parent container.- Throws:
InterruptedException
- if the thread is interrupted.- Since:
- 3.1
-
stoppableSleep
public static void stoppableSleep(MessageListenerContainer container, long interval) throws InterruptedException Sleep for the desired timeout, as long as the container continues to run.- Parameters:
container
- the container.interval
- the timeout.- Throws:
InterruptedException
- if the thread is interrupted.- Since:
- 2.7
-
conditionalSleep
public static void conditionalSleep(Supplier<Boolean> shouldSleepCondition, long interval) throws InterruptedException Sleep for the desired timeout, as long as shouldSleepCondition supplies true.- Parameters:
shouldSleepCondition
- to.interval
- the timeout.- Throws:
InterruptedException
- if the thread is interrupted.- Since:
- 3.0.9
-
createOffsetAndMetadata
public static org.apache.kafka.clients.consumer.OffsetAndMetadata createOffsetAndMetadata(MessageListenerContainer container, long offset) Create a newOffsetAndMetadata
using the given container and offset.- Parameters:
container
- a container.offset
- an offset.- Returns:
- an offset and metadata.
- Since:
- 2.8.6
-
unrecoverableBackOff(BackOff, Map, Map, MessageListenerContainer)
.