Package cool.mqtt.hooks.utils
Class MqttBrokerConfigBuilder
java.lang.Object
cool.mqtt.hooks.utils.MqttBrokerConfigBuilder
public class MqttBrokerConfigBuilder
extends java.lang.Object
Simple builder class to simplify the making of an
MqttBrokerConfig
instance.-
Constructor Summary
Constructors Constructor Description MqttBrokerConfigBuilder(java.lang.String address)
Creates anMqttBrokerConfigBuilder
initialized with the specified MQTT broker address. -
Method Summary
Modifier and Type Method Description MqttBrokerConfig
build()
Returns a newMqttBrokerConfig
instance initialized with all parameters provided to this builder.MqttBrokerConfigBuilder
clientIdPrefix(java.lang.String clientIdPrefix)
Sets the ClientId prefix (to be used for shared connection) on this builder.MqttBrokerConfigBuilder
connectionTimeout(int connectionTimeout)
Sets the connection timeout expressed in seconds on this builder.MqttBrokerConfigBuilder
keepAlive(int keepAlive)
Sets the keep alive interval expressed in seconds on this builder.MqttBrokerConfigBuilder
keystorePassword(char[] keystorePassword)
Sets the password for the JKS keystore on this builder.MqttBrokerConfigBuilder
keystorePath(java.nio.file.Path keystorePath)
Sets the absolute path to the JKS keystore on this builder.MqttBrokerConfigBuilder
password(java.lang.String password)
Sets thepassword
on this builder.MqttBrokerConfigBuilder
privateKeyPassword(char[] privateKeyPassword)
Sets the password for the private key (stored into the JSK keystore) on this builder.MqttBrokerConfigBuilder
securityProtocol(java.lang.String securityProtocol)
Sets the standard name of the security protocol on this builder.MqttBrokerConfigBuilder
truststorePassword(char[] truststorePassword)
Sets the password for the JKS truststore on this builder.MqttBrokerConfigBuilder
truststorePath(java.nio.file.Path truststorePath)
Sets the absolute path to the JKS truststore on this builder.MqttBrokerConfigBuilder
username(java.lang.String username)
Sets theusername
on this builder.MqttBrokerConfigBuilder
willMessage(java.lang.String topic, byte[] applicationMessage, QoS qos, boolean retain)
Sets the Will Message on this builder.
-
Constructor Details
-
MqttBrokerConfigBuilder
public MqttBrokerConfigBuilder(java.lang.String address)Creates anMqttBrokerConfigBuilder
initialized with the specified MQTT broker address.- Parameters:
address
- the address of the MQTT broker
-
-
Method Details
-
username
Sets theusername
on this builder.- Parameters:
username
- the username- Returns:
- a reference to this object
- See Also:
MqttBrokerConfig.getUsername()
-
password
Sets thepassword
on this builder.- Parameters:
password
- the password- Returns:
- a reference to this object
- See Also:
MqttBrokerConfig.getPassword()
-
willMessage
public MqttBrokerConfigBuilder willMessage(java.lang.String topic, byte[] applicationMessage, QoS qos, boolean retain)Sets the Will Message on this builder.- Parameters:
topic
- the topic nameapplicationMessage
- the carried Application Messageqos
- the Quality of Serviceretain
- the retained flag- Returns:
- a reference to this object
- Throws:
java.lang.IllegalArgumentException
- in the following cases:- the specified
qos
isnull
- the specified
topic
is eithernull
or empty
- the specified
- See Also:
MqttMessage
,MqttBrokerConfig.getWillMessage()
-
keepAlive
Sets the keep alive interval expressed in seconds on this builder.- Parameters:
keepAlive
- the keep alive interval in seconds- Returns:
- a reference to this object
- See Also:
MqttBrokerConfig.getKeepAlive()
-
connectionTimeout
Sets the connection timeout expressed in seconds on this builder.- Parameters:
connectionTimeout
- the connection timeout in seconds- Returns:
- a reference to this object
- See Also:
MqttBrokerConfig.getConnectionTimeout()
-
clientIdPrefix
Sets the ClientId prefix (to be used for shared connection) on this builder.- Parameters:
clientIdPrefix
- the ClientId prefix- Returns:
- a reference to this object
- See Also:
MqttBrokerConfig.getClientIdPrefix()
-
securityProtocol
Sets the standard name of the security protocol on this builder.The standard name must be specified according to Java Cryptography Architecture Standard Algorithm Name.
- Parameters:
securityProtocol
- the security protocol name- Returns:
- a reference to this object
- See Also:
SecurityParams.getSecurityProtocol()
-
truststorePath
Sets the absolute path to the JKS truststore on this builder.- Parameters:
truststorePath
- the absolute to the JKS truststore- Returns:
- a reference to this object
- See Also:
SecurityParams.getTruststorePath()
-
truststorePassword
Sets the password for the JKS truststore on this builder.- Parameters:
truststorePassword
- the password for the JKS truststore- Returns:
- a reference to this object
- See Also:
SecurityParams.getTruststorePassword()
-
keystorePath
Sets the absolute path to the JKS keystore on this builder.- Parameters:
keystorePath
- the absolute path to the JKS keystore- Returns:
- a reference to this object
- See Also:
SecurityParams.getKeystorePath()
-
keystorePassword
Sets the password for the JKS keystore on this builder.- Parameters:
keystorePassword
- the password for the JKS keystore.- Returns:
- a reference to this object
- See Also:
SecurityParams.getKeystorePassword()
-
privateKeyPassword
Sets the password for the private key (stored into the JSK keystore) on this builder.- Parameters:
privateKeyPassword
- the password for the private key stored into the JSK keystore- Returns:
- a reference to this object
- See Also:
SecurityParams.getPrivateKeyPassword()
-
build
Returns a newMqttBrokerConfig
instance initialized with all parameters provided to this builder.Note that the returned
MqttBrokerConfig
contains a Will Message only if a valid topic has been explicitly provided throughwillMessage(String, byte[], QoS, boolean)
.Similarly, the
MqttBrokerConfig
instance contains aSecurityParams
object only if at least one of the following parameters has been explicitly provided:- the security protocol (through
securityProtocol(String)
) - the truststore path (through
truststorePath(Path)
) - the keystore path (through
keystorePath(Path)
)
- Returns:
- an
MqttBrokerConfig
instance
- the security protocol (through
-