aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/vespa/messagebus/network/rpcnetworkparams.h
blob: a4b752f46d411f7a1521cef40b0454719ce2f002 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "identity.h"
#include <vespa/slobrok/cfg.h>
#include <vespa/vespalib/util/compressionconfig.h>

namespace mbus {

/**
 * To facilitate several configuration parameters to the {@link RPCNetwork} constructor, all parameters are
 * held by this class. This class has reasonable default values for each parameter.
 */
class RPCNetworkParams {
public:
    enum class OptimizeFor { LATENCY, THROUGHPUT};
    using CompressionConfig = vespalib::compression::CompressionConfig;

    RPCNetworkParams();
    RPCNetworkParams(config::ConfigUri configUri);
    ~RPCNetworkParams();

    /**
     * Returns the identity to use for the network.
     *
     * @return The identity.
     */
    const Identity &getIdentity() const {
        return _identity;
    }

    /**
     * Sets the identity to use for the network.
     *
     * @param identity The new identity.
     * @return This, to allow chaining.
     */
    RPCNetworkParams &setIdentity(const Identity &identity) {
        _identity = identity;
        return *this;
    }

    /**
     * Sets the identity to use for the network.
     *
     * @param identity A string representation of the identity.
     * @return This, to allow chaining.
     */
    RPCNetworkParams &setIdentity(const string &identity) {
        return setIdentity(Identity(identity));
    }

    /**
     * Returns the config id of the slobrok config.
     *
     * @return The config id.
     */
    const config::ConfigUri & getSlobrokConfig() const {
        return _slobrokConfig;
    }

    /**
     *
     */

    /**
     * Returns the port to listen to.
     *
     * @return The port.
     */
    int getListenPort() const {
        return _listenPort;
    }

    /**
     * Sets the port to listen to.
     *
     * @param listenPort The new port.
     * @return This, to allow chaining.
     */
    RPCNetworkParams &setListenPort(int listenPort) {
        _listenPort = listenPort;
        return *this;
    }

    /**
     * Sets number of threads for the thread pool.
     *
     * @param numThreads number of threads for thread pool
     * @return This, to allow chaining.
     */
    RPCNetworkParams &setNumThreads(uint32_t numThreads) {
        _numThreads = numThreads;
        return *this;
    }

    uint32_t getNumThreads() const { return _numThreads; }

    RPCNetworkParams &setOptimizeFor(OptimizeFor tcpNoDelay) {
        _optimizeFor = tcpNoDelay;
        return *this;
    }

    OptimizeFor getOptimizeFor() const { return _optimizeFor; }

    /**
     * Returns the number of seconds before an idle network connection expires.
     *
     * @return The number of seconds.
     */
    double getConnectionExpireSecs() const{
        return _connectionExpireSecs;
    }

    /**
     * Sets the number of seconds before an idle network connection expires.
     *
     * @param secs The number of seconds.
     * @return This, to allow chaining.
     */
    RPCNetworkParams &setConnectionExpireSecs(double secs) {
        _connectionExpireSecs = secs;
        return *this;
    }

    /**
     * Returns the maximum input buffer size allowed for the underlying FNET connection.
     *
     * @return The maximum number of bytes.
     */
    uint32_t getMaxInputBufferSize() const {
        return _maxInputBufferSize;
    }

    /**
     * Sets the maximum input buffer size allowed for the underlying FNET connection. Using the value 0 means that there
     * is no limit; the connection will not free any allocated memory until it is cleaned up. This might potentially
     * save alot of allocation time.
     *
     * @param maxInputBufferSize The maximum number of bytes.
     * @return This, to allow chaining.
     */
    RPCNetworkParams &setMaxInputBufferSize(uint32_t maxInputBufferSize) {
        _maxInputBufferSize = maxInputBufferSize;
        return *this;
    }

    /**
     * Returns the maximum output buffer size allowed for the underlying FNET connection.
     *
     * @return The maximum number of bytes.
     */
    uint32_t getMaxOutputBufferSize() const {
        return _maxOutputBufferSize;
    }

    /**
     * Sets the maximum output buffer size allowed for the underlying FNET connection. Using the value 0 means that there
     * is no limit; the connection will not free any allocated memory until it is cleaned up. This might potentially
     * save alot of allocation time.
     *
     * @param maxOutputBufferSize The maximum number of bytes.
     * @return This, to allow chaining.
     */
    RPCNetworkParams &setMaxOutputBufferSize(uint32_t maxOutputBufferSize) {
        _maxOutputBufferSize = maxOutputBufferSize;
        return *this;
    }

    RPCNetworkParams &setCompressionConfig(CompressionConfig compressionConfig) {
        _compressionConfig = compressionConfig;
        return *this;
    }
    CompressionConfig getCompressionConfig() const { return _compressionConfig; }


    RPCNetworkParams &setDispatchOnDecode(bool dispatchOnDecode) {
        _dispatchOnDecode = dispatchOnDecode;
        return *this;
    }

    uint32_t getDispatchOnDecode() const { return _dispatchOnDecode; }

    RPCNetworkParams &setDispatchOnEncode(bool dispatchOnEncode) {
        _dispatchOnEncode = dispatchOnEncode;
        return *this;
    }

    uint32_t getDispatchOnEncode() const { return _dispatchOnEncode; }
private:
    Identity          _identity;
    config::ConfigUri _slobrokConfig;
    int               _listenPort;
    uint32_t          _maxInputBufferSize;
    uint32_t          _maxOutputBufferSize;
    uint32_t          _numThreads;
    OptimizeFor       _optimizeFor;
    bool              _dispatchOnEncode;
    bool              _dispatchOnDecode;
    double            _connectionExpireSecs;
    CompressionConfig _compressionConfig;
};

}