*
* @return a {@link CuratorFramework} instance, managed and configured according to the {@code
* configuration}.
*/
public CuratorFramework build(final CuratorConfiguration configuration, final String name) {
final ZooKeeperConfiguration zkConfiguration = configuration.getEnsembleConfiguration();
final ZooKeeperFactory factory = new ZooKeeperFactory(environment);
final CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
.zookeeperFactory(new DropwizardConfiguredZooKeeperFactory(factory, name))
.ensembleProvider(new DropwizardConfiguredEnsembleProvider(zkConfiguration))
.connectionTimeoutMs((int) zkConfiguration.getConnectionTimeout().toMilliseconds())
.threadFactory(new ThreadFactoryBuilder().setNameFormat(name + "-%d").build())
.sessionTimeoutMs((int) zkConfiguration.getSessionTimeout().toMilliseconds())
.namespace(zkConfiguration.getNamespace())
.compressionProvider(configuration.getCompressionProvider())
.retryPolicy(configuration.getRetryPolicy())
.canBeReadOnly(zkConfiguration.canBeReadOnly());
// add optional auth details
final ZooKeeperConfiguration.Auth auth = zkConfiguration.getAuth();
if (auth != null) {
builder.authorization(auth.getScheme(), auth.getId());
}
final CuratorFramework framework = builder.build();