<commit_before>package com.andyadc.scaffold.lock.zookeeper.menagerie.lock;

import com.andyadc.scaffold.lock.DLock;
import com.andyadc.zookeeper.ZkPrimitive;
import com.andyadc.zookeeper.ZkSessionManager;
import com.andyadc.zookeeper.ZkUtils;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;

import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author andaicheng
 * @version 2017/5/10
 */
public class ReentrantZkLock extends ZkPrimitive implements DLock {

    private static final String lockPrefix = "lock";

    /**
     * A default delimiter to separate a lockPrefix from the sequential elements set by ZooKeeper.
     */
    protected static final char lockDelimiter = '-';

    private final ThreadLocal<LockHolder> locks = new ThreadLocal<>();

    /**
     * Constructs a new Lock on the specified node, using Open ACL privileges.
     *
     * @param baseNode         the node to lock on
     * @param zkSessionManager the session manager to use.
     */
    public ReentrantZkLock(String baseNode, ZkSessionManager zkSessionManager) {
        super(baseNode, zkSessionManager, ZooDefs.Ids.OPEN_ACL_UNSAFE);
    }

    @Override
    public final void lock() throws Exception {
        if (checkReentrancy()) {
            return;
        }

        //set a connection listener to listen for session expiration
        setConnectionListener();

        ZooKeeper zk = zkSessionManager.getZooKeeper();

        String lockNode;
        try {
            lockNode = zk.create(getBaseLockPath(), emptyNode, privileges, CreateMode.EPHEMERAL_SEQUENTIAL);


        } catch (KeeperException e) {

        } catch (InterruptedException e) {

        }

    }

    @Override<commit_msg>ReentrantZkLock<commit_after>package com.andyadc.scaffold.lock.zookeeper.menagerie.lock;

import com.andyadc.scaffold.lock.DLock;
import com.andyadc.zookeeper.ZkPrimitive;
import com.andyadc.zookeeper.ZkSessionManager;
import com.andyadc.zookeeper.ZkUtils;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;

import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author andaicheng
 * @version 2017/5/10
 */
public class ReentrantZkLock extends ZkPrimitive implements DLock {

    private static final String lockPrefix = "lock";

    /**
     * A default delimiter to separate a lockPrefix from the sequential elements set by ZooKeeper.
     */
    protected static final char lockDelimiter = '-';

    private final ThreadLocal<LockHolder> locks = new ThreadLocal<>();

    /**
     * Constructs a new Lock on the specified node, using Open ACL privileges.
     *
     * @param baseNode         the node to lock on
     * @param zkSessionManager the session manager to use.
     */
    public ReentrantZkLock(String baseNode, ZkSessionManager zkSessionManager) {
        super(baseNode, zkSessionManager, ZooDefs.Ids.OPEN_ACL_UNSAFE);
    }

    @Override
    public final void lock() throws Exception {
        if (checkReentrancy()) {
            return;
        }

        //set a connection listener to listen for session expiration
        setConnectionListener();

        ZooKeeper zk = zkSessionManager.getZooKeeper();

        String lockNode;
        try {
            lockNode = zk.create(getBaseLockPath(), emptyNode, privileges, CreateMode.EPHEMERAL_SEQUENTIAL);

            while (true) {
                if (broken)
                    throw new RuntimeException("ZooKeeper Session has expired, invalidating this lock object");

                localLock.unlock();
                try {
                    //ask ZooKeeper for the lock
                    boolean acquiredLock = tryAcquireDistributed(zk, lockNode, true);
                    if (!acquiredLock) {
                        //we don't have the lock, so we need to wait for our watcher to fire
                        //this method is not interruptible, so need to wait appropriately
                        condition.awaitUninterruptibly();
                    } else {
                        //we have the lock, so return happy
                        locks.set(new LockHolder(lockNode));
                        return;
                    }
                } finally {
                    localLock.unlock();
                }
            }
        } catch (KeeperException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } finally {
            //we no longer care about having a ConnectionListener here
            removeConnectionListener();
        }

    }

    @Override
{'fraction_non_alphanumeric': 0.08180904522613065, 'fraction_numerical': 0.002814070351758794, 'mean_word_length': 2.408219178082192, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '424998', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1358, 'n_words': 363}