org.mule.transport
Class AbstractPollingMessageReceiver

java.lang.Object
  extended by org.mule.transport.AbstractTransportMessageHandler
      extended by org.mule.transport.AbstractMessageReceiver
          extended by org.mule.transport.AbstractPollingMessageReceiver
All Implemented Interfaces:
Disposable, Initialisable, Lifecycle, LifecycleStateEnabled, Startable, Stoppable, MessageSource, Connectable, MessageReceiver
Direct Known Subclasses:
FileMessageReceiver, FtpMessageReceiver, MessageProcessorPollingMessageReceiver, PollingHttpMessageReceiver, PollingTcpMessageReceiver, RetrieveMessageReceiver, RmiMessageReceiver, SftpMessageReceiver, StdioMessageReceiver, TransactedPollingMessageReceiver, XmppPollingMessageReceiver

public abstract class AbstractPollingMessageReceiver
extends AbstractMessageReceiver

AbstractPollingMessageReceiver implements a base class for polling message receivers. The receiver provides a poll() method that implementations must implement to execute their custom code. Note that the receiver will not poll if the associated connector is not started.


Field Summary
static long DEFAULT_POLL_FREQUENCY
           
static TimeUnit DEFAULT_POLL_TIMEUNIT
           
static long DEFAULT_STARTUP_DELAY
           
protected  Map<ScheduledFuture,PollingReceiverWorker> schedules
           
 
Fields inherited from class org.mule.transport.AbstractMessageReceiver
defaultInboundTransformers, defaultResponseTransformers, flowConstruct, listener, receiverKey, replyToHandler
 
Fields inherited from class org.mule.transport.AbstractTransportMessageHandler
connected, connector, endpoint, lifecycleManager, logger, muleMessageFactory, retryTemplate
 
Fields inherited from interface org.mule.api.lifecycle.Initialisable
PHASE_NAME
 
Fields inherited from interface org.mule.api.lifecycle.Startable
PHASE_NAME
 
Fields inherited from interface org.mule.api.lifecycle.Stoppable
PHASE_NAME
 
Fields inherited from interface org.mule.api.lifecycle.Disposable
PHASE_NAME
 
Constructor Summary
AbstractPollingMessageReceiver(Connector connector, FlowConstruct flowConstruct, InboundEndpoint endpoint)
           
 
Method Summary
protected  PollingReceiverWorker createWork()
           
 void disableNativeScheduling()
           
protected  void doStart()
           
protected  void doStop()
           
protected  int getBatchSize(int available)
          The preferred number of messages to process in the current batch.
 long getFrequency()
           
 TimeUnit getTimeUnit()
           
 void performPoll()
          Check whether polling should take place on this instance.
protected abstract  void poll()
           
protected  boolean pollOnPrimaryInstanceOnly()
          If this returns true for a transport, polling for that transport takes place only on the primary instance.
protected  void schedule()
          This method registers this receiver for periodic polling ticks with the connectors scheduler.
 void setFrequency(long value)
           
 void setTimeUnit(TimeUnit timeUnit)
           
protected  void unschedule()
          This method cancels the schedules which were created in schedule().
 
Methods inherited from class org.mule.transport.AbstractMessageReceiver
applyInboundTransformers, applyResponseTransformers, connectHandler, createExecutionTemplate, createLifecycleManager, createMuleEvent, doDispose, doStartHandler, getConnectEventId, getConnectionDescription, getEndpoint, getEndpointURI, getFlowConstruct, getReceiverKey, getReplyToHandler, getWorkManager, handleUnacceptedFilter, initialise, processMessage, propagateRootMessageIdProperty, routeEvent, routeMessage, routeMessage, routeMessage, routeMessage, routeMessage, setEndpoint, setListener, setReceiverKey, shouldConsumeInEveryNode, toString, warnIfMuleClientSendUsed
 
Methods inherited from class org.mule.transport.AbstractTransportMessageHandler
activate, connect, createMuleMessage, createMuleMessage, createMuleMessage, createMuleMessageFactory, createNullMuleMessage, disconnect, dispose, disposeAndLogException, doConnect, doDisconnect, doInitialise, getConnectEventId, getConnector, getLifecycleState, initializeMessageFactory, initializeRetryPolicy, isConnected, isDoThreading, isStarted, isStarting, isStopped, isStopping, passivate, setEndpoint, start, stop, validate, validateConnection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mule.api.transport.MessageReceiver
createMuleMessage, createMuleMessage
 
Methods inherited from interface org.mule.api.transport.Connectable
connect, disconnect, isConnected, validateConnection
 
Methods inherited from interface org.mule.api.lifecycle.Startable
start
 
Methods inherited from interface org.mule.api.lifecycle.Stoppable
stop
 
Methods inherited from interface org.mule.api.lifecycle.Disposable
dispose
 

Field Detail

DEFAULT_POLL_FREQUENCY

public static final long DEFAULT_POLL_FREQUENCY
See Also:
Constant Field Values

DEFAULT_POLL_TIMEUNIT

public static final TimeUnit DEFAULT_POLL_TIMEUNIT

DEFAULT_STARTUP_DELAY

public static final long DEFAULT_STARTUP_DELAY
See Also:
Constant Field Values

schedules

protected final Map<ScheduledFuture,PollingReceiverWorker> schedules
Constructor Detail

AbstractPollingMessageReceiver

public AbstractPollingMessageReceiver(Connector connector,
                                      FlowConstruct flowConstruct,
                                      InboundEndpoint endpoint)
                               throws CreateException
Throws:
CreateException
Method Detail

doStart

protected void doStart()
                throws MuleException
Overrides:
doStart in class AbstractTransportMessageHandler
Throws:
MuleException

doStop

protected void doStop()
               throws MuleException
Overrides:
doStop in class AbstractMessageReceiver
Throws:
MuleException

schedule

protected void schedule()
                 throws RejectedExecutionException,
                        NullPointerException,
                        IllegalArgumentException
This method registers this receiver for periodic polling ticks with the connectors scheduler. Subclasses can override this in case they want to handle their polling differently.

Throws:
RejectedExecutionException
NullPointerException
IllegalArgumentException
See Also:
ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit)

unschedule

protected void unschedule()
This method cancels the schedules which were created in schedule().

See Also:
Future.cancel(boolean)

disableNativeScheduling

public void disableNativeScheduling()

createWork

protected PollingReceiverWorker createWork()

getFrequency

public long getFrequency()

setFrequency

public void setFrequency(long value)

getTimeUnit

public TimeUnit getTimeUnit()

setTimeUnit

public void setTimeUnit(TimeUnit timeUnit)

getBatchSize

protected int getBatchSize(int available)
The preferred number of messages to process in the current batch. We need to drain the queue quickly, but not by slamming the workManager too hard. It is impossible to determine this more precisely without proper load statistics/feedback or some kind of "event cost estimate". Therefore we just try to use half of the receiver's workManager, since it is shared with receivers for other endpoints. TODO make this user-settable

Parameters:
available - the number if messages currently available to be processed

performPoll

public final void performPoll()
                       throws Exception
Check whether polling should take place on this instance.

Throws:
Exception

pollOnPrimaryInstanceOnly

protected boolean pollOnPrimaryInstanceOnly()
If this returns true for a transport, polling for that transport takes place only on the primary instance.


poll

protected abstract void poll()
                      throws Exception
Throws:
Exception


Copyright © 2003-2014 MuleSoft, Inc.. All Rights Reserved.