Class MqttPacket
java.lang.Object
com.codename1.io.mqtt.MqttPacket
One MQTT 3.1.1 control packet as a value. Build one with the static
factories and give it to
MqttCodec.write(MqttPacket, java.io.OutputStream);
MqttCodec.read(java.io.InputStream, int) returns one. Only the accessors
that belong to the packet's getType() carry meaning.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intPacket type CONNACK.static final intPacket type CONNECT.static final intPacket type DISCONNECT.static final intPacket type PINGREQ.static final intPacket type PINGRESP.static final intPacket type PUBACK.static final intPacket type PUBLISH.static final intPacket type SUBACK.static final intPacket type SUBSCRIBE.static final intPacket type UNSUBACK.static final intPacket type UNSUBSCRIBE. -
Method Summary
Modifier and TypeMethodDescriptionstatic MqttPacketconnack(boolean sessionPresent, int returnCode) Builds a CONNACK packet.static MqttPacketBuilds a CONNECT packet from the options.static MqttPacketBuilds a DISCONNECT packet.The client identifier of a CONNECT.String[]The topic filters of a SUBSCRIBE or UNSUBSCRIBE.intThe keep alive, in seconds, of a CONNECT.intThe packet identifier of PUBLISH (QoS 1), PUBACK, SUBSCRIBE, SUBACK, UNSUBSCRIBE and UNSUBACK.byte[]The password of a CONNECT, or null.byte[]The body of a PUBLISH.intgetQos()The QoS of a PUBLISH.int[]The requested QoS list of a SUBSCRIBE, or the return codes of a SUBACK.intThe return code of a CONNACK (0 accepted, 1 to 5 refused).getTopic()The topic name of a PUBLISH.intgetType()The packet type, one of the constants of this class.The user name of a CONNECT, or null.byte[]The will payload of a CONNECT, or null.intThe will QoS of a CONNECT.The will topic of a CONNECT, or null.booleanThe clean session flag of a CONNECT.booleanisDup()The DUP flag of a PUBLISH.booleanisRetain()The retain flag of a PUBLISH.booleanThe session present flag of a CONNACK.booleanThe will retain flag of a CONNECT.static MqttPacketpingreq()Builds a PINGREQ packet.static MqttPacketpingresp()Builds a PINGRESP packet.static MqttPacketpuback(int packetId) Builds a PUBACK packet.static MqttPacketBuilds a PUBLISH packet.voidsetDup(boolean dup) Sets the DUP flag, used when a PUBLISH is sent again.static MqttPacketsuback(int packetId, int[] returnCodes) Builds a SUBACK packet; each code is the granted QoS or 0x80 for failure.static MqttPacketBuilds a SUBSCRIBE packet with parallel arrays of filters and requested QoS.static MqttPacketunsuback(int packetId) Builds an UNSUBACK packet.static MqttPacketunsubscribe(int packetId, String[] filters) Builds an UNSUBSCRIBE packet.
-
Field Details
-
CONNECT
public static final int CONNECTPacket type CONNECT.- See Also:
-
CONNACK
public static final int CONNACKPacket type CONNACK.- See Also:
-
PUBLISH
public static final int PUBLISHPacket type PUBLISH.- See Also:
-
PUBACK
public static final int PUBACKPacket type PUBACK.- See Also:
-
SUBSCRIBE
public static final int SUBSCRIBEPacket type SUBSCRIBE.- See Also:
-
SUBACK
public static final int SUBACKPacket type SUBACK.- See Also:
-
UNSUBSCRIBE
public static final int UNSUBSCRIBEPacket type UNSUBSCRIBE.- See Also:
-
UNSUBACK
public static final int UNSUBACKPacket type UNSUBACK.- See Also:
-
PINGREQ
public static final int PINGREQPacket type PINGREQ.- See Also:
-
PINGRESP
public static final int PINGRESPPacket type PINGRESP.- See Also:
-
DISCONNECT
public static final int DISCONNECTPacket type DISCONNECT.- See Also:
-
-
Method Details
-
connect
Builds a CONNECT packet from the options. -
connack
Builds a CONNACK packet. -
publish
public static MqttPacket publish(String topic, byte[] payload, int qos, boolean retain, boolean dup, int packetId) Builds a PUBLISH packet.
Parameters
-
topic: the topic name -
payload: the body -
qos: 0 or 1 -
retain: the retain flag -
dup: the DUP flag, set on a re-delivery -
packetId: 1 to 65535 for QoS 1, ignored for QoS 0
-
-
puback
Builds a PUBACK packet. -
subscribe
Builds a SUBSCRIBE packet with parallel arrays of filters and requested QoS. -
suback
Builds a SUBACK packet; each code is the granted QoS or 0x80 for failure. -
unsubscribe
Builds an UNSUBSCRIBE packet. -
unsuback
Builds an UNSUBACK packet. -
pingreq
Builds a PINGREQ packet. -
pingresp
Builds a PINGRESP packet. -
disconnect
Builds a DISCONNECT packet. -
getType
public int getType()The packet type, one of the constants of this class. -
getPacketId
public int getPacketId()The packet identifier of PUBLISH (QoS 1), PUBACK, SUBSCRIBE, SUBACK, UNSUBSCRIBE and UNSUBACK. -
getTopic
The topic name of a PUBLISH. -
getPayload
public byte[] getPayload()The body of a PUBLISH. -
getQos
public int getQos()The QoS of a PUBLISH. -
isRetain
public boolean isRetain()The retain flag of a PUBLISH. -
isDup
public boolean isDup()The DUP flag of a PUBLISH. -
setDup
public void setDup(boolean dup) Sets the DUP flag, used when a PUBLISH is sent again. -
isSessionPresent
public boolean isSessionPresent()The session present flag of a CONNACK. -
getReturnCode
public int getReturnCode()The return code of a CONNACK (0 accepted, 1 to 5 refused). -
getFilters
The topic filters of a SUBSCRIBE or UNSUBSCRIBE. -
getQosList
public int[] getQosList()The requested QoS list of a SUBSCRIBE, or the return codes of a SUBACK. -
getClientId
The client identifier of a CONNECT. -
isCleanSession
public boolean isCleanSession()The clean session flag of a CONNECT. -
getKeepAlive
public int getKeepAlive()The keep alive, in seconds, of a CONNECT. -
getUsername
The user name of a CONNECT, or null. -
getPassword
public byte[] getPassword()The password of a CONNECT, or null. -
getWillTopic
The will topic of a CONNECT, or null. -
getWillPayload
public byte[] getWillPayload()The will payload of a CONNECT, or null. -
getWillQos
public int getWillQos()The will QoS of a CONNECT. -
isWillRetain
public boolean isWillRetain()The will retain flag of a CONNECT.
-