All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.singularity.SingularityCuratorProvider Maven / Gradle / Ivy

package com.hubspot.singularity;

import static com.google.common.base.Preconditions.checkNotNull;

import com.hubspot.singularity.config.SingularityConfiguration;
import com.hubspot.singularity.config.ZooKeeperConfiguration;
import javax.inject.Inject;
import javax.inject.Provider;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.state.SessionConnectionStateErrorPolicy;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SingularityCuratorProvider implements Provider {
  private static final Logger LOG = LoggerFactory.getLogger(
    SingularityCuratorProvider.class
  );

  private final CuratorFramework curatorFramework;

  @Inject
  public SingularityCuratorProvider(final SingularityConfiguration configuration) {
    checkNotNull(configuration, "configuration is null");

    ZooKeeperConfiguration zookeeperConfig = configuration.getZooKeeperConfiguration();

    this.curatorFramework =
      CuratorFrameworkFactory
        .builder()
        .defaultData(null)
        .connectionStateErrorPolicy(new SessionConnectionStateErrorPolicy())
        .sessionTimeoutMs(zookeeperConfig.getSessionTimeoutMillis())
        .connectionTimeoutMs(zookeeperConfig.getConnectTimeoutMillis())
        .connectString(zookeeperConfig.getQuorum())
        .retryPolicy(
          new ExponentialBackoffRetry(
            zookeeperConfig.getRetryBaseSleepTimeMilliseconds(),
            zookeeperConfig.getRetryMaxTries()
          )
        )
        .namespace(zookeeperConfig.getZkNamespace())
        .build();
  }

  @Override
  public CuratorFramework get() {
    return curatorFramework;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy