blob: ac518b3a7d9cadf3d6b9ceabd62200c560565de8 (
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model;
import java.util.ArrayList;
import java.util.List;
/**
* API for allocating network ports
* This class acts as a bridge between NetworkPortRequestor and HostPorts
* for a single call to allocatePorts(), gathering the resulting port
* allocations in a list of integers.
* @author arnej
*/
public class PortAllocBridge {
private HostPorts host;
private NetworkPortRequestor service;
private List<Integer> ports = new ArrayList<>();
public PortAllocBridge(HostPorts host, NetworkPortRequestor service) {
this.host = host;
this.service = service;
}
public int requirePort(int port, String suffix) {
int got = host.requireNetworkPort(port, service, suffix);
ports.add(got);
return got;
}
public int wantPort(int port, String suffix) {
int got = host.wantNetworkPort(port, service, suffix);
ports.add(got);
return got;
}
public int allocatePort(String suffix) {
int got = host.allocateNetworkPort(service, suffix);
ports.add(got);
return got;
}
public List<Integer> result() {
return ports;
}
}
|