You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2019/06/13 15:08:20 UTC

[GitHub] [accumulo] keith-turner commented on a change in pull request #1201: fix #1123 replace observing config with continual derivation

keith-turner commented on a change in pull request #1201: fix #1123 replace observing config with continual derivation
URL: https://github.com/apache/accumulo/pull/1201#discussion_r293429897
 
 

 ##########
 File path: core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
 ##########
 @@ -435,6 +438,60 @@ Integer getDeprecatedScanThreads(String name) {
     return null;
   }
 
+  private static class RefCount<T> {
+    T obj;
+    long count;
+
+    RefCount(long c, T r) {
+      this.count = c;
+      this.obj = r;
+    }
+  }
+
+  private class Deriver<T> implements Supplier<T> {
+
+    private AtomicReference<RefCount<T>> refref;
+    private Function<AccumuloConfiguration,T> factory;
+
+    Deriver(Function<AccumuloConfiguration,T> factory) {
+      this.factory = factory;
+      refref = new AtomicReference<>();
+    }
+
+    @Override
+    public T get() {
+      RefCount<T> rc = refref.get();
+
+      long uc = getUpdateCount();
+
+      if (rc == null || rc.count != uc) {
+        T newObj = factory.apply(AccumuloConfiguration.this);
+
+        RefCount<T> nrc = new RefCount<>(uc, newObj);
+        refref.compareAndSet(rc, nrc);
 
 Review comment:
   Yeah I thought about doing a loop but decided against this because no matter what you do, after this functions returns the object could immediately become stale.  So I concluded the cycles would be needlessly spent trying to accomplish a goal that can never be accomplished.  I will add a comment about why the return value is ignored and a loop was not used. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services