|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.integration.handler.DelayHandler
public class DelayHandler
A MessageHandler
that is capable of delaying the continuation of a
Message flow based on the presence of a delay header on an inbound Message
or a default delay value configured on this handler. Note that the
continuation of the flow is delegated to a TaskScheduler
, and
therefore, the calling thread does not block. The advantage of this approach
is that many delays can be managed concurrently, even very long delays,
without producing a buildup of blocked Threads.
One thing to keep in mind, however, is that any active transactional context will not propagate from the original sender to the eventual recipient. This is a side-effect of passing the Message to the output channel after the delay with a different Thread in control.
When this handler's 'delayHeaderName' property is configured, that value, if
present on a Message, will take precedence over the handler's 'defaultDelay'
value. The actual header value may be a long, a String that can be parsed
as a long, or a Date. If it is a long, it will be interpreted as the length
of time to delay in milliseconds counting from the current time (e.g. a
value of 5000 indicates that the Message can be released as soon as five
seconds from the current time). If the value is a Date, it will be
delayed at least until that Date occurs (i.e. the delay in that case is
equivalent to headerDate.getTime() - new Date().getTime()
).
Field Summary |
---|
Fields inherited from interface org.springframework.core.Ordered |
---|
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE |
Constructor Summary | |
---|---|
DelayHandler(long defaultDelay)
Create a DelayHandler with the given default delay. |
|
DelayHandler(long defaultDelay,
java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
Create a DelayHandler with the given default delay. |
Method Summary | |
---|---|
void |
destroy()
|
int |
getOrder()
|
void |
handleMessage(Message<?> message)
Handles the message if possible. |
void |
setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
|
void |
setDefaultDelay(long defaultDelay)
Set the default delay in milliseconds. |
void |
setDelayHeaderName(java.lang.String delayHeaderName)
Specify the name of the header that should be checked for a delay period (in milliseconds) or a Date to delay until. |
void |
setOrder(int order)
|
void |
setOutputChannel(MessageChannel outputChannel)
Set the output channel for this handler. |
void |
setSendTimeout(long sendTimeout)
Set the timeout for sending reply Messages. |
void |
setWaitForTasksToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Set whether to wait for scheduled tasks to complete on shutdown. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DelayHandler(long defaultDelay)
public DelayHandler(long defaultDelay, java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
ScheduledExecutorService
.
Method Detail |
---|
public void setDefaultDelay(long defaultDelay)
public void setDelayHeaderName(java.lang.String delayHeaderName)
public void setOutputChannel(MessageChannel outputChannel)
public void setSendTimeout(long sendTimeout)
public void setWaitForTasksToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Default is "false". Switch this to "true" if you prefer fully completed tasks at the expense of a longer shutdown phase.
ExecutorService.shutdown()
,
ExecutorService.shutdownNow()
public void setOrder(int order)
public int getOrder()
getOrder
in interface org.springframework.core.Ordered
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException
setBeanFactory
in interface org.springframework.beans.factory.BeanFactoryAware
org.springframework.beans.BeansException
public final void handleMessage(Message<?> message)
MessageHandler
MessageRejectedException
e.g.
in case of a Selective Consumer. When a consumer tries to handle a
message, but fails to do so, a MessageHandlingException
is
thrown. In the last case it is recommended to treat the message as tainted
and go into an error scenario.
When the handling results in a message being sent failure to send that
message will result in a MessageDeliveryException
.
handleMessage
in interface MessageHandler
message
- the message to be handledpublic void destroy()
destroy
in interface org.springframework.beans.factory.DisposableBean
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |