-
Notifications
You must be signed in to change notification settings - Fork 215
/
HiveMqttClientPropertiesStepBuilder.java
149 lines (124 loc) · 5.16 KB
/
HiveMqttClientPropertiesStepBuilder.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
/*
* Copyright (c) 2022 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.messaging.mqtt.hivemq.clients;
import java.util.UUID;
import java.util.function.Supplier;
import org.eclipse.ditto.connectivity.model.Connection;
import org.eclipse.ditto.connectivity.model.ConnectionType;
import org.eclipse.ditto.connectivity.service.config.ConnectivityConfig;
import org.eclipse.ditto.connectivity.service.messaging.monitoring.logs.ConnectionLogger;
import org.eclipse.ditto.connectivity.service.messaging.tunnel.SshTunnelState;
import com.hivemq.client.mqtt.lifecycle.MqttClientConnectedListener;
import com.hivemq.client.mqtt.lifecycle.MqttClientDisconnectedListener;
/**
* A mutable builder with a fluent API for step-wise constructing a {@code HiveMqttClientProperties}.
* The design of this builder ensures that all mandatory properties have to be set by callers.
*/
public interface HiveMqttClientPropertiesStepBuilder {
/**
* Builder step for setting the MQTT {@link Connection}.
*/
interface MqttConnectionStep {
/**
* Sets the specified MQTT connection to this builder.
*
* @param mqttConnection the MQTT connection to be set.
* @return the next builder step.
* @throws NullPointerException if {@code mqttConnection} is {@code null}.
* @throws NoMqttConnectionException if the type of {@code mqttConnection} is neither
* {@link ConnectionType#MQTT} nor {@link ConnectionType#MQTT_5}.
*/
ConnectivityConfigStep withMqttConnection(Connection mqttConnection) throws NoMqttConnectionException;
}
/**
* Builder step for setting the {@link ConnectivityConfig}.
*/
interface ConnectivityConfigStep {
/**
* Sets the specified connectivity config to this builder.
*
* @param connectivityConfig the connectivity config to be set.
* @return the next builder step.
* @throws NullPointerException if {@code connectivityConfig} is {@code null}.
*/
SshTunnelStateSupplierStep withConnectivityConfig(ConnectivityConfig connectivityConfig);
}
/**
* Builder step for setting the {@code Supplier} for the {@link SshTunnelState}.
*/
interface SshTunnelStateSupplierStep {
/**
* Sets the specified supplier for the {@link SshTunnelState}.
*
* @param sshTunnelStateSupplier the supplier to be set.
* @return the next builder step.
* @throws NullPointerException if {@code sshTunnelStateSupplier} is {@code null}.
*/
ConnectionLoggerStep withSshTunnelStateSupplier(Supplier<SshTunnelState> sshTunnelStateSupplier);
}
/**
* Builder step for setting the {@link ConnectionLogger}.
*/
interface ConnectionLoggerStep {
/**
* Sets the specified {@code ConnectionLogger}.
*
* @param connectionLogger the connection logger to be set.
* @return the next builder step.
* @throws NullPointerException if {@code connectionLogger} is {@code null}.
*/
ActorUuidStep withConnectionLogger(ConnectionLogger connectionLogger);
}
/**
* Builder step for setting the actor {@link UUID}.
*/
interface ActorUuidStep {
/**
* Sets the specified actor UUID.
*
* @param actorUuid the UUID to be set.
* @return the next builder step.
* @throws NullPointerException if {@code actorUuid} is {@code null}.
*/
BuildableStep withActorUuid(UUID actorUuid);
}
/**
* Builder step for setting optional properties and eventually construct an instance of
* {@code HiveMqttClientProperties}.
*/
interface BuildableStep {
/**
* Sets a listener which is notified when the client is connected (a successful ConnAck message is received).
*
* @param listener the listener to set.
* @return this builder instance.
* @throws NullPointerException if {@code listener} is {@code null}.
*/
BuildableStep withClientConnectedListener(MqttClientConnectedListener listener);
/**
* Sets a listener which is notified when the client is disconnected (with or without a Disconnect message) or
* the connection fails.
*
* @param listener the listener to set.
* @return this builder instance.
* @throws NullPointerException if {@code listener} is {@code null}.
*/
BuildableStep withClientDisconnectedListener(MqttClientDisconnectedListener listener);
/**
* Creates a new instance of {@code HiveMqttClientProperties} with the properties of this builder.
*
* @return the new {@code HiveMqttClientProperties}.
*/
HiveMqttClientProperties build();
}
}