IBM WebSphereTM eXtreme Scale, Release 8.6
API Specification

com.ibm.websphere.objectgrid.plugins
Interface ExceptionMapper


public interface ExceptionMapper

The ExceptionMapper interface allows users to plug in specific exception mapping functionality. When ObjectGrid gets a generic Throwable from a third-party product, this interface can be used to map it to a different Throwable which can be more friendly or consumable to ObjectGrid.

For example, when a JPALoader or a JPAEntityLoader is used, the application could implement this interface to map a generic javax.persistence.PersistenceException to more consumable exceptions. The implementation class could introspect the SQL state and error code of the java.sql.SQLException chained in the JPA exception and throw a LoaderNotAvailableException if the SQL state or error code indicates the database server or network is not functional or the database runs out of resources.

Here is an example:

    public Throwable map(Throwable original) {
 
         Throwable cause = original;
 
         while (cause != null) {
             // keep looping to check the next chained exception
 
             if (cause instanceof SQLException) {
                 // Only check if the exception is an SQLException
 
                 SQLException sqle = (SQLException) cause;
                 
                 // If the loader not available SQL state set contains this SQL state, then
                 // we return a LoaderNotAvailableException with the original exception chained in it.
                 if (loaderNotAvailableSQLStateSet.contains(sqle.getSQLState())) {
                     return new LoaderNotAvailableException(original);
                 }
                 
                 // If the loader not available SQL error code set contains this error code, then
                 // we return a LoaderNotAvailableException with the original exception chained in it
                 if (loaderNotAvailableSQLErrorSet.contains(new Integer(sqle.getErrorCode()))) {
                     return new LoaderNotAvailableException(original);
                 }
             }
             
             // Get the next chained exception
             Throwable newCause = cause.getCause();
             
             // Safe-guard check to avoid indefinite loop if the exception chains itself
             if (newCause == cause) {
                 // Always return the original exception if cannot map it.
                 return original;
             } else {
                 cause = newCause;
             }
         }
 
         // Always retrun the original exception if cannot map it.
         return original;
     }
 
Currently, the ExceptionMapper can be configured in the following ObjectGrid beans:

Since:
7.0

Method Summary
 Throwable map(Throwable original)
          This method maps an Throwable to a more friendly or consumable Throwable if possible.
 

Method Detail

map

Throwable map(Throwable original)
This method maps an Throwable to a more friendly or consumable Throwable if possible. If the passed-in Throwable cannot be mapped, the implementation is expected to return it.

Parameters:
original - the Throwable to be mapped
Returns:
the mapped Throwable , or the original Throwable if it cannot be mapped.

IBM WebSphereTM eXtreme Scale, Release 8.6
API Specification

© Copyright International Business Machines Corp 2005,2012. All rights reserved.