milleruntime commented on a change in pull request #560: Provide new Crypto 
interface & impl
URL: https://github.com/apache/accumulo/pull/560#discussion_r208011274
 
 

 ##########
 File path: 
core/src/main/java/org/apache/accumulo/core/security/crypto/CryptoServiceFactory.java
 ##########
 @@ -16,30 +16,30 @@
  */
 package org.apache.accumulo.core.security.crypto;
 
+import java.util.concurrent.atomic.AtomicReference;
+
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.core.spi.crypto.CryptoService;
 import org.apache.accumulo.core.spi.crypto.CryptoService.CryptoException;
 import org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader;
 
 public class CryptoServiceFactory {
-  private static CryptoService singleton = null;
+  private static AtomicReference<CryptoService> singleton = new 
AtomicReference<>();
 
   /**
    * Load the singleton class configured in {@link 
Property#INSTANCE_CRYPTO_SERVICE}
    */
   public static CryptoService getConfigured(AccumuloConfiguration conf) {
+    CryptoService cyptoService = singleton.get();
     String configuredClass = 
conf.get(Property.INSTANCE_CRYPTO_SERVICE.getKey());
-    if (singleton == null) {
-      singleton = loadCryptoService(configuredClass);
-      
singleton.init(conf.getAllPropertiesWithPrefix(Property.INSTANCE_CRYPTO_PREFIX));
-    } else {
-      if (!singleton.getClass().getName().equals(configuredClass)) {
-        singleton = loadCryptoService(configuredClass);
-        
singleton.init(conf.getAllPropertiesWithPrefix(Property.INSTANCE_CRYPTO_PREFIX));
-      }
+    if (cyptoService == null || 
!cyptoService.getClass().getName().equals(configuredClass)) {
+      CryptoService newCryptoService = loadCryptoService(configuredClass);
+      
newCryptoService.init(conf.getAllPropertiesWithPrefix(Property.INSTANCE_CRYPTO_PREFIX));
+      singleton.compareAndSet(cyptoService, newCryptoService);
+      return singleton.get();
 
 Review comment:
   Hmm OK I hadn't thought of that.

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


With regards,
Apache Git Services

Reply via email to