aboutsummaryrefslogtreecommitdiffstats
path: root/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/LockedNodeList.java
blob: 7282867bc56484b660fa4ef870f8fec6a7d4b9c8 (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 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;

import java.util.List;
import java.util.Objects;

/**
 * A type-safe wrapper for {@link NodeList}. Callers that have a reference to this can safely be assumed to be holding
 * the allocation lock for the node repository.
 *
 * This is typically used in situations where modifying a node object depends on inspecting a consistent state of all
 * nodes in the repository.
 *
 * @author mpolden
 */
public final class LockedNodeList extends NodeList {

    private final Mutex lock;

    public LockedNodeList(List<Node> nodes, Mutex lock) {
        super(nodes, false);
        this.lock = Objects.requireNonNull(lock, "lock must be non-null");
    }

    /** Returns a new LockedNodeList with the same lock. */
    public LockedNodeList childList(List<Node> nodes) {
        return new LockedNodeList(nodes, lock);
    }

}