lizanle521 commented on issue #1779:
URL: 
https://github.com/apache/shardingsphere-elasticjob/issues/1779#issuecomment-748985721


   public class ConfigRegistryCenterFactory {
   
       private static final Map<HashCode, CoordinatorRegistryCenter> 
REG_CENTER_REGISTRY = new ConcurrentHashMap<>();
   
       /**
        * Create a {@link CoordinatorRegistryCenter} or return the existing one 
if there is one set up with the same {@code connectionString}, {@code 
namespace} and {@code digest} already.
        *
        * @param connectString registry center connect string
        * @param namespace registry center namespace
        * @param digest registry center digest
        * @return registry center
        */
       public static CoordinatorRegistryCenter 
createCoordinatorRegistryCenter(final String connectString, final String 
namespace, final String digest) {
           Hasher hasher = 
Hashing.sha256().newHasher().putString(connectString, 
StandardCharsets.UTF_8).putString(namespace, StandardCharsets.UTF_8);
           if (!Strings.isNullOrEmpty(digest)) {
               hasher.putString(digest, StandardCharsets.UTF_8);
           }
           HashCode hashCode = hasher.hash();
           return REG_CENTER_REGISTRY.computeIfAbsent(hashCode, unused -> {
               CoordinatorRegistryCenter result = 
newCoordinatorRegistryCenter(connectString, namespace, digest);
               result.init();
               return result;
           });
       }
   
       private static CoordinatorRegistryCenter 
newCoordinatorRegistryCenter(final String connectString,
                                                                             
final String namespace,
                                                                             
final String digest) {
           final ZookeeperConfiguration zkConfig = new 
ZookeeperConfiguration(connectString, namespace);
           if (!Strings.isNullOrEmpty(digest)) {
               zkConfig.setDigest(digest);
           }
           
           // connect to zk cluster slowly can cause this problem, set 
MaxSleepTimeMilliseconds can solve it 
           zkConfig.setMaxSleepTimeMilliseconds(30000);
           return new ZookeeperRegistryCenter(zkConfig);
       }
   }


----------------------------------------------------------------
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:
[email protected]


Reply via email to