You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2017/05/15 15:07:43 UTC

[07/19] isis git commit: ISIS-1613: updates AdapterManager's concurrency disabling stuff so that IsisWicketApplication can disable and reset externally.

ISIS-1613: updates AdapterManager's concurrency disabling stuff so that IsisWicketApplication can disable and reset externally.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/bb2bcdb2
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/bb2bcdb2
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/bb2bcdb2

Branch: refs/heads/ISIS-1613
Commit: bb2bcdb238bc9e7070ff8f06204e9d81100b5791
Parents: 415541b
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Mon May 15 10:12:22 2017 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Mon May 15 10:12:22 2017 +0100

----------------------------------------------------------------------
 .../metamodel/adapter/mgr/AdapterManager.java   | 32 +++++++++++++++++---
 1 file changed, 27 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/bb2bcdb2/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/mgr/AdapterManager.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/mgr/AdapterManager.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/mgr/AdapterManager.java
index 334eb08..ffcc8c8 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/mgr/AdapterManager.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/mgr/AdapterManager.java
@@ -72,7 +72,7 @@ public interface AdapterManager extends AdapterManagerBase {
         };
 
         /**
-         * Whether concurrency checking is currently disabled.
+         * Whether concurrency checking is currently enabled or disabled.
          */
         public static boolean isCurrentlyEnabled() {
             return concurrencyChecking.get().isChecking();
@@ -82,15 +82,37 @@ public interface AdapterManager extends AdapterManagerBase {
          * Allows a caller to temporarily disable concurrency checking for the current thread.
          */
         public static <T> T executeWithConcurrencyCheckingDisabled(final Callable<T> callable) {
-            final ConcurrencyChecking prior = ConcurrencyChecking.concurrencyChecking.get();
+            ConcurrencyChecking prior = null;
             try {
-                ConcurrencyChecking.concurrencyChecking.set(ConcurrencyChecking.NO_CHECK);
+                prior = disable();
                 return callable.call();
             } catch(Exception ex) {
                 throw new RuntimeException(ex);
             } finally {
-                ConcurrencyChecking.concurrencyChecking.set(prior);
+                reset(prior);
+            }
+        }
+
+        /**
+         * Recommended instead to call {@link #executeWithConcurrencyCheckingDisabled(Runnable)} or {@link #executeWithConcurrencyCheckingDisabled(Callable)}.
+         *
+         * <p>
+         *     If this method is used, then make sure to call {@link #reset(ConcurrencyChecking)} afterwards, using the value returned by this method.
+         * </p>
+         *
+         * @return the value of the {@link ConcurrencyChecking} thread-local prior to disabling it (to allow for nested calls).
+         */
+        public static ConcurrencyChecking disable() {
+            final ConcurrencyChecking prior = ConcurrencyChecking.concurrencyChecking.get();
+            ConcurrencyChecking.concurrencyChecking.set(ConcurrencyChecking.NO_CHECK);
+            return prior;
+        }
+
+        public static void reset(ConcurrencyChecking prior) {
+            if(prior == null) {
+                return;
             }
+            ConcurrencyChecking.concurrencyChecking.set(prior);
         }
 
         /**
@@ -99,7 +121,7 @@ public interface AdapterManager extends AdapterManagerBase {
         public static void executeWithConcurrencyCheckingDisabled(final Runnable runnable) {
             final ConcurrencyChecking prior = ConcurrencyChecking.concurrencyChecking.get();
             try {
-                ConcurrencyChecking.concurrencyChecking.set(ConcurrencyChecking.NO_CHECK);
+                disable();
                 runnable.run();
             } finally {
                 ConcurrencyChecking.concurrencyChecking.set(prior);