org.springframework.integration.dispatcher
Class PollingDispatcher

java.lang.Object
  extended by org.springframework.integration.dispatcher.PollingDispatcher
All Implemented Interfaces:
java.lang.Runnable, MessageSource, SubscribableSource, SchedulableTask

public class PollingDispatcher
extends java.lang.Object
implements SchedulableTask, SubscribableSource

Author:
Mark Fisher

Field Summary
static long DEFAULT_RECEIVE_TIMEOUT
           
private  MessageDispatcher dispatcher
           
private  org.apache.commons.logging.Log logger
           
static int MAX_MESSAGES_UNBOUNDED
           
private  int maxMessagesPerPoll
           
private  MessageExchangeTemplate messageExchangeTemplate
           
private  Schedule schedule
           
private  PollableSource<?> source
           
 
Constructor Summary
PollingDispatcher(PollableSource<?> source, Schedule schedule)
          Create a PollingDispatcher for the provided PollableSource.
PollingDispatcher(PollableSource<?> source, Schedule schedule, MessageDispatcher dispatcher)
           
PollingDispatcher(PollableSource<?> source, Schedule schedule, MessageDispatcher dispatcher, MessageExchangeTemplate messageExchangeTemplate)
           
 
Method Summary
private  MessageExchangeTemplate createDefaultTemplate()
           
 Schedule getSchedule()
           
 void run()
           
 void setMaxMessagesPerPoll(int maxMessagesPerPoll)
          Set the maximum number of messages to receive for each poll.
 void setReceiveTimeout(long receiveTimeout)
          Specify the timeout to use when receiving from the source (in milliseconds).
 void setSendTimeout(long sendTimeout)
          Specify the timeout to use when sending to a target (in milliseconds).
 boolean subscribe(MessageTarget target)
          Register a MessageTarget as a subscriber to this source.
 java.lang.String toString()
           
 boolean unsubscribe(MessageTarget target)
          Remove a MessageTarget from the subscribers of this source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_MESSAGES_UNBOUNDED

public static final int MAX_MESSAGES_UNBOUNDED
See Also:
Constant Field Values

DEFAULT_RECEIVE_TIMEOUT

public static final long DEFAULT_RECEIVE_TIMEOUT
See Also:
Constant Field Values

logger

private final org.apache.commons.logging.Log logger

source

private final PollableSource<?> source

dispatcher

private final MessageDispatcher dispatcher

schedule

private final Schedule schedule

messageExchangeTemplate

private final MessageExchangeTemplate messageExchangeTemplate

maxMessagesPerPoll

private volatile int maxMessagesPerPoll
Constructor Detail

PollingDispatcher

public PollingDispatcher(PollableSource<?> source,
                         Schedule schedule)
Create a PollingDispatcher for the provided PollableSource. It can be scheduled according to the specified Schedule.


PollingDispatcher

public PollingDispatcher(PollableSource<?> source,
                         Schedule schedule,
                         MessageDispatcher dispatcher)

PollingDispatcher

public PollingDispatcher(PollableSource<?> source,
                         Schedule schedule,
                         MessageDispatcher dispatcher,
                         MessageExchangeTemplate messageExchangeTemplate)
Method Detail

setReceiveTimeout

public void setReceiveTimeout(long receiveTimeout)
Specify the timeout to use when receiving from the source (in milliseconds). Note that this value will only be applicable if the source is an instance of BlockingSource.

A negative value indicates that receive calls should block indefinitely, and that is the default behavior.


setSendTimeout

public void setSendTimeout(long sendTimeout)
Specify the timeout to use when sending to a target (in milliseconds). Note that this value will only be applicable if the target is an instance of BlockingTarget.


setMaxMessagesPerPoll

public void setMaxMessagesPerPoll(int maxMessagesPerPoll)
Set the maximum number of messages to receive for each poll. A non-positive value indicates that polling should repeat as long as non-null messages are being received and successfully sent.

The default is unbounded.

See Also:
MAX_MESSAGES_UNBOUNDED

subscribe

public boolean subscribe(MessageTarget target)
Description copied from interface: SubscribableSource
Register a MessageTarget as a subscriber to this source.

Specified by:
subscribe in interface SubscribableSource

unsubscribe

public boolean unsubscribe(MessageTarget target)
Description copied from interface: SubscribableSource
Remove a MessageTarget from the subscribers of this source.

Specified by:
unsubscribe in interface SubscribableSource

getSchedule

public Schedule getSchedule()
Specified by:
getSchedule in interface SchedulableTask

run

public void run()
Specified by:
run in interface java.lang.Runnable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

createDefaultTemplate

private MessageExchangeTemplate createDefaultTemplate()