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 anMqttBrokerConfigBuilderinitialized with the specified MQTT broker address. -
Method Summary
Modifier and Type Method Description MqttBrokerConfigbuild()Returns a newMqttBrokerConfiginstance initialized with all parameters provided to this builder.MqttBrokerConfigBuilderclientIdPrefix(java.lang.String clientIdPrefix)Sets the ClientId prefix (to be used for shared connection) on this builder.MqttBrokerConfigBuilderconnectionTimeout(int connectionTimeout)Sets the connection timeout expressed in seconds on this builder.MqttBrokerConfigBuilderkeepAlive(int keepAlive)Sets the keep alive interval expressed in seconds on this builder.MqttBrokerConfigBuilderkeystorePassword(char[] keystorePassword)Sets the password for the JKS keystore on this builder.MqttBrokerConfigBuilderkeystorePath(java.nio.file.Path keystorePath)Sets the absolute path to the JKS keystore on this builder.MqttBrokerConfigBuilderpassword(java.lang.String password)Sets thepasswordon this builder.MqttBrokerConfigBuilderprivateKeyPassword(char[] privateKeyPassword)Sets the password for the private key (stored into the JSK keystore) on this builder.MqttBrokerConfigBuildersecurityProtocol(java.lang.String securityProtocol)Sets the standard name of the security protocol on this builder.MqttBrokerConfigBuildertruststorePassword(char[] truststorePassword)Sets the password for the JKS truststore on this builder.MqttBrokerConfigBuildertruststorePath(java.nio.file.Path truststorePath)Sets the absolute path to the JKS truststore on this builder.MqttBrokerConfigBuilderusername(java.lang.String username)Sets theusernameon this builder.MqttBrokerConfigBuilderwillMessage(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 anMqttBrokerConfigBuilderinitialized with the specified MQTT broker address.- Parameters:
address- the address of the MQTT broker
-
-
Method Details
-
username
Sets theusernameon this builder.- Parameters:
username- the username- Returns:
- a reference to this object
- See Also:
MqttBrokerConfig.getUsername()
-
password
Sets thepasswordon 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
qosisnull - the specified
topicis eithernullor 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 newMqttBrokerConfiginstance initialized with all parameters provided to this builder.Note that the returned
MqttBrokerConfigcontains a Will Message only if a valid topic has been explicitly provided throughwillMessage(String, byte[], QoS, boolean).Similarly, the
MqttBrokerConfiginstance contains aSecurityParamsobject 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
MqttBrokerConfiginstance
- the security protocol (through
-