org.mule.work
Class ProcessingMuleEventWork

java.lang.Object
  extended by org.mule.work.AbstractMuleEventWork
      extended by org.mule.work.ProcessingMuleEventWork
All Implemented Interfaces:
Runnable, javax.resource.spi.work.Work

public class ProcessingMuleEventWork
extends AbstractMuleEventWork

Implementation of AbstractMuleEventWork that executes a MessageProcessor using this work's event. Instances of this class can be used in a "fire and forget" fashion or the getResult(long, TimeUnit) method can be used to wait for background processing to finish. For cases when used in this latter manner, this class provides semmantics similar to Future.get(long, TimeUnit) but with some differences around exception handling, cancellation, etc (see getResult(long, TimeUnit)).

Since:
3.5.0

Field Summary
 
Fields inherited from class org.mule.work.AbstractMuleEventWork
event
 
Constructor Summary
ProcessingMuleEventWork(MessageProcessor messageProcessor, MuleEvent muleEvent)
           
 
Method Summary
protected  void doRun()
          Invokes MessageProcessor.process(MuleEvent) using and AbstractMuleEventWork#event.
 MuleEvent getResult(long timeout, TimeUnit timeUnit)
          This method is useful for having a thread other than the one executing this work waiting for the result being available.
 
Methods inherited from class org.mule.work.AbstractMuleEventWork
getEvent, release, run
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessingMuleEventWork

public ProcessingMuleEventWork(MessageProcessor messageProcessor,
                               MuleEvent muleEvent)
Method Detail

doRun

protected void doRun()
Invokes MessageProcessor.process(MuleEvent) using and AbstractMuleEventWork#event. if processing is sucessful the result is stored in resultEvent or if it throws exception, it will be stored in exception Storing the result/exception allows getResult(long, TimeUnit) to return the values

Specified by:
doRun in class AbstractMuleEventWork

getResult

public MuleEvent getResult(long timeout,
                           TimeUnit timeUnit)
                    throws InterruptedException,
                           ResponseTimeoutException,
                           MuleException
This method is useful for having a thread other than the one executing this work waiting for the result being available. This is similar to Future.get(long, TimeUnit) but with some significant differences, mainly around the type of exceptions to be thrown and the fact that this work cannot cancel itself

Parameters:
timeout - time to wait before throwing ResponseTimeoutException
timeUnit - the unit for the timeout
Returns:
a MuleEvent once that doRun() finised successfuly
Throws:
InterruptedException - if the calling thread is interrupted
ResponseTimeoutException - if the calling thread waiting time has exceeded the timeout and doRun() hasn't yet finished
MuleException - if doRun() finished with exception. In that case, the value captured in exception is thrown


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