|
Spring Data Key-Value | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.data.keyvalue.redis.listener.RedisMessageListenerContainer
public class RedisMessageListenerContainer
Container providing asynchronous behaviour for Redis message listeners. Handles the low level details of listening, converting and message dispatching.
As oppose to the low level Redis (one connection per subscription), the container uses only one connection that is 'multiplexed' for all registered listeners, the message dispatch being done through the task executor. Note the container uses the connection in a lazy fashion (the connection is used only if at least one listener is configured).
Field Summary | |
---|---|
static String |
DEFAULT_THREAD_NAME_PREFIX
Default thread name prefix: "RedisListeningContainer-". |
protected org.apache.commons.logging.Log |
logger
Logger available to subclasses |
Constructor Summary | |
---|---|
RedisMessageListenerContainer()
|
Method Summary | |
---|---|
void |
addMessageListener(MessageListener listener,
Collection<? extends Topic> topics)
Adds a message listener to the (potentially running) container. |
void |
addMessageListener(MessageListener listener,
Topic topic)
Adds a message listener to the (potentially running) container. |
void |
afterPropertiesSet()
|
protected TaskExecutor |
createDefaultTaskExecutor()
Creates a default TaskExecutor. |
void |
destroy()
|
protected void |
executeListener(MessageListener listener,
Message message,
byte[] pattern)
Execute the specified listener. |
RedisConnectionFactory |
getConnectionFactory()
Returns the connectionFactory. |
int |
getPhase()
|
protected void |
handleListenerException(Throwable ex)
Handle the given exception that arose during listener execution. |
protected void |
invokeErrorHandler(Throwable ex)
Invoke the registered ErrorHandler, if any. |
boolean |
isActive()
Return whether this container is currently active, that is, whether it has been set up but not shut down yet. |
boolean |
isAutoStartup()
|
boolean |
isRunning()
|
protected void |
processMessage(MessageListener listener,
Message message,
byte[] pattern)
Process a message received from the provider. |
void |
setBeanName(String name)
|
void |
setConnectionFactory(RedisConnectionFactory connectionFactory)
|
void |
setErrorHandler(ErrorHandler errorHandler)
Set an ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message. |
void |
setMessageListeners(Map<? extends MessageListener,Collection<? extends Topic>> listeners)
Attaches the given listeners (and their topics) to the container. |
void |
setSubscriptionExecutor(Executor subscriptionExecutor)
Sets the task execution used for subscribing to Redis channels. |
void |
setTaskExecutor(Executor taskExecutor)
Sets the task executor used for running the message listeners when messages are received. |
void |
setTopicSerializer(RedisSerializer<String> serializer)
Sets the serializer for converting the Topic s into low-level channels and patterns. |
void |
start()
|
void |
stop()
|
void |
stop(Runnable callback)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final org.apache.commons.logging.Log logger
public static final String DEFAULT_THREAD_NAME_PREFIX
Constructor Detail |
---|
public RedisMessageListenerContainer()
Method Detail |
---|
public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
protected TaskExecutor createDefaultTaskExecutor()
The default implementation builds a SimpleAsyncTaskExecutor
with the specified bean name (or the class name, if no bean name specified) as thread name prefix.
SimpleAsyncTaskExecutor.SimpleAsyncTaskExecutor(String)
public void destroy() throws Exception
destroy
in interface DisposableBean
Exception
public boolean isAutoStartup()
isAutoStartup
in interface SmartLifecycle
public void stop(Runnable callback)
stop
in interface SmartLifecycle
public int getPhase()
getPhase
in interface Phased
public boolean isRunning()
isRunning
in interface Lifecycle
public void start()
start
in interface Lifecycle
public void stop()
stop
in interface Lifecycle
protected void processMessage(MessageListener listener, Message message, byte[] pattern)
message
- pattern
- protected void executeListener(MessageListener listener, Message message, byte[] pattern)
handleListenerException(java.lang.Throwable)
public final boolean isActive()
protected void handleListenerException(Throwable ex)
The default implementation logs the exception at error level. This can be overridden in subclasses.
ex
- the exception to handleprotected void invokeErrorHandler(Throwable ex)
ex
- the uncaught error that arose during message processing.setErrorHandler(org.springframework.util.ErrorHandler)
public RedisConnectionFactory getConnectionFactory()
public void setConnectionFactory(RedisConnectionFactory connectionFactory)
connectionFactory
- The connectionFactory to set.public void setBeanName(String name)
setBeanName
in interface BeanNameAware
public void setTaskExecutor(Executor taskExecutor)
SimpleAsyncTaskExecutor
will be used by default.
The task executor can be adjusted depending on the work done by the listeners and the number of
messages coming in.
taskExecutor
- The taskExecutor to set.public void setSubscriptionExecutor(Executor subscriptionExecutor)
setTaskExecutor(Executor)
will be used. In some cases, this might be undersired as
the listening to the connection is a long running task.
Note: This implementation uses at most one long running thread (depending on whether there are any listeners registered or not)
and up to two threads during the initial registration.
subscriptionExecutor
- The subscriptionExecutor to set.public void setTopicSerializer(RedisSerializer<String> serializer)
Topic
s into low-level channels and patterns.
By default, StringRedisSerializer
is used.
serializer
- The serializer to set.public void setErrorHandler(ErrorHandler errorHandler)
public void setMessageListeners(Map<? extends MessageListener,Collection<? extends Topic>> listeners)
listeners
- map of message listeners and their associated topicspublic void addMessageListener(MessageListener listener, Collection<? extends Topic> topics)
listener
- message listenertopics
- message listener topicpublic void addMessageListener(MessageListener listener, Topic topic)
listener
- message listenertopic
- message topic
|
Spring Data Key-Value | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |