aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/messagebus/MessageBusParams.java
blob: c0e5b80dbff91bbd44466c0b81f5d7ad38f5bfa6 (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 Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi.messagebus;

import com.yahoo.documentapi.DocumentAccessParams;
import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol;
import com.yahoo.documentapi.messagebus.protocol.DocumentProtocolPoliciesConfig;
import com.yahoo.messagebus.SourceSessionParams;
import com.yahoo.messagebus.network.rpc.RPCNetworkParams;
import com.yahoo.vespa.config.content.DistributionConfig;

import static java.util.Objects.requireNonNull;

/**
 * @author Einar M R Rosenvinge
 */
public class MessageBusParams extends DocumentAccessParams {

    private String routingConfigId = null;
    private String protocolConfigId = null;
    private DocumentProtocolPoliciesConfig policiesConfig = null;
    private DistributionConfig distributionConfig = null;
    private String route = "route:default";
    private String routeForGet = "route:default-get";
    private int traceLevel = 0;
    private RPCNetworkParams rpcNetworkParams = new RPCNetworkParams();
    private com.yahoo.messagebus.MessageBusParams mbusParams = new com.yahoo.messagebus.MessageBusParams();
    private SourceSessionParams sourceSessionParams = new SourceSessionParams();

    public MessageBusParams() {}

    /**
     * Returns the id to resolve to routing config.
     *
     * @return The config id.
     */
    public String getRoutingConfigId() {
        return routingConfigId;
    }

    /**
     * Sets the id to resolve to routing config. This has a proper default value that holds for Vespa applications, and
     * can therefore be left unset.
     *
     * @param configId The config id.
     * @return This object for chaining.
     */
    public MessageBusParams setRoutingConfigId(String configId) {
        routingConfigId = configId;
        return this;
    }

    /**
     * Returns the id to resolve to protocol config.
     *
     * @return The config id.
     */
    public String getProtocolConfigId() {
        return protocolConfigId;
    }

    /**
     * Sets the id to resolve to protocol config. This has a proper default value that holds for Vespa applications,
     * and can therefore be left usnet.
     *
     * @param configId The config id.
     * @return This, to allow chaining.
     */
    public MessageBusParams setProtocolConfigId(String configId) {
        protocolConfigId = configId;
        return this;
    }

    /** Sets the config used by the {@link DocumentProtocol} policies. */
    public MessageBusParams setDocumentProtocolPoliciesConfig(DocumentProtocolPoliciesConfig policiesConfig,
                                                              DistributionConfig distributionConfig) {
        this.policiesConfig = requireNonNull(policiesConfig);
        this.distributionConfig = requireNonNull(distributionConfig);
        return this;
    }

    /**
     * Sets the name of the route to send appropriate requests to. This is a convenience method for prefixing a route
     * with "route:", and using {@link #setRoute} instead.
     *
     * @param routeName The route name.
     * @return This object for chaining.
     */
    public MessageBusParams setRouteName(String routeName) {
        return setRoute("route:" + routeName);
    }

    /**
     * Sets the route string to send all requests to. This string will be parsed as a route string, so setting a route
     * name directly will not necessarily have the intended consequences. Use "route:<routename>" syntax for route
     * names, or the convenience method {@link #setRouteName} for this.
     *
     * @param route The route string.
     * @return This object for chaining.
     */
    public MessageBusParams setRoute(String route) {
        this.route = route;
        return this;
    }

    public MessageBusParams setRouteNameForGet(String routeName) {
        return setRouteForGet("route:" + routeName);
    }
    public MessageBusParams setRouteForGet(String route) {
        this.routeForGet = route;
        return this;
    }

    /**
     * Returns the route string that all requests will be sent to.
     *
     * @return The route string.
     */
    public String getRoute() {
        return route;
    }

    public String getRouteForGet() {
        return routeForGet;
    }

    /**
     * Returns the trace level to use when sending.
     *
     * @return The trace level.
     */
    public int getTraceLevel() {
        return traceLevel;
    }

    /**
     * Sets the trace level to use when sending.
     *
     * @param traceLevel The trace level.
     * @return This object for chaining.
     */
    public MessageBusParams setTraceLevel(int traceLevel) {
        this.traceLevel = traceLevel;
        return this;
    }

    /**
     * Returns the params object used to instantiate the rpc network layer for message bus.
     *
     * @return The params object.
     */
    public RPCNetworkParams getRPCNetworkParams() {
        return rpcNetworkParams;
    }

    /**
     * Sets the params object used to instantiate the rpc network layer for message bus.
     *
     * @param params The params object.
     * @return This object for chaining.
     */
    public MessageBusParams setRPCNetworkParams(RPCNetworkParams params) {
        rpcNetworkParams = new RPCNetworkParams(params);
        return this;
    }

    /**
     * Returns the params object used to instantiate the message bus.
     *
     * @return The params object.
     */
    public com.yahoo.messagebus.MessageBusParams getMessageBusParams() {
        return mbusParams;
    }

    /**
     * Sets the params object used to instantiate the message bus.
     *
     * @param params The params object.
     * @return This object for chaining.
     */
    public MessageBusParams setMessageBusParams(com.yahoo.messagebus.MessageBusParams params) {
        mbusParams = new com.yahoo.messagebus.MessageBusParams(params);
        return this;
    }

    /**
     * Returns a reference to the extended source session params object.
     *
     * @return The params object.
     */
    public SourceSessionParams getSourceSessionParams() {
        return sourceSessionParams;
    }

    /**
     * Sets the extended source session params.
     *
     * @param params The params object.
     * @return This object for chaining.
     */
    public MessageBusParams setSourceSessionParams(SourceSessionParams params) {
        sourceSessionParams = new SourceSessionParams(params);
        return this;
    }
}