All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.vespa.hosted.provision.NodeMutex Maven / Gradle / Ivy

There is a newer version: 8.441.21
Show newest version
// Copyright Vespa.ai. 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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy