|
Spring Integration | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.integration.context.IntegrationObjectSupport 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,
org.springframework.scheduling.TaskScheduler taskScheduler)
Create a DelayHandler with the given default delay. |
Method Summary | |
---|---|
void |
destroy()
|
java.lang.String |
getComponentType()
Subclasses may implement this method to provide component type information. |
int |
getOrder()
|
void |
handleMessage(Message<?> message)
Handles the message if possible. |
protected void |
onInit()
Subclasses may implement this for initialization logic. |
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 |
setMessageStore(MessageStore messageStore)
Specify the MessageStore that should be used to store Messages
while awaiting the delay. |
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 org.springframework.integration.context.IntegrationObjectSupport |
---|
afterPropertiesSet, getBeanFactory, getComponentName, getConversionService, getTaskScheduler, setBeanFactory, setBeanName, setComponentName, setConversionService, setTaskScheduler, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public DelayHandler(long defaultDelay)
public DelayHandler(long defaultDelay, org.springframework.scheduling.TaskScheduler taskScheduler)
TaskScheduler
.
Method Detail |
---|
public void setDefaultDelay(long defaultDelay)
public void setDelayHeaderName(java.lang.String delayHeaderName)
public void setMessageStore(MessageStore messageStore)
MessageStore
that should be used to store Messages
while awaiting the delay.
public void setOutputChannel(MessageChannel outputChannel)
setOutputChannel
in interface MessageProducer
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.
This property will only have an effect for TaskScheduler implementations
that extend from ExecutorConfigurationSupport
.
ExecutorConfigurationSupport.setWaitForTasksToCompleteOnShutdown(boolean)
public void setOrder(int order)
public int getOrder()
getOrder
in interface org.springframework.core.Ordered
public java.lang.String getComponentType()
IntegrationObjectSupport
getComponentType
in interface NamedComponent
getComponentType
in class IntegrationObjectSupport
protected void onInit() throws java.lang.Exception
IntegrationObjectSupport
onInit
in class IntegrationObjectSupport
java.lang.Exception
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 failure of another message being sent
(e.g. a "reply" message), that failure will trigger a
MessageDeliveryException
.
handleMessage
in interface MessageHandler
message
- the message to be handledpublic void destroy() throws java.lang.Exception
destroy
in interface org.springframework.beans.factory.DisposableBean
java.lang.Exception
|
Spring Integration | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |