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 2019/08/10 05:29:49 UTC

[isis] branch v2 updated: ISIS-2158: refining wrapper's ASYNC execution mode, adds java-doc

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

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


The following commit(s) were added to refs/heads/v2 by this push:
     new 34a1818  ISIS-2158: refining wrapper's ASYNC execution mode, adds java-doc
34a1818 is described below

commit 34a18183e060e7f7873d84cb727d0baf6a5547a2
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat Aug 10 07:29:41 2019 +0200

    ISIS-2158: refining wrapper's ASYNC execution mode, adds java-doc
---
 .../applib/services/wrapper/WrapperFactory.java    | 25 ++++++++++++++++++++--
 .../handlers/DomainObjectInvocationHandler.java    |  4 ++--
 .../testdomain/commandexecution/WrapperTest.java   | 10 ++++-----
 3 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/wrapper/WrapperFactory.java b/core/applib/src/main/java/org/apache/isis/applib/services/wrapper/WrapperFactory.java
index 0720f37..3b4dfc2 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/wrapper/WrapperFactory.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/wrapper/WrapperFactory.java
@@ -94,9 +94,22 @@ public interface WrapperFactory {
         SWALLOW_EXCEPTIONS,
         
         /**
-         * Validate/Execute in background.
+         * 
+         * Validates synchronously but executes in background. Any wrapped object method that is supposed to 
+         * return something, will always return {@code null} when invoked to run in background.
+         * <p> 
+         * Execution gets skipped if {@link #SKIP_EXECUTION} is selected.
+         * <p>
+         * During background execution, presence or absence of {@link #SWALLOW_EXCEPTIONS} has no effect, 
+         * since background executions will not fail fast. Instead any exceptions that occur during
+         * background execution will be logged.
+         * 
+         * @since 2.0
+         * 
+         * @apiNote EXPERIMENTAL, what to do in case of exceptions possibly needs refinement, also there 
+         * should be some way to customize the background executor service.
          */
-        ASYNC,
+        ASYNC_EXECUTION,
         
         ;
         
@@ -108,6 +121,14 @@ public interface WrapperFactory {
         public static EnumSet<ExecutionMode> EXECUTE = EnumSet.noneOf(ExecutionMode.class); 
 
         /**
+         * Validate all business rules and then execute in background. Does throw an exception if 
+         * validation fails, any exceptions that occur during background execution will be logged.
+         * @since 2.0
+         * @apiNote EXPERIMENTAL see {@link #ASYNC_EXECUTION}
+         */
+        public static EnumSet<ExecutionMode> ASYNC = EnumSet.of(ASYNC_EXECUTION);
+        
+        /**
          * Skip all business rules and then execute, does throw an exception if execution fails.
          */
         public static EnumSet<ExecutionMode> SKIP_RULES = EnumSet.of(SKIP_RULE_VALIDATION);
diff --git a/core/runtime-extensions/src/main/java/org/apache/isis/wrapper/handlers/DomainObjectInvocationHandler.java b/core/runtime-extensions/src/main/java/org/apache/isis/wrapper/handlers/DomainObjectInvocationHandler.java
index ac7cf6f..41f07ed 100644
--- a/core/runtime-extensions/src/main/java/org/apache/isis/wrapper/handlers/DomainObjectInvocationHandler.java
+++ b/core/runtime-extensions/src/main/java/org/apache/isis/wrapper/handlers/DomainObjectInvocationHandler.java
@@ -824,7 +824,7 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
     }
     
     private boolean shouldExecuteAsync() {
-        return getExecutionMode().contains(ExecutionMode.ASYNC);
+        return getExecutionMode().contains(ExecutionMode.ASYNC_EXECUTION);
     }
     
     private void runValidationTask(Runnable task) {
@@ -847,7 +847,7 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
             return null;
         }
         if(shouldExecuteAsync()) {
-            return runAsync(task);
+            return runAsync(task); // will always return null
         }
         if(shouldFailFast()) {
             return task.get();
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/commandexecution/WrapperTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/commandexecution/WrapperTest.java
index 1d32ab3..4bfc787 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/commandexecution/WrapperTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/commandexecution/WrapperTest.java
@@ -18,7 +18,9 @@
  */
 package org.apache.isis.testdomain.commandexecution;
 
-import java.util.EnumSet;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -36,15 +38,13 @@ import org.apache.isis.applib.services.background.BackgroundService;
 import org.apache.isis.applib.services.factory.FactoryService;
 import org.apache.isis.applib.services.repository.RepositoryService;
 import org.apache.isis.applib.services.wrapper.WrapperFactory;
+import org.apache.isis.applib.services.wrapper.WrapperFactory.ExecutionMode;
 import org.apache.isis.extensions.fixtures.fixturescripts.FixtureScripts;
 import org.apache.isis.testdomain.jdo.InventoryManager;
 import org.apache.isis.testdomain.jdo.JdoTestDomainModule;
 import org.apache.isis.testdomain.jdo.JdoTestDomainPersona;
 import org.apache.isis.testdomain.jdo.Product;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
 import lombok.Getter;
 import lombok.val;
 
@@ -106,7 +106,7 @@ class WrapperTest {
 
         actionDomainEventListener.prepareLatch();
 
-        wrapperFactory.wrap(inventoryManager, EnumSet.of(WrapperFactory.ExecutionMode.ASYNC))
+        wrapperFactory.wrap(inventoryManager, ExecutionMode.ASYNC)
             .updateProductPrice(product, 123);
 
         assertTrue(