<commit_before>package backtype.storm.nimbus;

import backtype.storm.Config;
import backtype.storm.utils.Utils;
import com.google.common.base.Preconditions;
import com.netflix.curator.framework.CuratorFramework;
import com.netflix.curator.framework.CuratorFrameworkFactory;
import com.netflix.curator.framework.recipes.locks.InterProcessMutex;
import com.netflix.curator.retry.RetryNTimes;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author slukjanov
 */
public class NimbusLeaderElections {
    private CuratorFramework client;
    private InterProcessMutex mutex;
    private volatile boolean hasLeadership;

    public NimbusLeaderElections() {
    }

    public void init(final Map conf, final String id) {
        try {
            Preconditions.checkNotNull(conf);
            client = createZkClient(conf);

            String mutexPath = (String) conf.get(Config.NIMBUS_ELECTIONS_ZOOKEEPER_ROOT);

            mutex = new InterProcessMutex(client, mutexPath) {
                @Override
                protected byte[] getLockNodeBytes() {
                    try {
                        return id == null ? null : id.getBytes("UTF-8");
                    } catch (UnsupportedEncodingException e) {
                        throw new RuntimeException("UTF-8 isn't supported", e);
                    }
                }<commit_msg>ensure mutex path to avoid NoNode exception<commit_after>package backtype.storm.nimbus;

import backtype.storm.Config;
import backtype.storm.utils.Utils;
import com.google.common.base.Preconditions;
import com.netflix.curator.framework.CuratorFramework;
import com.netflix.curator.framework.CuratorFrameworkFactory;
import com.netflix.curator.framework.recipes.locks.InterProcessMutex;
import com.netflix.curator.retry.RetryNTimes;
import com.netflix.curator.utils.ZKPaths;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author slukjanov
 */
public class NimbusLeaderElections {
    private CuratorFramework client;
    private InterProcessMutex mutex;
    private volatile boolean hasLeadership;

    public NimbusLeaderElections() {
    }

    public void init(final Map conf, final String id) {
        try {
            Preconditions.checkNotNull(conf);
            client = createZkClient(conf);

            String mutexPath = (String) conf.get(Config.NIMBUS_ELECTIONS_ZOOKEEPER_ROOT);

            ZKPaths.mkdirs(client.getZookeeperClient().getZooKeeper(), mutexPath);
            mutex = new InterProcessMutex(client, mutexPath) {
                @Override
                protected byte[] getLockNodeBytes() {
                    try {
                        return id == null ? null : id.getBytes("UTF-8");
                    } catch (UnsupportedEncodingException e) {
                        throw new RuntimeException("UTF-8 isn't supported", e);
                    }
                }
{'fraction_non_alphanumeric': 0.08874388254486133, 'fraction_numerical': 0.0013050570962479609, 'mean_word_length': 2.748166259168704, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4438199', 'n_tokens_mistral': 865, 'n_tokens_neox': 841, 'n_words': 174}