-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathMqttConfigurationServiceImpl.java
More file actions
259 lines (214 loc) · 10.2 KB
/
MqttConfigurationServiceImpl.java
File metadata and controls
259 lines (214 loc) · 10.2 KB
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
/*
* Copyright 2019-present HiveMQ GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hivemq.configuration.service.impl;
import com.hivemq.configuration.service.MqttConfigurationService;
import com.hivemq.extension.sdk.api.annotations.NotNull;
import com.hivemq.mqtt.message.QoS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Singleton;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.KEEP_ALIVE_ALLOW_UNLIMITED_DEFAULT;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.KEEP_ALIVE_MAX_DEFAULT;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.MAXIMUM_QOS_DEFAULT;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.MAX_EXPIRY_INTERVAL_DEFAULT;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.MAX_QUEUED_MESSAGES_DEFAULT;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.ALLOW_DOLLAR_TOPICS_DEFAULT;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.QUEUED_MESSAGES_STRATEGY_DEFAULT;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.RETAINED_MESSAGES_ENABLED_DEFAULT;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.SERVER_RECEIVE_MAXIMUM_DEFAULT;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.SHARED_SUBSCRIPTIONS_ENABLED_DEFAULT;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.SUBSCRIPTION_IDENTIFIER_ENABLED_DEFAULT;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.TOPIC_ALIAS_ENABLED_DEFAULT;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.TOPIC_ALIAS_MAX_PER_CLIENT_DEFAULT;
import static com.hivemq.configuration.entity.mqtt.MqttConfigurationDefaults.WILDCARD_SUBSCRIPTIONS_ENABLED_DEFAULT;
import static com.hivemq.mqtt.message.connect.Mqtt5CONNECT.DEFAULT_MAXIMUM_PACKET_SIZE_NO_LIMIT;
import static com.hivemq.mqtt.message.connect.Mqtt5CONNECT.SESSION_EXPIRY_MAX;
/**
* @author Dominik Obermaier
* @author Florian Limpöck
*/
@Singleton
public class MqttConfigurationServiceImpl implements MqttConfigurationService {
private static final Logger log = LoggerFactory.getLogger(MqttConfigurationServiceImpl.class);
private final AtomicLong maxClientSessionExpiryInterval = new AtomicLong(SESSION_EXPIRY_MAX);
private final AtomicLong maxMessageExpiryInterval = new AtomicLong(MAX_EXPIRY_INTERVAL_DEFAULT);
private final AtomicInteger serverReceiveMaximum = new AtomicInteger(SERVER_RECEIVE_MAXIMUM_DEFAULT);
private final AtomicInteger maxPacketSize = new AtomicInteger(DEFAULT_MAXIMUM_PACKET_SIZE_NO_LIMIT);
private final AtomicLong maxQueuedMessages = new AtomicLong(MAX_QUEUED_MESSAGES_DEFAULT);
private final AtomicReference<QueuedMessagesStrategy> queuedMessagesStrategy =
new AtomicReference<>(QUEUED_MESSAGES_STRATEGY_DEFAULT);
private final AtomicBoolean retainedMessagesEnabled = new AtomicBoolean(RETAINED_MESSAGES_ENABLED_DEFAULT);
private final AtomicBoolean allowDollarTopics = new AtomicBoolean(ALLOW_DOLLAR_TOPICS_DEFAULT);
private final AtomicBoolean wildcardSubscriptionsEnabled =
new AtomicBoolean(WILDCARD_SUBSCRIPTIONS_ENABLED_DEFAULT);
private final AtomicBoolean topicAliasEnabled = new AtomicBoolean(TOPIC_ALIAS_ENABLED_DEFAULT);
private final AtomicInteger topicAliasMaxPerClient = new AtomicInteger(TOPIC_ALIAS_MAX_PER_CLIENT_DEFAULT);
private final AtomicBoolean subscriptionIdentifierEnabled =
new AtomicBoolean(SUBSCRIPTION_IDENTIFIER_ENABLED_DEFAULT);
private final AtomicBoolean sharedSubscriptionsEnabled = new AtomicBoolean(SHARED_SUBSCRIPTIONS_ENABLED_DEFAULT);
private final AtomicBoolean keepAliveAllowZero = new AtomicBoolean(KEEP_ALIVE_ALLOW_UNLIMITED_DEFAULT);
private final AtomicInteger keepAliveMax = new AtomicInteger(KEEP_ALIVE_MAX_DEFAULT);
private final AtomicReference<QoS> maximumQos = new AtomicReference<>(MAXIMUM_QOS_DEFAULT);
@Override
public long maxQueuedMessages() {
return maxQueuedMessages.get();
}
@Override
public long maxSessionExpiryInterval() {
return maxClientSessionExpiryInterval.get();
}
@Override
public long maxMessageExpiryInterval() {
return maxMessageExpiryInterval.get();
}
@Override
public int serverReceiveMaximum() {
return serverReceiveMaximum.get();
}
@Override
public int maxPacketSize() {
return maxPacketSize.get();
}
@Override
public @NotNull QueuedMessagesStrategy getQueuedMessagesStrategy() {
return queuedMessagesStrategy.get();
}
@Override
public boolean retainedMessagesEnabled() {
return retainedMessagesEnabled.get();
}
@Override
public boolean allowDollarTopicsEnabled() { return allowDollarTopics.get(); }
@Override
public boolean wildcardSubscriptionsEnabled() {
return wildcardSubscriptionsEnabled.get();
}
@Override
public @NotNull QoS maximumQos() {
return maximumQos.get();
}
@Override
public boolean topicAliasEnabled() {
return topicAliasEnabled.get();
}
@Override
public int topicAliasMaxPerClient() {
return topicAliasMaxPerClient.get();
}
@Override
public boolean subscriptionIdentifierEnabled() {
return subscriptionIdentifierEnabled.get();
}
@Override
public boolean sharedSubscriptionsEnabled() {
return sharedSubscriptionsEnabled.get();
}
@Override
public boolean keepAliveAllowZero() {
return keepAliveAllowZero.get();
}
@Override
public int keepAliveMax() {
return keepAliveMax.get();
}
@Override
public void setQueuedMessagesStrategy(@NotNull final QueuedMessagesStrategy strategy) {
checkNotNull(strategy, "Queued Messages strategy must not be null");
log.debug("Setting queued messages strategy for each client to {}", strategy.name());
queuedMessagesStrategy.set(strategy);
}
@Override
public void setMaxPacketSize(final int maxPacketSize) {
log.debug("Setting the maximum packet size for mqtt messages {} bytes", maxPacketSize);
this.maxPacketSize.set(maxPacketSize);
}
@Override
public void setMaxQueuedMessages(final long maxQueuedMessages) {
log.debug("Setting the number of max queued messages per client to {} entries", maxQueuedMessages);
this.maxQueuedMessages.set(maxQueuedMessages);
}
@Override
public void setMaxSessionExpiryInterval(final long maxClientSessionExpiryInterval) {
log.debug("Setting the expiry interval for client sessions to {} seconds", maxClientSessionExpiryInterval);
this.maxClientSessionExpiryInterval.set(maxClientSessionExpiryInterval);
}
@Override
public void setMaxMessageExpiryInterval(final long messageExpiryInterval) {
log.debug("Setting the expiry interval for publish messages to {} seconds", messageExpiryInterval);
this.maxMessageExpiryInterval.set(messageExpiryInterval);
}
@Override
public void setRetainedMessagesEnabled(final boolean enabled) {
log.debug("Setting retained messages enabled to {}", enabled);
this.retainedMessagesEnabled.set(enabled);
}
@Override
public void setAllowDollarTopicsEnabled(final boolean enabled) {
log.debug("Setting allow dollar topics enabled to {}", enabled);
this.allowDollarTopics.set(enabled);
}
@Override
public void setWildcardSubscriptionsEnabled(final boolean enabled) {
log.debug("Setting wildcard subscriptions enabled to {}", enabled);
this.wildcardSubscriptionsEnabled.set(enabled);
}
@Override
public void setMaximumQos(@NotNull final QoS maximumQos) {
checkNotNull(maximumQos, "Maximum QoS may never be null");
log.debug("Setting maximum qos to {} ", maximumQos);
this.maximumQos.set(maximumQos);
}
@Override
public void setTopicAliasEnabled(final boolean enabled) {
log.debug("Setting topic alias enabled to {}", enabled);
this.topicAliasEnabled.set(enabled);
}
@Override
public void setTopicAliasMaxPerClient(final int maxPerClient) {
log.debug("Setting topic alias maximum per client to {}", maxPerClient);
this.topicAliasMaxPerClient.set(maxPerClient);
}
@Override
public void setSubscriptionIdentifierEnabled(final boolean enabled) {
log.debug("Setting subscription identifier enabled to {}", enabled);
this.subscriptionIdentifierEnabled.set(enabled);
}
@Override
public void setSharedSubscriptionsEnabled(final boolean enabled) {
log.debug("Setting shared subscriptions enabled to {}", enabled);
this.sharedSubscriptionsEnabled.set(enabled);
}
@Override
public void setKeepAliveAllowZero(final boolean allowZero) {
log.debug("Setting keep alive allow zero to {}", allowZero);
this.keepAliveAllowZero.set(allowZero);
}
@Override
public void setKeepAliveMax(final int keepAliveMax) {
log.debug("Setting keep alive maximum to {} seconds", keepAliveMax);
this.keepAliveMax.set(keepAliveMax);
}
@Override
public void setServerReceiveMaximum(final int serverReceiveMaximum) {
log.debug("Setting the server receive maximum to {}", serverReceiveMaximum);
this.serverReceiveMaximum.set(serverReceiveMaximum);
}
}