package com.friday.custody.common;


import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.locks.ReentrantLock;

public class CacheLockMap {
    private static final Map<String, ReentrantLock> cacheLockMap = new HashMap<>();

    public static synchronized void put(String key, ReentrantLock value) {
        cacheLockMap.put(key, value);
    }

    public static synchronized ReentrantLock get(String key) {
        ReentrantLock lock = cacheLockMap.get(key);
        if (Objects.isNull(lock)) {
            lock = new ReentrantLock();
            cacheLockMap.put(key, lock);
        }
        return lock;
    }

    public static synchronized void remove(String key) {
        cacheLockMap.remove(key);
    }
}