* @param name the name for the {@link CuratorFramework} instance.
*
* @return a {@link CuratorFramework} instance, managed and configured.
*/
public CuratorFramework build(final Environment environment, final String name) {
final ZooKeeperFactory factory = getZooKeeperFactory();
final String namespace = factory.getNamespace();
final CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
.zookeeperFactory(new DropwizardConfiguredZooKeeperFactory(environment, name))
.ensembleProvider(new DropwizardConfiguredEnsembleProvider(factory))
.connectionTimeoutMs((int) factory.getConnectionTimeout().toMilliseconds())
.threadFactory(new ThreadFactoryBuilder().setNameFormat(name + "-%d").build())
.sessionTimeoutMs((int) factory.getSessionTimeout().toMilliseconds())
.namespace(namespace.startsWith("/") ? namespace.substring(1) : namespace)
.compressionProvider(getCompressionProvider())
.retryPolicy(getRetryPolicy())
.canBeReadOnly(factory.isReadOnly());
// add optional auth details
final ZooKeeperFactory.Auth auth = factory.getAuth();
if (auth != null) {
builder.authorization(auth.getScheme(), auth.getId().getBytes());
}
final CuratorFramework framework = builder.build();