org.mule.impl
Class AbstractExceptionListener

java.lang.Object
  extended byorg.mule.impl.AbstractExceptionListener
All Implemented Interfaces:
java.beans.ExceptionListener, Initialisable
Direct Known Subclasses:
DefaultExceptionStrategy

public abstract class AbstractExceptionListener
extends java.lang.Object
implements java.beans.ExceptionListener, Initialisable

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 implementaiton for dispatching exception events from this Listener.

Version:
$Revision: 1.4 $
Author:
Ross Mason

Field Summary
protected  java.util.List endpoints
           
protected  Log logger
          logger used by this class
 
Constructor Summary
AbstractExceptionListener()
           
 
Method Summary
 void addEndpoint(UMOEndpoint endpoint)
           
 void exceptionThrown(java.lang.Exception e)
           
protected  UMOEndpoint getEndpoint(java.lang.Throwable t)
          Returns an endpoint for the given exception.
 java.util.List getEndpoints()
           
protected  java.lang.Object getErrorMessagePayload(UMOMessage message)
           
protected  java.lang.Throwable getExceptionType(java.lang.Exception e, java.lang.Class exceptionType)
           
abstract  void handleLifecycleException(java.lang.Object component, java.lang.Throwable e)
          Lifecycle exceptions are thrown when an error occurs during an object's lifecycle call such as start, stop or initialise.
abstract  void handleMessagingException(UMOMessage message, java.lang.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
abstract  void handleRoutingException(UMOMessage message, UMOEndpoint endpoint, java.lang.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(java.lang.Throwable e)
          A handler for all other exceptions
 void initialise()
          Method used to perform any initialisation work.
protected  void logException(java.lang.Throwable t)
          Used to log the error passed into this Exception Listener
protected  void logFatal(UMOMessage message, java.lang.Throwable t)
          Logs a fatal error message to the logging system.
protected  void markTransactionForRollback()
          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
 boolean removeEndpoint(UMOEndpoint endpoint)
           
protected  void routeException(UMOMessage message, UMOEndpoint failedEndpoint, java.lang.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 UMOMassage available to dispatch.
 void setEndpoints(java.util.List endpoints)
           
 
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 java.util.List endpoints
Constructor Detail

AbstractExceptionListener

public AbstractExceptionListener()
Method Detail

getEndpoints

public java.util.List getEndpoints()

setEndpoints

public void setEndpoints(java.util.List endpoints)

addEndpoint

public void addEndpoint(UMOEndpoint endpoint)

removeEndpoint

public boolean removeEndpoint(UMOEndpoint endpoint)

exceptionThrown

public void exceptionThrown(java.lang.Exception e)
Specified by:
exceptionThrown in interface java.beans.ExceptionListener

getExceptionType

protected java.lang.Throwable getExceptionType(java.lang.Exception e,
                                               java.lang.Class exceptionType)

initialise

public void initialise()
                throws InitialisationException,
                       RecoverableException
Description copied from interface: Initialisable
Method used to perform any initialisation work. If a fatal error occurs during initialisation an InitialisationException should be thrown, causing the Mule instance to shutdown. If the error is recoverable, say by retrying to connect, a RecoverableException should be thrown. There is no guarantee that by throwing a Recoverable exception that the Mule instance will not shut down.

Specified by:
initialise in interface Initialisable
Throws:
InitialisationException - if a fatal error occurs causing the Mule instance to shutdown
RecoverableException - if an error occurs that can be recovered from

markTransactionForRollback

protected void markTransactionForRollback()
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


routeException

protected void routeException(UMOMessage message,
                              UMOEndpoint failedEndpoint,
                              java.lang.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 UMOMassage available to dispatch. The message dispatched from this method will be an ExceptionMessage which contains the exception thrown the UMOMessage and any context information.

Parameters:
message - the UMOMessage being processed when the exception occurred
failedEndpoint - optional; the endpoint being dispatched or recieved 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

getErrorMessagePayload

protected java.lang.Object getErrorMessagePayload(UMOMessage message)

getEndpoint

protected UMOEndpoint getEndpoint(java.lang.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(java.lang.Throwable t)
Used to log the error passed into this Exception Listener

Parameters:
t - the exception thrown

logFatal

protected void logFatal(UMOMessage message,
                        java.lang.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 UMOMessage currently being processed
t - the fatal exception to log

handleMessagingException

public abstract void handleMessagingException(UMOMessage message,
                                              java.lang.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(UMOMessage message,
                                            UMOEndpoint endpoint,
                                            java.lang.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(java.lang.Object component,
                                              java.lang.Throwable e)
Lifecycle 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(java.lang.Throwable e)
A handler for all other exceptions

Parameters:
e - the top level exception thrown


Copyright © 2003-2005 SymphonySoft Limited. All Rights Reserved.