22
22
import org .eclipse .ditto .internal .utils .config .ScopedConfig ;
23
23
24
24
import com .typesafe .config .Config ;
25
+ import com .typesafe .config .ConfigFactory ;
25
26
26
27
/**
27
28
* This class is the default implementation of {@link MqttConfig}.
30
31
public final class DefaultMqttConfig implements MqttConfig {
31
32
32
33
private static final String CONFIG_PATH = "mqtt" ;
34
+ private static final String RECONNECT_BACKOFF_PATH = "reconnect" ;
33
35
34
36
private final int sourceBufferSize ;
37
+ private final int eventLoopThreads ;
38
+ private final boolean cleanSession ;
35
39
private final boolean reconnectForRedelivery ;
36
40
private final boolean useSeparateClientForPublisher ;
37
41
private final Duration reconnectForRedeliveryDelay ;
42
+ private final BackOffConfig reconnectBackOffConfig ;
38
43
39
44
private DefaultMqttConfig (final ScopedConfig config ) {
40
45
sourceBufferSize = config .getInt (MqttConfigValue .SOURCE_BUFFER_SIZE .getConfigPath ());
46
+ eventLoopThreads = config .getInt (MqttConfigValue .EVENT_LOOP_THREADS .getConfigPath ());
47
+ cleanSession = config .getBoolean (MqttConfigValue .CLEAN_SESSION .getConfigPath ());
41
48
reconnectForRedelivery = config .getBoolean (MqttConfigValue .RECONNECT_FOR_REDELIVERY .getConfigPath ());
42
49
reconnectForRedeliveryDelay =
43
50
config .getDuration (MqttConfigValue .RECONNECT_FOR_REDELIVERY_DELAY .getConfigPath ());
44
51
useSeparateClientForPublisher = config .getBoolean (MqttConfigValue .SEPARATE_PUBLISHER_CLIENT .getConfigPath ());
52
+ reconnectBackOffConfig = DefaultBackOffConfig .of (config .hasPath (RECONNECT_BACKOFF_PATH )
53
+ ? config .getConfig (RECONNECT_BACKOFF_PATH )
54
+ : ConfigFactory .parseString ("backoff" + "={}" ));
45
55
}
46
56
47
57
/**
@@ -60,6 +70,16 @@ public int getSourceBufferSize() {
60
70
return sourceBufferSize ;
61
71
}
62
72
73
+ @ Override
74
+ public int getEventLoopThreads () {
75
+ return eventLoopThreads ;
76
+ }
77
+
78
+ @ Override
79
+ public boolean isCleanSession () {
80
+ return cleanSession ;
81
+ }
82
+
63
83
@ Override
64
84
public boolean shouldReconnectForRedelivery () {
65
85
return reconnectForRedelivery ;
@@ -75,6 +95,11 @@ public boolean shouldUseSeparatePublisherClient() {
75
95
return useSeparateClientForPublisher ;
76
96
}
77
97
98
+ @ Override
99
+ public BackOffConfig getReconnectBackOffConfig () {
100
+ return reconnectBackOffConfig ;
101
+ }
102
+
78
103
@ Override
79
104
public boolean equals (@ Nullable final Object o ) {
80
105
if (this == o ) {
@@ -85,24 +110,30 @@ public boolean equals(@Nullable final Object o) {
85
110
}
86
111
final DefaultMqttConfig that = (DefaultMqttConfig ) o ;
87
112
return Objects .equals (sourceBufferSize , that .sourceBufferSize ) &&
113
+ Objects .equals (eventLoopThreads , that .eventLoopThreads ) &&
114
+ Objects .equals (cleanSession , that .cleanSession ) &&
88
115
Objects .equals (reconnectForRedelivery , that .reconnectForRedelivery ) &&
89
116
Objects .equals (reconnectForRedeliveryDelay , that .reconnectForRedeliveryDelay ) &&
90
- Objects .equals (useSeparateClientForPublisher , that .useSeparateClientForPublisher );
117
+ Objects .equals (useSeparateClientForPublisher , that .useSeparateClientForPublisher ) &&
118
+ Objects .equals (reconnectBackOffConfig , that .reconnectBackOffConfig );
91
119
}
92
120
93
121
@ Override
94
122
public int hashCode () {
95
- return Objects .hash (sourceBufferSize , reconnectForRedelivery , reconnectForRedeliveryDelay ,
96
- useSeparateClientForPublisher );
123
+ return Objects .hash (sourceBufferSize , eventLoopThreads , cleanSession , reconnectForRedelivery ,
124
+ reconnectForRedeliveryDelay , useSeparateClientForPublisher , reconnectBackOffConfig );
97
125
}
98
126
99
127
@ Override
100
128
public String toString () {
101
129
return getClass ().getSimpleName () + " [" +
102
130
"sourceBufferSize=" + sourceBufferSize +
131
+ ", eventLoopThreads=" + eventLoopThreads +
132
+ ", cleanSession=" + cleanSession +
103
133
", reconnectForRedelivery=" + reconnectForRedelivery +
104
134
", reconnectForRedeliveryDelay=" + reconnectForRedeliveryDelay +
105
135
", useSeparateClientForPublisher=" + useSeparateClientForPublisher +
136
+ ", reconnectBackOffConfig=" + reconnectBackOffConfig +
106
137
"]" ;
107
138
}
108
139
0 commit comments