From 50e109d812651a4e9f05db1df09f837859c1fd28 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Thu, 7 Jun 2018 10:29:54 +0200 Subject: Remove unused Locks class --- .../vespa/hosted/controller/concurrent/Locks.java | 55 ---------------------- 1 file changed, 55 deletions(-) delete mode 100644 controller-server/src/main/java/com/yahoo/vespa/hosted/controller/concurrent/Locks.java (limited to 'controller-server') diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/concurrent/Locks.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/concurrent/Locks.java deleted file mode 100644 index 6168812203a..00000000000 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/concurrent/Locks.java +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.hosted.controller.concurrent; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.ReentrantLock; - -/** - * Holds a map of locks indexed on keys of a given type. - * This is suitable in cases where exclusive access should be granted to any one of a set of keyed objects and - * there is a finite collection of keyed objects. - * - * The returned locks are reentrant (i.e the owning thread may call lock multiple times) and auto-closable. - * - * Typical use is - * - * try (Lock lock = locks.lock(id)) { - * exclusive use of the object with key id - * } - * - * - * @author bratseth - */ -public class Locks { - - private final Map locks = new ConcurrentHashMap<>(); - - private final long timeoutMs; - - public Locks(int timeout, TimeUnit timeoutUnit) { - timeoutMs = timeoutUnit.toMillis(timeout); - } - - /** - * Locks key. This will block until the key is acquired. - * Users of this must close any lock acquired. - * - * @param key the key to lock - * @return the acquired lock - * @throws TimeoutException if the lock could not be acquired within the timeout - */ - public Lock lock(TYPE key) { - try { - ReentrantLock lock = locks.computeIfAbsent(key, k -> new ReentrantLock(true)); - boolean acquired = lock.tryLock(timeoutMs, TimeUnit.MILLISECONDS); - if ( ! acquired) - throw new TimeoutException("Timed out waiting for the lock to " + key); - return new Lock(lock); - } catch (InterruptedException e) { - throw new RuntimeException("Interrupted while waiting for lock of " + key); - } - } - -} -- cgit v1.2.3