<commit_before>/**
 * Copyright (c) 2016, All Contributors (see CONTRIBUTORS file)
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.eventsourcing.repository;

import com.eventsourcing.Lock;
import com.eventsourcing.repository.LockProvider;
import com.google.common.util.concurrent.AbstractService;
import org.osgi.service.component.annotations.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Semaphore;

/**
 * Local, in-memory lock provider
 */
@Component(property = {"type=MemoryLockProvider"})
public class LocalLockProvider extends AbstractService implements LockProvider {
    private Map<Object, Semaphore> locks = new HashMap<>();

    @Override
    public Lock lock(Object lock) {
        Semaphore semaphore = locks.containsKey(lock) ? locks.get(lock) : new Semaphore(1);
        locks.put(lock, semaphore);
        semaphore.acquireUninterruptibly();
        return new MemoryLock(semaphore);
    }

    @Override
    protected void doStart() {
        notifyStarted();
    }

    @Override
    protected void doStop() {
        notifyStopped();
    }

    static class MemoryLock implements Lock {
        private final Semaphore semaphore;

        public MemoryLock(Semaphore semaphore) {
            this.semaphore = semaphore;
        }
<commit_msg>Problem: LocalLock is still being named MemoryLock in a few places<commit_after>/**
 * Copyright (c) 2016, All Contributors (see CONTRIBUTORS file)
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.eventsourcing.repository;

import com.eventsourcing.Lock;
import com.google.common.util.concurrent.AbstractService;
import org.osgi.service.component.annotations.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Semaphore;

/**
 * Local, in-memory lock provider
 */
@Component(property = {"type=LocalLockProvider"})
public class LocalLockProvider extends AbstractService implements LockProvider {
    private Map<Object, Semaphore> locks = new HashMap<>();

    @Override
    public Lock lock(Object lock) {
        Semaphore semaphore = locks.containsKey(lock) ? locks.get(lock) : new Semaphore(1);
        locks.put(lock, semaphore);
        semaphore.acquireUninterruptibly();
        return new LocalLock(semaphore);
    }

    @Override
    protected void doStart() {
        notifyStarted();
    }

    @Override
    protected void doStop() {
        notifyStopped();
    }

    static class LocalLock implements Lock {
        private final Semaphore semaphore;

        public LocalLock(Semaphore semaphore) {
            this.semaphore = semaphore;
        }

{'fraction_non_alphanumeric': 0.09725516773974924, 'fraction_numerical': 0.006099627245001694, 'mean_word_length': 3.392857142857143, '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': '683450', 'n_tokens_mistral': 860, 'n_tokens_neox': 825, 'n_words': 246}