|
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.AbstractMessageHandler org.springframework.integration.handler.AbstractReplyProducingMessageHandler org.springframework.integration.handler.DelayHandler
@ManagedResource 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.
headerDate.getTime() - new Date().getTime()
).
Field Summary |
---|
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport |
---|
logger |
Fields inherited from interface org.springframework.core.Ordered |
---|
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE |
Constructor Summary | |
---|---|
DelayHandler(java.lang.String messageGroupId)
Create a DelayHandler with the given 'messageGroupId' that is used as 'key' for MessageGroup
to store delayed Messages in the MessageGroupStore . |
|
DelayHandler(java.lang.String messageGroupId,
org.springframework.scheduling.TaskScheduler taskScheduler)
Create a DelayHandler with the given default delay. |
Method Summary | |
---|---|
java.lang.String |
getComponentType()
Subclasses may implement this method to provide component type information. |
int |
getDelayedMessageCount()
|
protected java.lang.Object |
handleRequestMessage(Message<?> requestMessage)
Checks if 'requestMessage' wasn't delayed before ( releaseMessageAfterDelay(org.springframework.integration.Message>, long) and DelayHandler.DelayedMessageWrapper ). |
void |
onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
Handles ContextRefreshedEvent to invoke reschedulePersistedMessages()
as late as possible after application context startup. |
protected void |
onInit()
Subclasses may implement this for initialization logic. |
void |
reschedulePersistedMessages()
Used for reading persisted Messages in the 'messageStore' to reschedule them e.g. |
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(MessageGroupStore messageStore)
Specify the MessageGroupStore that should be used to store Messages
while awaiting the delay. |
Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler |
---|
getMessagingTemplate, handleMessageInternal, setChannelResolver, setOutputChannel, setRequiresReply, setSendTimeout, shouldCopyRequestHeaders |
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler |
---|
getOrder, handleMessage, setOrder, setShouldTrack |
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 |
Methods inherited from interface org.springframework.integration.context.NamedComponent |
---|
getComponentName |
Constructor Detail |
---|
public DelayHandler(java.lang.String messageGroupId)
MessageGroup
to store delayed Messages in the MessageGroupStore
. The sending of Messages after
the delay will be handled by registered in the ApplicationContext default ThreadPoolTaskScheduler
.
IntegrationObjectSupport.getTaskScheduler()
public DelayHandler(java.lang.String messageGroupId, org.springframework.scheduling.TaskScheduler taskScheduler)
TaskScheduler
.
Method Detail |
---|
public void setDefaultDelay(long defaultDelay)
public void setDelayHeaderName(java.lang.String delayHeaderName)
public void setMessageStore(MessageGroupStore messageStore)
MessageGroupStore
that should be used to store Messages
while awaiting the delay.
public java.lang.String getComponentType()
IntegrationObjectSupport
getComponentType
in interface NamedComponent
getComponentType
in class AbstractMessageHandler
protected void onInit()
IntegrationObjectSupport
onInit
in class AbstractReplyProducingMessageHandler
protected java.lang.Object handleRequestMessage(Message<?> requestMessage)
releaseMessageAfterDelay(org.springframework.integration.Message>, long)
and DelayHandler.DelayedMessageWrapper
).
Than determine 'delay' for 'requestMessage' (determineDelayForMessage(org.springframework.integration.Message>)
)
and if delay > 0
schedules 'releaseMessage' task after 'delay'.
handleRequestMessage
in class AbstractReplyProducingMessageHandler
requestMessage
- - the Message which may be delayed.
null
if 'requestMessage' is delayed,
otherwise - 'payload' from 'requestMessage'.releaseMessage(org.springframework.integration.Message>)
public int getDelayedMessageCount()
getDelayedMessageCount
in interface DelayHandlerManagement
public void reschedulePersistedMessages()
reschedulePersistedMessages
in interface DelayHandlerManagement
public void onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
ContextRefreshedEvent
to invoke reschedulePersistedMessages()
as late as possible after application context startup.
Also it checks initialized
to ignore
other ContextRefreshedEvent
s which may be published
in the 'parent-child' contexts, e.g. in the Spring-MVC applications.
onApplicationEvent
in interface org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
event
- - ContextRefreshedEvent
which occurs
after Application context is completely initialized.reschedulePersistedMessages()
|
Spring Integration | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |