blob: 830ba45ef0fdb1365995539e2b7ffc9689decb02 (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.dispatch.rpc;
import com.google.common.collect.ImmutableMap;
import com.yahoo.compress.Compressor;
import com.yahoo.processing.request.CompoundName;
import com.yahoo.search.dispatch.FillInvoker;
import com.yahoo.vespa.config.search.DispatchConfig;
import java.util.Map;
/**
* RpcResourcePool constructs {@link FillInvoker} objects that communicate with content nodes over RPC. It also contains
* the RPC connection pool.
*
* @author ollivir
*/
public class RpcResourcePool {
/** The compression method which will be used with rpc dispatch. "lz4" (default) and "none" is supported. */
public final static CompoundName dispatchCompression = new CompoundName("dispatch.compression");
private final Compressor compressor = new Compressor();
private final Client client;
/** Connections to the search nodes this talks to, indexed by node id ("partid") */
private final ImmutableMap<Integer, Client.NodeConnection> nodeConnections;
public RpcResourcePool(Client client, Map<Integer, Client.NodeConnection> nodeConnections) {
this.client = client;
this.nodeConnections = ImmutableMap.copyOf(nodeConnections);
}
public RpcResourcePool(DispatchConfig dispatchConfig) {
this.client = new RpcClient();
// Create node rpc connections, indexed by the node distribution key
ImmutableMap.Builder<Integer, Client.NodeConnection> nodeConnectionsBuilder = new ImmutableMap.Builder<>();
for (DispatchConfig.Node node : dispatchConfig.node()) {
nodeConnectionsBuilder.put(node.key(), client.createConnection(node.host(), node.port()));
}
this.nodeConnections = nodeConnectionsBuilder.build();
}
public Compressor compressor() {
return compressor;
}
public Client client() {
return client;
}
public ImmutableMap<Integer, Client.NodeConnection> nodeConnections() {
return nodeConnections;
}
public void release() {
for (Client.NodeConnection nodeConnection : nodeConnections.values()) {
nodeConnection.close();
}
}
}
|