/
DefaultAmqp10Config.java
201 lines (175 loc) · 8.03 KB
/
DefaultAmqp10Config.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
/*
* Copyright (c) 2020 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.connectivity.service.config;
import java.time.Duration;
import java.util.Map;
import java.util.Objects;
import javax.annotation.concurrent.Immutable;
import org.eclipse.ditto.base.service.config.ThrottlingConfig;
import org.eclipse.ditto.internal.utils.config.ConfigWithFallback;
import org.eclipse.ditto.internal.utils.config.ScopedConfig;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
/**
* This class is the default implementation of {@link Amqp10Config}.
*/
@Immutable
public final class DefaultAmqp10Config implements Amqp10Config, WithStringMapDecoding {
private static final String CONFIG_PATH = "amqp10";
private static final String CONSUMER_PATH = "consumer";
private static final String BACKOFF_PATH = "backoff";
private final boolean consumerRateLimitEnabled;
private final int consumerMaxInFlight;
private final Duration consumerRedeliveryExpectationTimeout;
private final int producerCacheSize;
private final BackOffConfig backOffConfig;
private final ThrottlingConfig consumerThrottlingConfig;
private final int maxQueueSize;
private final int messagePublishingParallelism;
private final Duration globalConnectTimeout;
private final Duration globalSendTimeout;
private final Duration globalRequestTimeout;
private final int globalPrefetchPolicyAllCount;
private final Map<String, String> hmacAlgorithms;
private DefaultAmqp10Config(final ScopedConfig config) {
consumerRateLimitEnabled = config.getBoolean(Amqp10ConfigValue.CONSUMER_RATE_LIMIT_ENABLED.getConfigPath());
consumerMaxInFlight = config.getInt(Amqp10ConfigValue.CONSUMER_MAX_IN_FLIGHT.getConfigPath());
consumerRedeliveryExpectationTimeout =
config.getDuration(Amqp10ConfigValue.CONSUMER_REDELIVERY_EXPECTATION_TIMEOUT.getConfigPath());
producerCacheSize = config.getInt(Amqp10ConfigValue.PRODUCER_CACHE_SIZE.getConfigPath());
backOffConfig = DefaultBackOffConfig.of(config.hasPath(BACKOFF_PATH)
? config
: ConfigFactory.parseString(BACKOFF_PATH + "={}"));
consumerThrottlingConfig = ThrottlingConfig.of(config.hasPath(CONSUMER_PATH)
? config.getConfig(CONSUMER_PATH)
: ConfigFactory.empty());
maxQueueSize = config.getInt(Amqp10ConfigValue.MAX_QUEUE_SIZE.getConfigPath());
messagePublishingParallelism = config.getInt(Amqp10ConfigValue.MESSAGE_PUBLISHING_PARALLELISM.getConfigPath());
globalConnectTimeout = config.getDuration(Amqp10ConfigValue.GLOBAL_CONNECT_TIMEOUT.getConfigPath());
globalSendTimeout = config.getDuration(Amqp10ConfigValue.GLOBAL_SEND_TIMEOUT.getConfigPath());
globalRequestTimeout = config.getDuration(Amqp10ConfigValue.GLOBAL_REQUEST_TIMEOUT.getConfigPath());
globalPrefetchPolicyAllCount =
config.getInt(Amqp10ConfigValue.GLOBAL_PREFETCH_POLICY_ALL_COUNT.getConfigPath());
hmacAlgorithms = asStringMap(config, HttpPushConfig.ConfigValue.HMAC_ALGORITHMS.getConfigPath());
}
/**
* Returns an instance of {@code DefaultAmqp10Config} based on the settings of the specified Config.
*
* @param config is supposed to provide the settings of the JavaScript mapping config at {@value #CONFIG_PATH}.
* @return the instance.
* @throws org.eclipse.ditto.internal.utils.config.DittoConfigError if {@code config} is invalid.
*/
public static DefaultAmqp10Config of(final Config config) {
return new DefaultAmqp10Config(ConfigWithFallback.newInstance(config, CONFIG_PATH, Amqp10ConfigValue.values()));
}
@Override
public boolean isConsumerRateLimitEnabled() {
return consumerRateLimitEnabled;
}
@Override
public int getConsumerMaxInFlight() {
return consumerMaxInFlight;
}
@Override
public Duration getConsumerRedeliveryExpectationTimeout() {
return consumerRedeliveryExpectationTimeout;
}
@Override
public ThrottlingConfig getConsumerThrottlingConfig() {
return consumerThrottlingConfig;
}
@Override
public int getProducerCacheSize() {
return producerCacheSize;
}
@Override
public BackOffConfig getBackOffConfig() {
return backOffConfig;
}
@Override
public int getMaxQueueSize() {
return maxQueueSize;
}
@Override
public int getPublisherParallelism() {
return messagePublishingParallelism;
}
@Override
public Duration getGlobalConnectTimeout() {
return globalConnectTimeout;
}
@Override
public Duration getGlobalSendTimeout() {
return globalSendTimeout;
}
@Override
public Duration getGlobalRequestTimeout() {
return globalRequestTimeout;
}
@Override
public int getGlobalPrefetchPolicyAllCount() {
return globalPrefetchPolicyAllCount;
}
@Override
public Map<String, String> getHmacAlgorithms() {
return hmacAlgorithms;
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final DefaultAmqp10Config that = (DefaultAmqp10Config) o;
return consumerRateLimitEnabled == that.consumerRateLimitEnabled &&
consumerMaxInFlight == that.consumerMaxInFlight &&
producerCacheSize == that.producerCacheSize &&
globalPrefetchPolicyAllCount == that.globalPrefetchPolicyAllCount &&
Objects.equals(consumerRedeliveryExpectationTimeout, that.consumerRedeliveryExpectationTimeout) &&
Objects.equals(backOffConfig, that.backOffConfig) &&
maxQueueSize == that.maxQueueSize &&
messagePublishingParallelism == that.messagePublishingParallelism &&
Objects.equals(consumerThrottlingConfig, that.consumerThrottlingConfig) &&
Objects.equals(globalConnectTimeout, that.globalConnectTimeout) &&
Objects.equals(globalSendTimeout, that.globalSendTimeout) &&
Objects.equals(globalRequestTimeout, that.globalRequestTimeout) &&
Objects.equals(hmacAlgorithms, that.hmacAlgorithms);
}
@Override
public int hashCode() {
return Objects.hash(consumerRateLimitEnabled, consumerMaxInFlight, consumerRedeliveryExpectationTimeout,
producerCacheSize, backOffConfig, consumerThrottlingConfig, maxQueueSize,
messagePublishingParallelism, globalConnectTimeout, globalSendTimeout, globalRequestTimeout,
globalPrefetchPolicyAllCount, hmacAlgorithms);
}
@Override
public String toString() {
return getClass().getSimpleName() + " [" +
"consumerRateLimitEnabled=" + consumerRateLimitEnabled +
", consumerMaxInFlight=" + consumerMaxInFlight +
", consumerRedeliveryExpectationTimeout=" + consumerRedeliveryExpectationTimeout +
", producerCacheSize=" + producerCacheSize +
", backOffConfig=" + backOffConfig +
", consumerThrottlingConfig=" + consumerThrottlingConfig +
", maxQueueSize=" + maxQueueSize +
", messagePublishingParallelism=" + messagePublishingParallelism +
", globalConnectTimeout=" + globalConnectTimeout +
", globalSendTimeout=" + globalSendTimeout +
", globalRequestTimeout=" + globalRequestTimeout +
", globalPrefetchPolicyAllCount=" + globalPrefetchPolicyAllCount +
", hmacAlgorithms=" + hmacAlgorithms +
"]";
}
}