aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2018-06-07 10:29:54 +0200
committerMartin Polden <mpolden@mpolden.no>2018-06-07 10:59:56 +0200
commit50e109d812651a4e9f05db1df09f837859c1fd28 (patch)
tree4d2ceca1d369251f71d814382893d9abe38646aa /controller-server
parente114f3f407fb61d00b010c86159d0153f95161c5 (diff)
Remove unused Locks class
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/concurrent/Locks.java55
1 files changed, 0 insertions, 55 deletions
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
- * <code>
- * try (Lock lock = locks.lock(id)) {
- * exclusive use of the object with key id
- * }
- * </code>
- *
- * @author bratseth
- */
-public class Locks<TYPE> {
-
- private final Map<TYPE, ReentrantLock> 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 <b>must</b> 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);
- }
- }
-
-}