org.mule
Class AbstractExceptionListener

java.lang.Object
  extended by org.mule.AbstractExceptionListener
All Implemented Interfaces:
ExceptionListener, MuleContextAware, Disposable, Initialisable
Direct Known Subclasses:
DefaultExceptionStrategy, QuietExceptionStrategy

public abstract class AbstractExceptionListener
extends Object
implements ExceptionListener, Initialisable, Disposable, MuleContextAware

AbstractExceptionListener is a base implementation that custom Exception Listeners can override. It provides template methods for handling the for base types of exceptions plus allows multimple endpoints to be associated with this exception listener and provides an implementation for dispatching exception events from this Listener.


Field Summary
protected  WildcardFilter commitTxFilter
           
protected  boolean enableNotifications
           
protected  List endpoints
           
protected  edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean initialised
           
protected  Log logger
          logger used by this class
protected  MuleContext muleContext
           
protected  WildcardFilter rollbackTxFilter
           
 
Fields inherited from interface org.mule.api.lifecycle.Initialisable
PHASE_NAME
 
Fields inherited from interface org.mule.api.lifecycle.Disposable
PHASE_NAME
 
Constructor Summary
AbstractExceptionListener()
           
 
Method Summary
 void addEndpoint(OutboundEndpoint endpoint)
           
protected  void closeStream(MuleMessage message)
           
 void dispose()
          A lifecycle method where implementor should free up any resources.
protected  void doInitialise(MuleContext muleContext)
           
 void exceptionThrown(Exception e)
           
protected  void fireNotification(ExceptionNotification notification)
          Fires a server notification to all registered ExceptionNotificationListener eventManager.
 WildcardFilter getCommitTxFilter()
           
 List getEndpoints()
           
protected  List getEndpoints(Throwable t)
          Returns an endpoint for the given exception.
protected  Object getErrorMessagePayload(MuleMessage message)
           
protected  Throwable getExceptionType(Throwable t, Class exceptionType)
           
 WildcardFilter getRollbackTxFilter()
           
abstract  void handleLifecycleException(Object component, Throwable e)
          DefaultLifecyclePhase exceptions are thrown when an error occurs during an object's lifecycle call such as start, stop or initialise.
abstract  void handleMessagingException(MuleMessage message, Throwable e)
          A messaging exception is thrown when an excpetion occurs during normal message processing.
abstract  void handleRoutingException(MuleMessage message, ImmutableEndpoint endpoint, Throwable e)
          A routing exception is thrown when an excpetion occurs during normal message processing A RoutingException holds a reference to the current message and te endpoint being routing to or from when the error occurred.
abstract  void handleStandardException(Throwable e)
          A handler for all other exceptions
protected  void handleTransaction(Throwable t)
          If there is a current transaction this method will mark it for rollback This method should not be called if an event is routed from this exception handler to an endpoint that should take part in the current transaction
 void initialise()
          The initialise method is call every time the Exception stategy is assigned to a service or connector.
 boolean isEnableNotifications()
           
 boolean isInitialised()
           
protected  void logException(Throwable t)
          Used to log the error passed into this Exception Listener
protected  void logFatal(MuleMessage message, Throwable t)
          Logs a fatal error message to the logging system.
 boolean removeEndpoint(OutboundEndpoint endpoint)
           
protected  void rollbackTransaction()
           
protected  void routeException(MuleMessage message, ImmutableEndpoint failedEndpoint, Throwable t)
          Routes the current exception to an error endpoint such as a Dead Letter Queue (jms) This method is only invoked if there is a MuleMessage available to dispatch.
 void setCommitTxFilter(WildcardFilter commitTxFilter)
           
 void setEnableNotifications(boolean enableNotifications)
           
 void setEndpoints(List endpoints)
           
 void setMuleContext(MuleContext context)
           
 void setRollbackTxFilter(WildcardFilter rollbackTxFilter)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected transient Log logger
logger used by this class


endpoints

protected List endpoints

initialised

protected edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean initialised

muleContext

protected MuleContext muleContext

rollbackTxFilter

protected WildcardFilter rollbackTxFilter

commitTxFilter

protected WildcardFilter commitTxFilter

enableNotifications

protected boolean enableNotifications
Constructor Detail

AbstractExceptionListener

public AbstractExceptionListener()
Method Detail

setMuleContext

public void setMuleContext(MuleContext context)
Specified by:
setMuleContext in interface MuleContextAware

getEndpoints

public List getEndpoints()

setEndpoints

public void setEndpoints(List endpoints)

addEndpoint

public void addEndpoint(OutboundEndpoint endpoint)

removeEndpoint

public boolean removeEndpoint(OutboundEndpoint endpoint)

exceptionThrown

public void exceptionThrown(Exception e)
Specified by:
exceptionThrown in interface ExceptionListener

getExceptionType

protected Throwable getExceptionType(Throwable t,
                                     Class exceptionType)

initialise

public final void initialise()
                      throws InitialisationException
The initialise method is call every time the Exception stategy is assigned to a service or connector. This implementation ensures that initialise is called only once. The actual initialisation code is contained in the doInitialise() method.

Specified by:
initialise in interface Initialisable
Throws:
InitialisationException
RecoverableException - if an error occurs that can be recovered from

doInitialise

protected void doInitialise(MuleContext muleContext)
                     throws InitialisationException
Throws:
InitialisationException

handleTransaction

protected void handleTransaction(Throwable t)
If there is a current transaction this method will mark it for rollback This method should not be called if an event is routed from this exception handler to an endpoint that should take part in the current transaction


rollbackTransaction

protected void rollbackTransaction()

routeException

protected void routeException(MuleMessage message,
                              ImmutableEndpoint failedEndpoint,
                              Throwable t)
Routes the current exception to an error endpoint such as a Dead Letter Queue (jms) This method is only invoked if there is a MuleMessage available to dispatch. The message dispatched from this method will be an ExceptionMessage which contains the exception thrown the MuleMessage and any context information.

Parameters:
message - the MuleMessage being processed when the exception occurred
failedEndpoint - optional; the endpoint being dispatched or received on when the error occurred. This is NOT the endpoint that the message will be disptched on and is only supplied to this method for logging purposes
t - the exception thrown. This will be sent with the ExceptionMessage
See Also:
ExceptionMessage

closeStream

protected void closeStream(MuleMessage message)

getErrorMessagePayload

protected Object getErrorMessagePayload(MuleMessage message)

getEndpoints

protected List getEndpoints(Throwable t)
Returns an endpoint for the given exception. ExceptionListeners can have multiple endpoints registered on them. This methods allows custom implementations to control which endpoint is used based on the exception thrown. This implementation simply returns the first endpoint in the list.

Parameters:
t - the exception thrown
Returns:
The endpoint used to dispatch an exception message on or null if there are no endpoints registered

logException

protected void logException(Throwable t)
Used to log the error passed into this Exception Listener

Parameters:
t - the exception thrown

logFatal

protected void logFatal(MuleMessage message,
                        Throwable t)
Logs a fatal error message to the logging system. This should be used mostly if an error occurs in the exception listener itself. This implementation logs the the message itself to the logs if it is not null

Parameters:
message - The MuleMessage currently being processed
t - the fatal exception to log

isInitialised

public boolean isInitialised()

dispose

public void dispose()
Description copied from interface: Disposable
A lifecycle method where implementor should free up any resources. If an exception is thrown it should just be logged and processing should continue. This method should not throw Runtime exceptions.

Specified by:
dispose in interface Disposable

fireNotification

protected void fireNotification(ExceptionNotification notification)
Fires a server notification to all registered ExceptionNotificationListener eventManager.

Parameters:
notification - the notification to fire.

getCommitTxFilter

public WildcardFilter getCommitTxFilter()

setCommitTxFilter

public void setCommitTxFilter(WildcardFilter commitTxFilter)

isEnableNotifications

public boolean isEnableNotifications()

setEnableNotifications

public void setEnableNotifications(boolean enableNotifications)

getRollbackTxFilter

public WildcardFilter getRollbackTxFilter()

setRollbackTxFilter

public void setRollbackTxFilter(WildcardFilter rollbackTxFilter)

handleMessagingException

public abstract void handleMessagingException(MuleMessage message,
                                              Throwable e)
A messaging exception is thrown when an excpetion occurs during normal message processing. A MessagingException holds a reference to the current message that is passed into this method

Parameters:
message - the current message being processed
e - the top level exception thrown. This may be a Messaging exception or some wrapper exception
See Also:
MessagingException

handleRoutingException

public abstract void handleRoutingException(MuleMessage message,
                                            ImmutableEndpoint endpoint,
                                            Throwable e)
A routing exception is thrown when an excpetion occurs during normal message processing A RoutingException holds a reference to the current message and te endpoint being routing to or from when the error occurred. Both are passed into this method

Parameters:
message - the current message being processed
endpoint - the endpoint being dispatched to or received from when the error occurred
e - the top level exception thrown. This may be a Messaging exception or some wrapper exception
See Also:
RoutingException

handleLifecycleException

public abstract void handleLifecycleException(Object component,
                                              Throwable e)
DefaultLifecyclePhase exceptions are thrown when an error occurs during an object's lifecycle call such as start, stop or initialise. The exception contains a reference to the object that failed which can be used for more informative logging.

Parameters:
component - the object that failed during a lifecycle call
e - the top level exception thrown. This may or may not be the LifecycleException but a lifecycle exception will be present in the exception stack.
See Also:
LifecycleException

handleStandardException

public abstract void handleStandardException(Throwable e)
A handler for all other exceptions

Parameters:
e - the top level exception thrown


Copyright © 2003-2009 MuleSource, Inc.. All Rights Reserved.