Class MqttClientWillBuilder
- java.lang.Object
-
- com.plccom.mqtt.client.MqttClientWillBuilder
-
public final class MqttClientWillBuilder extends Object
High-level builder for configuring a client Last Will onPlccomMqttClientBuilder.The builder mirrors the everyday MQTT Last Will workflow: choose the Will Topic, provide the Last Will payload, optionally select QoS and Retain, then return to the parent client builder with
done(). MQTT 5 Will Properties are exposed as optional hints; they are encoded only for MQTT 5 connections, while MQTT 3.1.1 connections continue to send the classic Will Topic, payload, QoS and Retain fields.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MqttClientWillBuildercontentType(String value)Sets the MQTT 5 Will Content Type property.MqttClientWillBuildercorrelationData(byte[] value)Sets the MQTT 5 Will Correlation Data property.PlccomMqttClientBuilderdone()Stores the Last Will configuration in the parent client builder and returns that parent builder.MqttClientWillBuildermessageExpirySeconds(long value)Sets the MQTT 5 Will Message Expiry Interval property.MqttClientWillBuildermessageExpirySeconds(Long value)Sets the MQTT 5 Will Message Expiry Interval property.MqttClientWillBuilderpayloadFormatBytes()Declares the Last Will payload as unspecified binary data for MQTT 5 receivers.MqttClientWillBuilderpayloadFormatUtf8()Declares the Last Will payload as UTF-8 character data for MQTT 5 receivers.MqttClientWillBuilderpayloadFormatUtf8(Boolean value)Sets the MQTT 5 Will Payload Format Indicator property.MqttClientWillBuilderqos0()Selects QoS 0 for the Last Will publication.MqttClientWillBuilderqos1()Selects QoS 1 for the Last Will publication.MqttClientWillBuilderqos2()Selects QoS 2 for the Last Will publication.MqttClientWillBuilderqualityOfService(PlccomMqttQualityOfService value)Sets the requested Last Will QoS explicitly.MqttClientWillBuilderresponseTopic(String value)Sets the MQTT 5 Will Response Topic property.MqttClientWillBuilderretain()Enables the Last Will Retain flag.MqttClientWillBuilderretain(boolean value)Sets the Last Will Retain flag.MqttClientWillBuilderuserProperty(String name, String value)Adds one MQTT 5 Will User Property.MqttClientWillBuilderwillDelaySeconds(long value)Sets the MQTT 5 Will Delay Interval property.MqttClientWillBuilderwillDelaySeconds(Long value)Sets the MQTT 5 Will Delay Interval property.
-
-
-
Method Detail
-
qos0
public MqttClientWillBuilder qos0()
Selects QoS 0 for the Last Will publication.- Returns:
- this builder
-
qos1
public MqttClientWillBuilder qos1()
Selects QoS 1 for the Last Will publication.- Returns:
- this builder
-
qos2
public MqttClientWillBuilder qos2()
Selects QoS 2 for the Last Will publication.- Returns:
- this builder
-
qualityOfService
public MqttClientWillBuilder qualityOfService(PlccomMqttQualityOfService value)
Sets the requested Last Will QoS explicitly.- Parameters:
value- QoS requested for the Last Will publication- Returns:
- this builder
- Throws:
NullPointerException- ifvalueisnull
-
retain
public MqttClientWillBuilder retain()
Enables the Last Will Retain flag.- Returns:
- this builder
-
retain
public MqttClientWillBuilder retain(boolean value)
Sets the Last Will Retain flag.- Parameters:
value-trueto ask the broker to retain the Will- Returns:
- this builder
-
payloadFormatUtf8
public MqttClientWillBuilder payloadFormatUtf8(Boolean value)
Sets the MQTT 5 Will Payload Format Indicator property.Use
truewhen the Last Will payload is valid UTF-8 character data andfalsewhen the payload should be treated as unspecified binary data. Supplyingnullomits the property.- Parameters:
value- payload format hint, ornullto omit the property- Returns:
- this builder
-
payloadFormatUtf8
public MqttClientWillBuilder payloadFormatUtf8()
Declares the Last Will payload as UTF-8 character data for MQTT 5 receivers.- Returns:
- this builder
-
payloadFormatBytes
public MqttClientWillBuilder payloadFormatBytes()
Declares the Last Will payload as unspecified binary data for MQTT 5 receivers.- Returns:
- this builder
-
messageExpirySeconds
public MqttClientWillBuilder messageExpirySeconds(Long value)
Sets the MQTT 5 Will Message Expiry Interval property.The broker starts the expiry timer when it publishes the Will. A value of
0means the Will expires immediately, whilenulllets the broker apply its default behavior.- Parameters:
value- expiry interval in seconds, ornullto omit the property- Returns:
- this builder
- Throws:
IllegalArgumentException- ifvalueis outside the MQTT unsigned 32-bit range
-
messageExpirySeconds
public MqttClientWillBuilder messageExpirySeconds(long value)
Sets the MQTT 5 Will Message Expiry Interval property.- Parameters:
value- expiry interval in seconds- Returns:
- this builder
- Throws:
IllegalArgumentException- ifvalueis outside the MQTT unsigned 32-bit range
-
willDelaySeconds
public MqttClientWillBuilder willDelaySeconds(Long value)
Sets the MQTT 5 Will Delay Interval property.The broker waits for this duration after an ungraceful disconnect before publishing the Will. If the same client reconnects before the delay expires, a compliant broker can cancel the pending Will.
- Parameters:
value- delay interval in seconds, ornullto omit the property- Returns:
- this builder
- Throws:
IllegalArgumentException- ifvalueis outside the MQTT unsigned 32-bit range
-
willDelaySeconds
public MqttClientWillBuilder willDelaySeconds(long value)
Sets the MQTT 5 Will Delay Interval property.- Parameters:
value- delay interval in seconds- Returns:
- this builder
- Throws:
IllegalArgumentException- ifvalueis outside the MQTT unsigned 32-bit range
-
contentType
public MqttClientWillBuilder contentType(String value)
Sets the MQTT 5 Will Content Type property.- Parameters:
value- content type, ornullto omit the property- Returns:
- this builder
-
responseTopic
public MqttClientWillBuilder responseTopic(String value)
Sets the MQTT 5 Will Response Topic property.The value is a Topic Name, not a Topic Filter. Wildcards are rejected later by the protocol encoder using the configured client limits.
- Parameters:
value- response topic, ornullto omit the property- Returns:
- this builder
-
correlationData
public MqttClientWillBuilder correlationData(byte[] value)
Sets the MQTT 5 Will Correlation Data property.- Parameters:
value- correlation data bytes, ornullto omit the property- Returns:
- this builder
-
userProperty
public MqttClientWillBuilder userProperty(String name, String value)
Adds one MQTT 5 Will User Property.- Parameters:
name- property namevalue- property value- Returns:
- this builder
- Throws:
NullPointerException- ifnameorvalueisnull
-
done
public PlccomMqttClientBuilder done()
Stores the Last Will configuration in the parent client builder and returns that parent builder.- Returns:
- parent client builder
- Throws:
NullPointerException- if the Will topic or QoS isnullIllegalArgumentException- if the Will topic is empty
-
-