DELTASPIKE-1277 immediately reload if config got changed

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

Branch: refs/heads/master
Commit: 04cf7acd667d27ed8faebb6c1668a98ca7aa92a8
Parents: fa8bff8
Author: Mark Struberg <strub...@apache.org>
Authored: Tue Mar 6 16:52:33 2018 +0100
Committer: Mark Struberg <strub...@apache.org>
Committed: Tue Mar 6 16:52:33 2018 +0100

----------------------------------------------------------------------
 .../core/impl/config/TypedResolverImpl.java          | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/04cf7acd/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/TypedResolverImpl.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/TypedResolverImpl.java
 
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/TypedResolverImpl.java
index c7d3f85..f532f0e 100644
--- 
a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/TypedResolverImpl.java
+++ 
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/TypedResolverImpl.java
@@ -66,7 +66,10 @@ public class TypedResolverImpl<T> implements 
ConfigResolver.UntypedResolver<T>
     private boolean logChanges = false;
 
     private long cacheTimeMs = -1;
+
     private volatile long reloadAfter = -1;
+    private long lastReloadedAt = -1;
+
     private T lastValue = null;
 
 
@@ -211,10 +214,15 @@ public class TypedResolverImpl<T> implements 
ConfigResolver.UntypedResolver<T>
         long now = -1;
         if (cacheTimeMs > 0)
         {
-            now = System.currentTimeMillis();
+            now = System.nanoTime();
             if (now <= reloadAfter)
             {
-                return lastValue;
+                // now check if anything in the underlying Config got changed
+                long lastCfgChange = config.getLastChanged();
+                if (lastCfgChange < lastReloadedAt)
+                {
+                    return lastValue;
+                }
             }
         }
 
@@ -251,7 +259,8 @@ public class TypedResolverImpl<T> implements 
ConfigResolver.UntypedResolver<T>
 
         if (cacheTimeMs > 0)
         {
-            reloadAfter = now + cacheTimeMs;
+            reloadAfter = now + TimeUnit.MILLISECONDS.toNanos(cacheTimeMs);
+            lastReloadedAt = now;
         }
 
         return value;

Reply via email to