Repository: isis Updated Branches: refs/heads/master 3969f34c5 -> 2aa0df30a
ISIS-960: Make the event bus handle exceptions more gracefully, not swallow them. Project: http://git-wip-us.apache.org/repos/asf/isis/repo Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/2d1b44d9 Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/2d1b44d9 Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/2d1b44d9 Branch: refs/heads/master Commit: 2d1b44d9a183e7b4a8a35284560fec7e0f54b313 Parents: 3969f34 Author: Jeroen van der Wal <[email protected]> Authored: Thu Nov 27 18:14:12 2014 +0100 Committer: Jeroen van der Wal <[email protected]> Committed: Thu Nov 27 18:14:12 2014 +0100 ---------------------------------------------------------------------- .../eventbus/EventBusServiceDefault.java | 36 ++++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/isis/blob/2d1b44d9/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusServiceDefault.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusServiceDefault.java index cd3626c..9b70ab8 100644 --- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusServiceDefault.java +++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusServiceDefault.java @@ -17,13 +17,18 @@ package org.apache.isis.core.runtime.services.eventbus; import java.util.List; + import javax.enterprise.context.RequestScoped; + import com.google.common.base.Throwables; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.SubscriberExceptionContext; import com.google.common.eventbus.SubscriberExceptionHandler; + import org.apache.isis.applib.NonRecoverableException; import org.apache.isis.applib.RecoverableException; +import org.apache.isis.applib.services.eventbus.AbstractInteractionEvent; +import org.apache.isis.applib.services.eventbus.AbstractInteractionEvent.Phase; import org.apache.isis.applib.services.eventbus.EventBusService; import org.apache.isis.core.commons.exceptions.IsisApplicationException; import org.apache.isis.core.metamodel.facets.Annotations; @@ -78,14 +83,33 @@ public class EventBusServiceDefault extends EventBusService { return new SubscriberExceptionHandler(){ @Override public void handleException(Throwable exception, SubscriberExceptionContext context) { - final List<Throwable> causalChain = Throwables.getCausalChain(exception); - for (Throwable cause : causalChain) { - if(cause instanceof RecoverableException || cause instanceof NonRecoverableException) { - getTransactionManager().getTransaction().setAbortCause(new IsisApplicationException(exception)); - return; + Object event = context.getEvent(); + if(!(event instanceof AbstractInteractionEvent)) { + return; + } + final AbstractInteractionEvent<?> interactionEvent = (AbstractInteractionEvent<?>) event; + final Phase phase = interactionEvent.getPhase(); + switch (phase) { + case HIDE: + interactionEvent.hide(); + break; + case DISABLE: + interactionEvent.disable(exception.getMessage()!=null?exception.getMessage(): exception.getClass().getName() + " thrown."); + break; + case VALIDATE: + interactionEvent.invalidate(exception.getMessage()!=null?exception.getMessage(): exception.getClass().getName() + " thrown."); + break; + case EXECUTING: + case EXECUTED: + final List<Throwable> causalChain = Throwables.getCausalChain(exception); + for (Throwable cause : causalChain) { + if(cause instanceof RecoverableException || cause instanceof NonRecoverableException) { + getTransactionManager().getTransaction().setAbortCause(new IsisApplicationException(exception)); + return; + } } + break; } - // otherwise simply ignore } }; }
