com.emarsys.ecommon.exceptions.handling
Class ExceptionHandlerPool

java.lang.Object
  extended by com.emarsys.ecommon.exceptions.handling.ExceptionHandlerPool
All Implemented Interfaces:
ExceptionHandling

public class ExceptionHandlerPool
extends java.lang.Object
implements ExceptionHandling

ExceptionHandlerPool represents some kind of default implementation of the ExceptionHandling interface with almost no restrictions.

NOTE: the whole pluggable exception handling (PEH) module is highly experimental and still under heavy development, don't use it in production code unless you know what you're doing!

Author:
Michael "kULO" Kulovits

Field Summary
protected  java.util.Map<ExceptionScenario<?,?>,ExceptionHandler<?,?>> pool
           
 
Constructor Summary
ExceptionHandlerPool()
           
 
Method Summary
<E extends java.lang.Exception,T extends java.lang.Exception>
ExceptionHandler<E,T>
getExceptionHandler(ExceptionScenario<E,T> scenario)
           
 java.util.Map<ExceptionScenario<?,?>,ExceptionHandler<?,?>> getExceptionHandlers()
           The passed Map must not be the ExceptionHandling's interal, modifyable representation in order to protect from violating invariants.
<E extends java.lang.Exception,T extends java.lang.Exception>
void
registerExceptionHandler(ExceptionScenario<E,T> scenario, ExceptionHandler<E,T> handler)
           
 ExceptionHandling unionExceptionHandling(ExceptionHandling handling)
          Will add all ExceptionHandlers from the passed handling and overwrite already existing ones; already registered distinct handlers will remain registered.
<E extends java.lang.Exception,T extends java.lang.Exception>
void
unregisterExceptionHandler(ExceptionScenario<E,T> scenario)
          Unregisters the ExceptionHandler associated with the passed scenario if present.
 ExceptionHandling useExceptionHandling(ExceptionHandling handling)
          Will overwrite this exception handlings behavior with the passed instance's one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pool

protected volatile java.util.Map<ExceptionScenario<?,?>,ExceptionHandler<?,?>> pool
Constructor Detail

ExceptionHandlerPool

public ExceptionHandlerPool()
Method Detail

getExceptionHandler

public <E extends java.lang.Exception,T extends java.lang.Exception> ExceptionHandler<E,T> getExceptionHandler(ExceptionScenario<E,T> scenario)
Specified by:
getExceptionHandler in interface ExceptionHandling
Returns:
the ExceptionHandler registered for the passed ExceptionScenario or null if not present.
See Also:
ExceptionHandling.getExceptionHandler(com.emarsys.ecommon.exceptions.handling.ExceptionScenario)

getExceptionHandlers

public java.util.Map<ExceptionScenario<?,?>,ExceptionHandler<?,?>> getExceptionHandlers()
Description copied from interface: ExceptionHandling

The passed Map must not be the ExceptionHandling's interal, modifyable representation in order to protect from violating invariants. So the returned map might be a copy or a an immutable proxy of the exception handlings internal state.

Specified by:
getExceptionHandlers in interface ExceptionHandling
Returns:
all ExceptionHandlers registered with this instance togheter with their associated ExceptionScenarios but never null, if no handler is present an empty Map will be returned.

See Also:
ExceptionHandling.getExceptionHandlers()

registerExceptionHandler

public <E extends java.lang.Exception,T extends java.lang.Exception> void registerExceptionHandler(ExceptionScenario<E,T> scenario,
                                                                                                   ExceptionHandler<E,T> handler)
Specified by:
registerExceptionHandler in interface ExceptionHandling
See Also:
ExceptionHandling.registerExceptionHandler(com.emarsys.ecommon.exceptions.handling.ExceptionScenario, com.emarsys.ecommon.exceptions.handling.ExceptionHandler)

unregisterExceptionHandler

public <E extends java.lang.Exception,T extends java.lang.Exception> void unregisterExceptionHandler(ExceptionScenario<E,T> scenario)
Description copied from interface: ExceptionHandling
Unregisters the ExceptionHandler associated with the passed scenario if present.

Specified by:
unregisterExceptionHandler in interface ExceptionHandling
See Also:
ExceptionHandling.unregisterExceptionHandler(com.emarsys.ecommon.exceptions.handling.ExceptionScenario)

unionExceptionHandling

public ExceptionHandling unionExceptionHandling(ExceptionHandling handling)
Description copied from interface: ExceptionHandling
Will add all ExceptionHandlers from the passed handling and overwrite already existing ones; already registered distinct handlers will remain registered.

Specified by:
unionExceptionHandling in interface ExceptionHandling
Returns:
the ExceptionHandling now in use.
See Also:
ExceptionHandling.unionExceptionHandling(com.emarsys.ecommon.exceptions.handling.ExceptionHandling)

useExceptionHandling

public ExceptionHandling useExceptionHandling(ExceptionHandling handling)
Description copied from interface: ExceptionHandling
Will overwrite this exception handlings behavior with the passed instance's one.

Specified by:
useExceptionHandling in interface ExceptionHandling
Returns:
the ExceptionHandling now in use, needs not to be the same (identical) instance as the passed one.
See Also:
ExceptionHandling.useExceptionHandling(com.emarsys.ecommon.exceptions.handling.ExceptionHandling)


Copyright © 2010 emarsys AG. All Rights Reserved.