T
- the type of the object that the handler is expecting.public class ConcurrentMessageHandler<T> extends java.lang.Object implements MessageHandler<T>
MessageHandler
decorator that wraps a delegate implementation in
an ExecutorService
to handle many incoming messages concurrently on
different threads. A default single-threaded executor is provided if no
ExecutorService
is provided.Constructor and Description |
---|
ConcurrentMessageHandler(MessageHandler<T> delegate)
Submits incoming handling requests on a single threaded executor to
avoid blocking the main thread.
|
ConcurrentMessageHandler(MessageHandler<T> delegate,
java.util.concurrent.ExecutorService executorService)
Allows for concurrent handling of messages by handing of the logic to
a delegate
MessageHandler but wrapping those calls within
an Executor.execute(Runnable) . |
Modifier and Type | Method and Description |
---|---|
void |
handle(T message)
Perform some action when receiving a message.
|
boolean |
shutdown()
Closes the MessageHandler and terminates the
executorService . |
public ConcurrentMessageHandler(MessageHandler<T> delegate, java.util.concurrent.ExecutorService executorService)
MessageHandler
but wrapping those calls within
an Executor.execute(Runnable)
.delegate
- the MessageHandler
to actually handle the incoming messagesexecutorService
- the ExecutorService
to submit handling requests to.public ConcurrentMessageHandler(MessageHandler<T> delegate)
delegate
- the MessageHandler
to actually handle the incoming messages/public void handle(T message)
MessageHandler
handle
in interface MessageHandler<T>
message
- the messagepublic boolean shutdown() throws java.lang.InterruptedException
executorService
.executorService
is successfully shut down.java.lang.InterruptedException
- if there is a timeout waiting for the executor service to shut down