org.mule.transport.file
Class FileMessageReceiver

java.lang.Object
  extended by org.mule.transport.AbstractTransportMessageHandler
      extended by org.mule.transport.AbstractMessageReceiver
          extended by org.mule.transport.AbstractPollingMessageReceiver
              extended by org.mule.transport.file.FileMessageReceiver
All Implemented Interfaces:
Disposable, Initialisable, Lifecycle, LifecycleStateEnabled, Startable, Stoppable, MessageSource, Connectable, MessageReceiver

public class FileMessageReceiver
extends AbstractPollingMessageReceiver

FileMessageReceiver is a polling listener that reads files from a directory.


Field Summary
static String COMPARATOR_CLASS_NAME_PROPERTY
           
static String COMPARATOR_REVERSE_ORDER_PROPERTY
           
 
Fields inherited from class org.mule.transport.AbstractPollingMessageReceiver
DEFAULT_POLL_FREQUENCY, DEFAULT_POLL_TIMEUNIT, DEFAULT_STARTUP_DELAY, 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
FileMessageReceiver(Connector connector, FlowConstruct flowConstruct, InboundEndpoint endpoint, String readDir, String moveDir, String moveToPattern, long frequency)
           
 
Method Summary
protected  boolean attemptFileLock(File sourceFile)
          Try to acquire a lock on a file and release it immediately.
protected  void basicListFiles(File currentDirectory, List<File> discoveredFiles)
           
protected  void checkMustForceSync()
          If we will be autodeleting File objects, events must be processed synchronously to avoid a race
protected  org.mule.transport.file.ReceiverFileInputStream createReceiverFileInputStream(File sourceFile, File destinationFile)
           
protected  void doConnect()
           
protected  void doDisconnect()
           
protected  void doDispose()
           
protected  Comparator<File> getComparator()
           
 void poll()
           
protected  boolean pollOnPrimaryInstanceOnly()
          If this returns true for a transport, polling for that transport takes place only on the primary instance.
 void processFile(File file)
           
protected  void rollbackFileMove(File sourceFile, String destinationFilePath)
          Exception tolerant roll back method
 
Methods inherited from class org.mule.transport.AbstractPollingMessageReceiver
createWork, disableNativeScheduling, doStart, doStop, getBatchSize, getFrequency, getTimeUnit, performPoll, schedule, setFrequency, setTimeUnit, unschedule
 
Methods inherited from class org.mule.transport.AbstractMessageReceiver
applyInboundTransformers, applyResponseTransformers, createExecutionTemplate, createLifecycleManager, createMuleEvent, getConnectEventId, getConnectionDescription, getEndpoint, getEndpointURI, getFlowConstruct, getReceiverKey, getReplyToHandler, getWorkManager, handleUnacceptedFilter, initialise, propagateRootMessageIdProperty, routeMessage, routeMessage, routeMessage, routeMessage, routeMessage, setEndpoint, setListener, setReceiverKey, toString, warnIfMuleClientSendUsed
 
Methods inherited from class org.mule.transport.AbstractTransportMessageHandler
activate, connect, createMuleMessage, createMuleMessage, createMuleMessage, createMuleMessageFactory, createNullMuleMessage, disconnect, dispose, disposeAndLogException, doInitialise, getConnectEventId, getConnector, getLifecycleState, initializeMessageFactory, initializeRetryPolicy, isConnected, isDoThreading, isStarted, isStarting, 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

COMPARATOR_CLASS_NAME_PROPERTY

public static final String COMPARATOR_CLASS_NAME_PROPERTY
See Also:
Constant Field Values

COMPARATOR_REVERSE_ORDER_PROPERTY

public static final String COMPARATOR_REVERSE_ORDER_PROPERTY
See Also:
Constant Field Values
Constructor Detail

FileMessageReceiver

public FileMessageReceiver(Connector connector,
                           FlowConstruct flowConstruct,
                           InboundEndpoint endpoint,
                           String readDir,
                           String moveDir,
                           String moveToPattern,
                           long frequency)
                    throws CreateException
Throws:
CreateException
Method Detail

checkMustForceSync

protected void checkMustForceSync()
                           throws CreateException
If we will be autodeleting File objects, events must be processed synchronously to avoid a race

Throws:
CreateException

doConnect

protected void doConnect()
                  throws Exception
Overrides:
doConnect in class AbstractTransportMessageHandler
Throws:
Exception

doDisconnect

protected void doDisconnect()
                     throws Exception
Overrides:
doDisconnect in class AbstractTransportMessageHandler
Throws:
Exception

doDispose

protected void doDispose()
Overrides:
doDispose in class AbstractMessageReceiver

poll

public void poll()
Specified by:
poll in class AbstractPollingMessageReceiver

pollOnPrimaryInstanceOnly

protected boolean pollOnPrimaryInstanceOnly()
Description copied from class: AbstractPollingMessageReceiver
If this returns true for a transport, polling for that transport takes place only on the primary instance.

Overrides:
pollOnPrimaryInstanceOnly in class AbstractPollingMessageReceiver

processFile

public void processFile(File file)
                 throws MuleException
Throws:
MuleException

createReceiverFileInputStream

protected org.mule.transport.file.ReceiverFileInputStream createReceiverFileInputStream(File sourceFile,
                                                                                        File destinationFile)
                                                                                 throws FileNotFoundException
Throws:
FileNotFoundException

attemptFileLock

protected boolean attemptFileLock(File sourceFile)
                           throws MuleException
Try to acquire a lock on a file and release it immediately. Usually used as a quick check to see if another process is still holding onto the file, e.g. a large file (more than 100MB) is still being written to.

Parameters:
sourceFile - file to check
Returns:
true if the file can be locked
Throws:
MuleException

basicListFiles

protected void basicListFiles(File currentDirectory,
                              List<File> discoveredFiles)

rollbackFileMove

protected void rollbackFileMove(File sourceFile,
                                String destinationFilePath)
                         throws IOException
Exception tolerant roll back method

Throws:
Throwable
IOException

getComparator

protected Comparator<File> getComparator()
                                  throws Exception
Throws:
Exception


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