Skip to content

Commit

Permalink
CuratorFramework is started immediately
Browse files Browse the repository at this point in the history
Start framework in the ctor to allow other bundles to interact with
zookeeper during their run() method.
  • Loading branch information
Felix Braun committed Oct 10, 2014
1 parent 48196c6 commit 9ad6672
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static com.google.common.base.Preconditions.checkNotNull;
import io.dropwizard.lifecycle.Managed;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.imps.CuratorFrameworkState;
import org.apache.curator.utils.EnsurePath;

public class CuratorManager implements Managed {
Expand All @@ -17,11 +19,16 @@ public class CuratorManager implements Managed {
*/
public CuratorManager(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.start();
// framework was already started in ctor,
// ensure that the root path is available
new EnsurePath("/").ensure(framework.getZookeeperClient());
}
Expand Down

0 comments on commit 9ad6672

Please sign in to comment.