blob: 20c246b3ebd071d52cf61a3d7d5865cd8aed2d04 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.provision;
import com.yahoo.transaction.Mutex;
/**
* Holds a node and mutex pair, with the mutex closed by {@link #close()}.
*
* @author hakon
*/
public class NodeMutex implements Mutex {
private final Node node;
private final Mutex mutex;
public NodeMutex(Node node, Mutex mutex) {
this.node = node;
this.mutex = mutex;
}
public Node node() { return node; }
@Override public void close() { mutex.close(); }
/** Returns a node mutex with the same mutex as this, but the given node. Be sure to close only one. */
public NodeMutex with(Node updatedNode) {
if (!node.equals(updatedNode)) {
throw new IllegalArgumentException("Updated node not equal to current");
}
return new NodeMutex(updatedNode, mutex);
}
}
|