You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/04/12 18:23:15 UTC

[isis] 02/02: ISIS-1935 fixes event types having no type safety

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 3a4f3ea3142eab4c5c1bd48840cb4438ba13da19
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Apr 12 20:23:08 2018 +0200

    ISIS-1935 fixes event types having no type safety
---
 .../isis/applib/services/eventbus/EventBusService.java  |  2 +-
 .../adapter/EventBusImplementationForAxonSimple.java    |  2 +-
 .../adapter/EventBusImplementationForGuava.java         | 17 ++++++++++++-----
 .../eventbus/EventBusImplementationAbstract.java        |  3 +++
 4 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/EventBusService.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/EventBusService.java
index 8b66e21..e12ee72 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/EventBusService.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/EventBusService.java
@@ -209,8 +209,8 @@ public abstract class EventBusService {
         if(skip(event)) {
             return;
         }
-        getEventBusImplementation().post(event);
         hasPosted = true;
+        getEventBusImplementation().post(event);
     }
 
 
diff --git a/core/plugins/eventbus-axon/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusImplementationForAxonSimple.java b/core/plugins/eventbus-axon/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusImplementationForAxonSimple.java
index 0d6c3bf..4a96a07 100644
--- a/core/plugins/eventbus-axon/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusImplementationForAxonSimple.java
+++ b/core/plugins/eventbus-axon/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusImplementationForAxonSimple.java
@@ -105,7 +105,7 @@ public class EventBusImplementationForAxonSimple extends EventBusImplementationA
     static class AxonEventListener<T> implements EventBusImplementation.EventListener<T> {
     	private final Consumer<T> eventConsumer;
 		private final EventListenerProxy proxy;
-    	private AxonEventListener(Class<T> targetType, Consumer<T> eventConsumer) {
+    	private AxonEventListener(final Class<T> targetType, final Consumer<T> eventConsumer) {
 			this.eventConsumer = Objects.requireNonNull(eventConsumer);
 			this.proxy = new EventListenerProxy() {
 				@SuppressWarnings("unchecked")
diff --git a/core/plugins/eventbus-guava/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusImplementationForGuava.java b/core/plugins/eventbus-guava/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusImplementationForGuava.java
index 36e7ec1..535ccc7 100644
--- a/core/plugins/eventbus-guava/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusImplementationForGuava.java
+++ b/core/plugins/eventbus-guava/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusImplementationForGuava.java
@@ -71,8 +71,8 @@ public class EventBusImplementationForGuava extends EventBusImplementationAbstra
     }
 
     @Override
-    public <T> EventListener<T> addEventListener(Class<T> targetType, Consumer<T> onEvent) {
-    	final EventListener<T> eventListener = new GuavaEventListener<>(onEvent);
+    public <T> EventListener<T> addEventListener(final Class<T> targetType, final Consumer<T> onEvent) {
+    	final EventListener<T> eventListener = new GuavaEventListener<>(targetType, onEvent);
     	eventBus.register(eventListener);
     	return eventListener;
     }
@@ -85,14 +85,21 @@ public class EventBusImplementationForGuava extends EventBusImplementationAbstra
 	// -- HELPER
 	
     private static class GuavaEventListener<T> implements EventBusImplementation.EventListener<T> {
+    	private final Class<T> targetType;
     	private final Consumer<T> eventConsumer;
-    	private GuavaEventListener(Consumer<T> eventConsumer) {
+    	private GuavaEventListener(final Class<T> targetType, final Consumer<T> eventConsumer) {
+    		this.targetType = Objects.requireNonNull(targetType);
 			this.eventConsumer = Objects.requireNonNull(eventConsumer);
 		}
 		@com.google.common.eventbus.Subscribe
 		@Override
-    	public void on(T event) {
-    		eventConsumer.accept(event);
+    	public void on(T payload) {
+			if(payload==null) {
+				return;
+			}
+			if(targetType.isAssignableFrom(payload.getClass())){
+				eventConsumer.accept(payload);
+			}
     	}
     }
 
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusImplementationAbstract.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusImplementationAbstract.java
index 5bca628..f36b9dc 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusImplementationAbstract.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusImplementationAbstract.java
@@ -45,6 +45,9 @@ public abstract class EventBusImplementationAbstract implements EventBusImplemen
         }
 
         final AbstractDomainEvent.Phase phase = domainEvent.getEventPhase();
+        if(phase==null) {
+        	throw new RuntimeException(exception);
+        }
         switch (phase) {
             case HIDE:
             case DISABLE:

-- 
To stop receiving notification emails like this one, please contact
ahuber@apache.org.