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

io.dropwizard.discovery.manage.CuratorManager Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package io.dropwizard.discovery.manage;

import static com.google.common.base.Preconditions.checkNotNull;
import io.dropwizard.lifecycle.Managed;
import javax.annotation.Nonnull;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.imps.CuratorFrameworkState;
import org.apache.curator.utils.EnsurePath;

public class CuratorManager implements Managed {

    private final CuratorFramework framework;

    /**
     * Constructor
     * 
     * @param framework
     *            {@link CuratorFramework}
     */
    public CuratorManager(@Nonnull final CuratorFramework framework) {
        this.framework = checkNotNull(framework);
        // start framework directly to allow other bundles to interact with
        // zookeeper during their run() method.
        if (framework.getState() != CuratorFrameworkState.STARTED) {
            framework.start();
        }
    }

    @Override
    public void start() throws Exception {
        // framework was already started in constructor
        // ensure that the root path is available
        new EnsurePath("/").ensure(framework.getZookeeperClient());
    }

    @Override
    public void stop() throws Exception {
        framework.close();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy