-
Notifications
You must be signed in to change notification settings - Fork 215
/
RouteBaseProperties.java
263 lines (234 loc) · 9.22 KB
/
RouteBaseProperties.java
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.gateway.service.endpoints.routes;
import java.util.Objects;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import org.eclipse.ditto.base.model.common.ConditionChecker;
import org.eclipse.ditto.base.model.headers.translator.HeaderTranslator;
import org.eclipse.ditto.gateway.service.util.config.endpoints.CommandConfig;
import org.eclipse.ditto.gateway.service.util.config.endpoints.HttpConfig;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
/**
* Base properties of each {@link AbstractRoute} implementation.
*/
@NotThreadSafe
public final class RouteBaseProperties {
private final ActorRef proxyActor;
private final ActorSystem actorSystem;
private final HttpConfig httpConfig;
private final CommandConfig commandConfig;
private final HeaderTranslator headerTranslator;
private final ActorRef connectivityShardRegionProxy;
private RouteBaseProperties(final Builder builder) {
proxyActor = ConditionChecker.checkNotNull(builder.proxyActor, "builder.proxyActor");
actorSystem = ConditionChecker.checkNotNull(builder.actorSystem, "builder.actorSystem");
httpConfig = ConditionChecker.checkNotNull(builder.httpConfig, "builder.httpConfig");
commandConfig = ConditionChecker.checkNotNull(builder.commandConfig, "builder.commandConfig");
headerTranslator = ConditionChecker.checkNotNull(builder.headerTranslator, "builder.headerTranslator");
connectivityShardRegionProxy = ConditionChecker.checkNotNull(builder.connectivityShardRegionProxy,
"builder.connectivityShardRegionProxy");
}
/**
* Returns a mutable builder with a fluent API for creating a {@code RouteBaseProperties} object.
*
* @return the builder.
*/
public static Builder newBuilder() {
return new Builder();
}
/**
* Returns a mutable builder with a fluent API for creating a {@code RouteBaseProperties} object.
*
* @param routeBaseProperties the initial properties of the returned builder
* @return the builder.
* @throws NullPointerException if {@code routeBaseProperties} is {@code null}.
*/
public static Builder newBuilder(final RouteBaseProperties routeBaseProperties) {
ConditionChecker.checkNotNull(routeBaseProperties, "routeBaseProperties");
return newBuilder()
.proxyActor(routeBaseProperties.getProxyActor())
.actorSystem(routeBaseProperties.getActorSystem())
.httpConfig(routeBaseProperties.getHttpConfig())
.commandConfig(routeBaseProperties.getCommandConfig())
.headerTranslator(routeBaseProperties.getHeaderTranslator())
.connectivityShardRegionProxy(routeBaseProperties.getConnectivityShardRegionProxy());
}
/**
* Returns the proxy actor ref.
*
* @return the proxy actor ref.
*/
public ActorRef getProxyActor() {
return proxyActor;
}
/**
* Returns the actor system.
*
* @return the actor system.
*/
public ActorSystem getActorSystem() {
return actorSystem;
}
/**
* Returns the HTTP config.
*
* @return the HTTP config.
*/
public HttpConfig getHttpConfig() {
return httpConfig;
}
/**
* Returns the command config.
*
* @return the command config.
*/
public CommandConfig getCommandConfig() {
return commandConfig;
}
/**
* Returns the {@link HeaderTranslator}.
*
* @return the {@code HeaderTranslator}.
*/
public HeaderTranslator getHeaderTranslator() {
return headerTranslator;
}
/**
* Returns the connectivity shard region actor proxy reference.
*
* @return the connectivity shard region actor proxy reference.
*/
public ActorRef getConnectivityShardRegionProxy() {
return connectivityShardRegionProxy;
}
@Override
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final var that = (RouteBaseProperties) o;
return Objects.equals(proxyActor, that.proxyActor) &&
Objects.equals(actorSystem, that.actorSystem) &&
Objects.equals(httpConfig, that.httpConfig) &&
Objects.equals(commandConfig, that.commandConfig) &&
Objects.equals(headerTranslator, that.headerTranslator) &&
Objects.equals(connectivityShardRegionProxy, that.connectivityShardRegionProxy);
}
@Override
public int hashCode() {
return Objects.hash(proxyActor,
actorSystem,
httpConfig,
commandConfig,
headerTranslator,
connectivityShardRegionProxy);
}
@NotThreadSafe
public static final class Builder {
private ActorRef proxyActor;
private ActorSystem actorSystem;
private HttpConfig httpConfig;
private CommandConfig commandConfig;
private HeaderTranslator headerTranslator;
private ActorRef connectivityShardRegionProxy;
private Builder() {
proxyActor = null;
actorSystem = null;
httpConfig = null;
commandConfig = null;
headerTranslator = null;
connectivityShardRegionProxy = null;
}
/**
* Sets the specified proxy actor reference argument.
*
* @param proxyActor the proxy actor reference to be set.
* @return this builder to allow method chaining.
* @throws NullPointerException if {@code proxyActor} is {@code null}.
*/
public Builder proxyActor(final ActorRef proxyActor) {
this.proxyActor = ConditionChecker.checkNotNull(proxyActor, "proxyActor");
return this;
}
/**
* Sets the specified actor system argument.
*
* @param actorSystem the actor system to be set.
* @return this builder to allow method chaining.
* @throws NullPointerException if {@code actorSystem} is {@code null}.
*/
public Builder actorSystem(final ActorSystem actorSystem) {
this.actorSystem = ConditionChecker.checkNotNull(actorSystem, "actorSystem");
return this;
}
/**
* Sets the specified {@code HttpConfig} argument.
*
* @param httpConfig the config to be set.
* @return this builder to allow method chaining.
* @throws NullPointerException if {@code httpConfig} is {@code null}.
*/
public Builder httpConfig(final HttpConfig httpConfig) {
this.httpConfig = ConditionChecker.checkNotNull(httpConfig, "httpConfig");
return this;
}
/**
* Sets the specified {@code CommandConfig} argument.
*
* @param commandConfig the config to be set.
* @return this builder to allow method chaining.
* @throws NullPointerException if {@code commandConfig} is {@code null}.
*/
public Builder commandConfig(final CommandConfig commandConfig) {
this.commandConfig = ConditionChecker.checkNotNull(commandConfig, "commandConfig");
return this;
}
/**
* Sets the specified {@code HeaderTranslator} argument.
*
* @param headerTranslator the header translator to be set.
* @return this builder to allow method chaining.
* @throws NullPointerException if {@code headerTranslator} is {@code null}.
*/
public Builder headerTranslator(final HeaderTranslator headerTranslator) {
this.headerTranslator = ConditionChecker.checkNotNull(headerTranslator, "headerTranslator");
return this;
}
/**
* Sets the specified connectivity shard region actor proxy reference.
*
* @param connectivityShardRegionProxy the actor reference to be set.
* @return this builder to allow method chaining.
* @throws NullPointerException if {@code connectivityShardRegionProxy} is {@code null}.
*/
public Builder connectivityShardRegionProxy(final ActorRef connectivityShardRegionProxy) {
this.connectivityShardRegionProxy =
ConditionChecker.checkNotNull(connectivityShardRegionProxy, "connectivityShardRegionProxy");
return this;
}
/**
* Builds a {@code RouteBaseProperties} object with the properties set to this builder.
*
* @return the {@code RouteBaseProperties}.
* @throws NullPointerException if any required property is {@code null}.
*/
public RouteBaseProperties build() {
return new RouteBaseProperties(this);
}
}
}