From cc8ace92f17c8e5aef7d68ff316e5cd038cd36b5 Mon Sep 17 00:00:00 2001
From: Nathan Lasseter
+Asynchronous message listener. Classes implementing this interface
+ can be passed to
+
+
+
+
+ This method is invoked synchronously by the MQTT client. An
+ acknowledgment on the network is not sent back to the server until this
+ method returns cleanly.
+ If an implementation of this method throws an
+ Any additional messages which arrive while an
+ implementation of this method is running, will build up in memory, and
+ will then back up on the network.
+ If an application needs to persist data, then it
+ should ensure the data is persisted prior to returning from this method, as
+ after returning from this method, the message is considered to have been
+ delivered, and will not be reproducable.
+ It is possible to send a new message within an implementation of this callback
+ (for example, a response to this message), but the implementation must not
+ disconnect the client, as it will be impossible to send an acknowledgement for
+ the message being processed, and a deadlock will occur.
+
+
+Lightweight client for talking to a server via the MQTT version 3
+ protocol. The client allows an application to use publish/subscribe
+ messaging.
+
+
+
+
+ If the port is not specified, it will
+ default to 1883 for "tcp://" URIs, and 8883 for "ssl://" URIs.
+
+ The client identifier should be unique across all clients connecting to the same
+ server. A convenience method is provided to generate a random client id that
+ should satisfy this criteria -
+ In Java SE, SSL can be configured in one of several ways, which the
+ client will use in the following order:
+ In Java ME, the platform settings are used for SSL connections. A default instance of
+
+ If the port is not specified, it will
+ default to 1883 for "tcp://" URIs, and 8883 for "ssl://" URIs.
+
+ The client identifier should be unique across all clients connecting to the same
+ server. A convenience method is provided to generate a random client id that
+ should satisfy this criteria -
+ In Java SE, SSL can be configured in one of several ways, which the
+ client will use in the following order:
+ In Java ME, the platform settings are used for SSL connections. An implementation of file-based persistence is provided in the
+ class
+
+
+
+
+ Firstly, the client will wait for all
+
+
+
+ When you build an application,
+ the design of the topic tree should take into account the following principles
+ of topic name syntax and semantics: The following principles apply to the construction and content of a topic
+ tree:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Package
+ Class
+ Use
+ Tree
+ Serialized
+ Deprecated
+ Index
+ Help
+
+
+
+
+
+
+ PREV CLASS
+ NEXT CLASS
+
+ FRAMES
+ NO FRAMES
+
+
+
+
+
+
+
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD
+
+DETAIL: FIELD | CONSTR | METHOD
+
+
+
+
+
+org.eclipse.paho.client.mqttv3
+
+
+Interface MqttCallback
+
+
+
+MqttClient.setCallback(MqttCallback),
+ which will create a call back on this interface.
+
+
+
+
+
+
+
+
+Method Summary
+
+
+
+
+ void
+connectionLost(java.lang.Throwable cause)
+
+
+ This method is called when the connection to the server is lost.
+
+
+
+ void
+deliveryComplete(MqttDeliveryToken token)
+
+
+ Called when delivery for a message has been completed, and all
+ acknowledgements have been received.
+
+
+
+ void
+messageArrived(MqttTopic topic,
+ MqttMessage message)
+
+
+ This method is called when a message arrives from the server.
+
+
+
+
+
+
+
+Method Detail
+
+connectionLost
+
+public void connectionLost(java.lang.Throwable cause)
+
+
+
+
+cause - the reason behind the loss of connection.
+
+
+messageArrived
+
+public void messageArrived(MqttTopic topic,
+ MqttMessage message)
+ throws java.lang.Exception
+
+
+Exception, then the
+ client will be shut down. When the client is next re-connected, any QoS
+ 1 or 2 messages will be redelivered.
+
+topic - the topic on which the message arrived.message - the actual message.
+java.lang.Exception - if a terminal error has occurred, and the client should be
+ shut down.
+
+
+deliveryComplete
+
+public void deliveryComplete(MqttDeliveryToken token)
+
+
+
+MqttTopic.publish(MqttMessage).
+
+
+token - the delivery token associated with the message.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Package
+ Class
+ Use
+ Tree
+ Serialized
+ Deprecated
+ Index
+ Help
+
+
+
+
+
+
+ PREV CLASS
+ NEXT CLASS
+
+ FRAMES
+ NO FRAMES
+
+
+
+
+
+
+
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD
+
+DETAIL: FIELD | CONSTR | METHOD
+
+
+
+
diff --git a/libs/org.eclipse.paho.client.mqttv3/org/eclipse/paho/client/mqttv3/MqttClient.html b/libs/org.eclipse.paho.client.mqttv3/org/eclipse/paho/client/mqttv3/MqttClient.html
new file mode 100644
index 0000000..3a14a1a
--- /dev/null
+++ b/libs/org.eclipse.paho.client.mqttv3/org/eclipse/paho/client/mqttv3/MqttClient.html
@@ -0,0 +1,959 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Package
+ Class
+ Use
+ Tree
+ Serialized
+ Deprecated
+ Index
+ Help
+
+
+
+
+
+
+ PREV CLASS
+ NEXT CLASS
+
+ FRAMES
+ NO FRAMES
+
+
+
+
+
+
+
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD
+
+DETAIL: FIELD | CONSTR | METHOD
+
+
+
+
+
+org.eclipse.paho.client.mqttv3
+
+
+Class MqttClient
+java.lang.Object
+
+
org.eclipse.paho.client.mqttv3.MqttClient
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Constructor Summary
+
+
+
+MqttClient(java.lang.String serverURI,
+ java.lang.String clientId)
+
+
+ Creates an MqttClient to connect to the specified address, using the
+ specified client identifier.
+
+
+MqttClient(java.lang.String serverURI,
+ java.lang.String clientId,
+ MqttClientPersistence persistence)
+
+
+ Creates an MqttClient to connect to the specified address, using the
+ specified client identifer and persistence implementation.
+
+
+
+
+
+Method Summary
+
+
+
+
+ void
+connect()
+
+
+ Connects to a server using the default options.
+
+
+
+
+ void
+connect(MqttConnectOptions options)
+
+
+ Connects to a server using the specified options.
+
+
+
+
+ void
+disconnect()
+
+
+ Disconnects from the server, which quiesces for up to a
+ maximum of thirty seconds, to allow the client to finish any work it
+ currently has.
+
+
+
+ void
+disconnect(long quiesceTimeout)
+
+
+ Disconnects from the server.
+
+
+
+
+static java.lang.String
+generateClientId()
+
+
+ Returns a randomly generated client identifier based on the current user's login
+ name and the system time.
+
+
+
+
+ java.lang.String
+getClientId()
+
+
+ Returns the client ID used by this client.
+
+
+
+ MqttDeliveryToken[]
+getPendingDeliveryTokens()
+
+
+ Returns the delivery tokens for any outstanding publish operations.
+
+
+
+ java.lang.String
+getServerURI()
+
+
+ Returns the address of the server used by this client, as a URI.
+
+
+
+
+ MqttTopic
+getTopic(java.lang.String topic)
+
+
+ Gets a topic object which can be used to publish messages.
+
+
+
+
+ boolean
+isConnected()
+
+
+ Determines if this client is currently connected to the
+ server.
+
+
+
+ void
+setCallback(MqttCallback callback)
+
+
+ Sets the callback listener to use for asynchronously received
+ messages.
+
+
+
+
+ void
+subscribe(java.lang.String topicFilter)
+
+
+ Subscribes to a topic, which may include wildcards, using the default
+ options.
+
+
+
+ void
+subscribe(java.lang.String[] topicFilters)
+
+
+ Subscribes to multiple topics, each of which may include wildcards,
+ using the default options.
+
+
+
+ void
+subscribe(java.lang.String[] topicFilters,
+ int[] qos)
+
+
+ Subscribes to multiple topics, each of which may include wildcards,
+ using the specified options.
+
+
+
+ void
+subscribe(java.lang.String topicFilter,
+ int qos)
+
+
+ Subscribes to a topic, which may include wildcards, using the specified
+ options.
+
+
+
+ void
+unsubscribe(java.lang.String topicFilter)
+
+
+ Unsubscribes from a topic.
+
+
+
+ void
+unsubscribe(java.lang.String[] topicFilters)
+
+
+ Unsubscribes from multiple topics.
+
+
+
+
+Methods inherited from class java.lang.Object
+
+
+
+equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+
+
+
+
+
+Constructor Detail
+
+MqttClient
+
+public MqttClient(java.lang.String serverURI,
+ java.lang.String clientId)
+ throws MqttException
+
+
+
+
+ tcp://localhost:1883ssl://localhost:8883generateClientId(). As the client identifier
+ is used by the server to identify a client when it reconnects, the client must use the
+ same identifier between connections if durable subscriptions are to be used.
+
+
+
+ SSLSocketFactory - applications can
+ use MqttConnectOptions.setSocketFactory(SocketFactory) to supply
+ a factory with the appropriate SSL settings.MqttConnectOptions.setSSLProperties(Properties).MqttDefaultFilePersistence is used by
+ the client. To specify a different persistence implementation, or to turn
+ off persistence, use the MqttClient(String, String, MqttClientPersistence) constructor.
+serverURI - the address to connect to, specified as a URIclientId - the client ID to use
+java.lang.IllegalArgumentException - if the URI does not start with
+ "tcp://", "ssl://" or "local://".
+java.lang.IllegalArgumentException - if the clientId is null or is greater than 23 characters in length
+MqttException - if any other problem was encountered
+
+
+MqttClient
+
+public MqttClient(java.lang.String serverURI,
+ java.lang.String clientId,
+ MqttClientPersistence persistence)
+ throws MqttException
+
+
+
+
+
+
+
+
+ tcp://localhost:1883ssl://localhost:8883local://FirstBrokergenerateClientId(). As the client identifier
+ is used by the server to identify a client when it reconnects, the client must use the
+ same identifier between connections if durable subscriptions are to be used.
+
+
+
+ SSLSocketFactory - applications can
+ use MqttConnectOptions.setSocketFactory(SocketFactory) to supply
+ a factory with the appropriate SSL settings.MqttConnectOptions.setSSLProperties(Properties).MqttClientPersistence interface, which the client can use to
+ persist messages. If the application is only sending QoS 0 messages,
+ then this is not needed.
+
+ MqttDefaultFilePersistence.
+ If no persistence is needed, it can be explicitly set to null.serverURI - the address to connect to, specified as a URIclientId - the client ID to usepersistence - the persistence mechanism to use.
+java.lang.IllegalArgumentException - if the URI does not start with
+ "tcp://", "ssl://" or "local://".
+java.lang.IllegalArgumentException - if the clientId is null or is greater than 23 characters in length
+MqttException - if any other problem was encountered
+
+
+
+
+
+Method Detail
+
+connect
+
+public void connect()
+ throws MqttSecurityException,
+ MqttException
+
+
+setCallback(MqttCallback) prior to
+ connecting.
+
+
+
+
+
+MqttSecurityException
+MqttException
+
+
+connect
+
+public void connect(MqttConnectOptions options)
+ throws MqttSecurityException,
+ MqttException
+
+
+setCallback(MqttCallback) prior to
+ connecting.
+
+
+
+
+
+MqttSecurityException
+MqttException
+
+
+disconnect
+
+public void disconnect()
+ throws MqttException
+
+
+
+
+
+
+
+MqttExceptiondisconnect(long)
+
+
+disconnect
+
+public void disconnect(long quiesceTimeout)
+ throws MqttException
+
+
+MqttCallback methods.
+ MqttCallback methods to
+ complete. It will then quiesce for the specified time, to allow for
+ work which has already been accepted to complete - for example, it will
+ wait for the QoS 2 flows from earlier publications to complete. After
+ the quiesce timeout, the client will disconnect from the server. When
+ the client is next connected, any QoS 1 or 2 messages which have not
+ completed will be retried.
+
+
+
+quiesceTimeout - the amount of time in milliseconds to allow for existing work to finish
+ before disconnecting. A value of zero or less means the client will
+ not quiesce.
+MqttException
+
+
+isConnected
+
+public boolean isConnected()
+
+
+
+
+
+
+
+true if connected, false otherwise.
+
+
+getClientId
+
+public java.lang.String getClientId()
+
+
+
+
+
+
+
+
+
+
+getServerURI
+
+public java.lang.String getServerURI()
+
+
+
+
+
+
+
+MqttClient(String, String)
+
+
+getTopic
+
+public MqttTopic getTopic(java.lang.String topic)
+
+
+
+
+
+
+
+
getTopic in interface org.eclipse.paho.client.mqttv3.internal.DestinationProvidertopic - the topic to use, for example "finance/stock/ibm".
+java.lang.IllegalArgumentException - if the topic contains a '+' or '#'
+ wildcard character.+public void subscribe(java.lang.String topicFilter) + throws MqttException, + MqttSecurityException+
setCallback(MqttCallback) method should be called
+ before this method, otherwise any received messages will be discarded.
++
MqttException
+MqttSecurityExceptionsubscribe(String[], int[])+public void subscribe(java.lang.String[] topicFilters) + throws MqttException, + MqttSecurityException+
setCallback(MqttCallback) method should be called
+ before this method, otherwise any received messages will be discarded.
++
MqttException
+MqttSecurityExceptionsubscribe(String[], int[])+public void subscribe(java.lang.String topicFilter, + int qos) + throws MqttException, + MqttSecurityException+
setCallback(MqttCallback) method should be called
+ before this method, otherwise any received messages will be discarded.
++
topicFilter - the topic to subscribe to, which can include wildcards.qos - the quality of service at which to subscribe.
+MqttException
+MqttSecurityExceptionsubscribe(String[], int[])+public void subscribe(java.lang.String[] topicFilters, + int[] qos) + throws MqttException, + MqttSecurityException+
setCallback(MqttCallback) method should be called
+ before this method, otherwise any received messages will be discarded.
+
+ The "topic filter" string used when subscribing + may contain special characters, which allow you to subscribe to multiple topics + at once.
+The topic level separator is used to introduce structure into the topic, and + can therefore be specified within the topic for that purpose. The multi-level + wildcard and single-level wildcard can be used for subscriptions, but they + cannot be used within a topic by the publisher of a message. +
The number sign (#) is a wildcard character that matches + any number of levels within a topic. For example, if you subscribe to finance/stock/ibm/#, you receive + messages on these topics:
finance/stock/ibm+ +
finance/stock/ibm/closingprice
finance/stock/ibm/currentprice
The multi-level wildcard + can represent zero or more levels. Therefore, finance/# can also match + the singular finance, where # represents zero levels. The topic + level separator is meaningless in this context, because there are no levels + to separate.
+ +The multi-level wildcard can + be specified only on its own or next to the topic level separator character. + Therefore, # and finance/# are both valid, but finance# is + not valid. The multi-level wildcard must be the last character + used within the topic tree. For example, finance/# is valid but finance/#/closingprice is + not valid.
The plus sign (+) is a wildcard character that matches only one topic + level. For example, finance/stock/+ matches finance/stock/ibm and finance/stock/xyz, + but not finance/stock/ibm/closingprice. Also, because the single-level + wildcard matches only a single level, finance/+ does not match finance.
+ +Use + the single-level wildcard at any level in the topic tree, and in conjunction + with the multilevel wildcard. Specify the single-level wildcard next to the + topic level separator, except when it is specified on its own. Therefore, + and finance/+ are + both valid, but finance+ is not valid. The single-level + wildcard can be used at the end of the topic tree or within the topic tree. + For example, finance/+ and finance/+/ibm are both valid.
++
topicFilters - the topics to subscribe to, which can include wildcards.qos - the qualities of service levels at which to subscribe.
+MqttException - if there was an error registering the subscription.
+java.lang.IllegalArgumentException - if the two supplied arrays are not the same size.
+MqttSecurityException+public void unsubscribe(java.lang.String topicFilter) + throws MqttException+
+
topicFilter - the topic to unsubscribe from.
+MqttException+public void unsubscribe(java.lang.String[] topicFilters) + throws MqttException+
+
topicFilters - the topics to unsubscribe from.
+MqttException+public void setCallback(MqttCallback callback) + throws MqttException+
MqttCallback.messageArrived(MqttTopic, MqttMessage)
+ method will be called back whenever a message arrives.
++
callback - the class to callback when a message arrives.
+MqttException+public static java.lang.String generateClientId()+
When cleanSession is set to false, an application should ensure it uses the + same client identifier when it reconnects to the server to resume state and maintain + assured message delivery.
++
MqttConnectOptions.setCleanSession(boolean)+public MqttDeliveryToken[] getPendingDeliveryTokens()+
+
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+Represents a persistent data store, used to store outbound and inbound messages while they
+ are in flight, enabling delivery to the QOS specified. You can specify an implementation
+ of this interface using MqttClient.MqttClient(String, String, MqttClientPersistence),
+ which the MqttClient will use to persist QoS 1 and 2 messages.
+
+ If the methods defined throw the MqttPersistenceException then the state of the data persisted
+ should remain as prior to the method being called. For example, if put(String, MqttPersistable)
+ throws an exception at any point then the data will be assumed to not be in the persistent store.
+ Similarly if remove(String) throws an exception then the data will be
+ assumed to still be held in the persistent store.
+ It is up to the persistence interface to log any exceptions or error information + which may be required when diagnosing a persistence failure.
++ +
+
| +Method Summary | +|
|---|---|
+ void |
+clear()
+
++ Clears persistence, so that it no longer contains any persisted data. |
+
+ void |
+close()
+
++ Close the persistent store that was previously opened. + |
+
+ boolean |
+containsKey(java.lang.String key)
+
++ Returns whether or not data is persisted using the specified key. |
+
+ MqttPersistable |
+get(java.lang.String key)
+
++ Gets the specified data out of the persistent store. |
+
+ java.util.Enumeration |
+keys()
+
++ Returns an Enumeration over the keys in this persistent data store. |
+
+ void |
+open(java.lang.String clientId,
+ java.lang.String serverURI)
+
++ Initialise the persistent store. + |
+
+ void |
+put(java.lang.String key,
+ MqttPersistable persistable)
+
++ Puts the specified data into the persistent store. |
+
+ void |
+remove(java.lang.String key)
+
++ Remove the data for the specified key. |
+
| +Method Detail | +
+public void open(java.lang.String clientId, + java.lang.String serverURI) + throws MqttPersistenceException+
+
clientId - The client for which the persistent store should be opened.serverURI - The connection string as specified when the MQTT client instance was created.
+MqttPersistenceException - if there was a problem opening the persistent store.+public void close() + throws MqttPersistenceException+
+
MqttPersistenceException+public void put(java.lang.String key, + MqttPersistable persistable) + throws MqttPersistenceException+
+
key - the key for the data, which will be used later to retrieve it.persistable - the data to persist
+MqttPersistenceException - if there was a problem putting the data
+ into the persistent store.+public MqttPersistable get(java.lang.String key) + throws MqttPersistenceException+
+
key - the key for the data, which was used when originally saving it.
+MqttPersistenceException - if there was a problem getting the data
+ from the persistent store.+public void remove(java.lang.String key) + throws MqttPersistenceException+
+
MqttPersistenceException+public java.util.Enumeration keys() + throws MqttPersistenceException+
+
String objects.
+MqttPersistenceException+public void clear() + throws MqttPersistenceException+
+
MqttPersistenceException+public boolean containsKey(java.lang.String key) + throws MqttPersistenceException+
+
key - the key for data, which was used when originally saving it.
+MqttPersistenceException
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+java.lang.Object ++org.eclipse.paho.client.mqttv3.MqttConnectOptions +
+Stores options used when connecting to a server. +
+ +
+
| +Constructor Summary | +|
|---|---|
MqttConnectOptions()
+
++ Constructs a new MqttConnectOptions object using the
+ default values.
+
+ |
+|
| +Method Summary | +|
|---|---|
+ int |
+getConnectionTimeout()
+
++ Returns the connection timeout value. |
+
+ int |
+getKeepAliveInterval()
+
++ Returns the "keep alive" interval. |
+
+ char[] |
+getPassword()
+
++ Returns the password to use for the connection. |
+
+ javax.net.SocketFactory |
+getSocketFactory()
+
++ Returns the socket factory that will be used when connecting, or + null if one has not been set. |
+
+ java.util.Properties |
+getSSLProperties()
+
++ Returns the SSL properties for the connection. |
+
+ java.lang.String |
+getUserName()
+
++ Returns the user name to use for the connection. |
+
+ MqttTopic |
+getWillDestination()
+
++ Returns the topic to be used for last will and testament (LWT). |
+
+ MqttMessage |
+getWillMessage()
+
++ Returns the message to be sent as last will and testament (LWT). + |
+
+ boolean |
+isCleanSession()
+
++ Returns whether the server should remember state for the client across reconnects. |
+
+ void |
+setCleanSession(boolean cleanSession)
+
++ Sets whether the server should remember state for the client across reconnects. + |
+
+ void |
+setConnectionTimeout(int connectionTimeout)
+
++ Sets the connection timeout value. + |
+
+ void |
+setKeepAliveInterval(int keepAliveInterval)
+
++ Sets the "keep alive" interval. + |
+
+ void |
+setPassword(char[] password)
+
++ Sets the password to use for the connection. |
+
+ void |
+setSocketFactory(javax.net.SocketFactory socketFactory)
+
++ Sets the SocketFactory to use. |
+
+ void |
+setSSLProperties(java.util.Properties props)
+
++ Sets the SSL properties for the connection. |
+
+ void |
+setUserName(java.lang.String userName)
+
++ Sets the user name to use for the connection. |
+
+ void |
+setWill(MqttTopic topic,
+ byte[] payload,
+ int qos,
+ boolean retained)
+
++ Sets the "Last Will and Testament" (LWT) for the connection. + |
+
| Methods inherited from class java.lang.Object | +
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
| +Constructor Detail | +
+public MqttConnectOptions()+
MqttConnectOptions object using the
+ default values.
+
+ The defaults are:
+ +
| +Method Detail | +
+public char[] getPassword()+
+
+public void setPassword(char[] password)+
+
+public java.lang.String getUserName()+
+
+public void setUserName(java.lang.String userName)+
+
java.lang.IllegalArgumentException - if the user name is blank or only
+ contains whitespace characters.+public void setWill(MqttTopic topic, + byte[] payload, + int qos, + boolean retained)+
+
topic - the topic to publish to.payload - the byte payload for the message.qos - the quality of service to publish the message at (0, 1 or 2).retained - whether or not the message should be retained.+public int getKeepAliveInterval()+
+
setKeepAliveInterval(int)+public void setKeepAliveInterval(int keepAliveInterval)+
The default value is 60 seconds
++
keepAliveInterval - the interval, measured in seconds.+public int getConnectionTimeout()+
+
setConnectionTimeout(int)+public void setConnectionTimeout(int connectionTimeout)+
connect,
+ subscribe and
+ unsubscribe to complete.
+ The default timeout is 30 seconds.
++
connectionTimeout - the timeout value, measured in seconds.+public javax.net.SocketFactory getSocketFactory()+
null if one has not been set.
++
+public void setSocketFactory(javax.net.SocketFactory socketFactory)+
SocketFactory to use. This allows an application
+ to apply its own policies around the creation of network sockets. If
+ using an SSL connection, an SSLSocketFactory can be used
+ to supply application-specific security settings.
++
socketFactory - the factory to use.+public MqttTopic getWillDestination()+
+
null if LWT is not set.setWill(MqttTopic, byte[], int, boolean)+public MqttMessage getWillMessage()+
IllegalStateException being thrown.
++
null if LWT is not set.+public java.util.Properties getSSLProperties()+
+
+public void setSSLProperties(java.util.Properties props)+
setSocketFactory(SocketFactory).
+ The following properties can be used:
+ com.ibm.micro.security.Password.obfuscate(char[] password).
+ This obfuscates the password using a simple and insecure XOR and Base64
+ encoding mechanism. Note that this is only a simple scrambler to
+ obfuscate clear-text passwords.com.ibm.micro.security.Password.obfuscate(char[] password).
+ This obfuscates the password using a simple and insecure XOR and Base64
+ encoding mechanism. Note that this is only a simple scrambler to
+ obfuscate clear-text passwords.+
+public boolean isCleanSession()+
+
+public void setCleanSession(boolean cleanSession)+
+
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+java.lang.Object ++org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence +
+An implementation of the MqttClientPersistence interface that provides
+ file based persistence.
+
+ A directory is specified when the Persistence object is created. When the persistence
+ is then opened (see open(String, String)), a sub-directory is made beneath the base
+ for this particular client ID and connection key. This allows one persistence base directory
+ to be shared by multiple clients.
+
+ The sub-directory's name is created from a concatenation of the client ID and connection key
+ with any instance of '/', '\\', ':' or ' ' removed.
+
+ +
+
| +Constructor Summary | +|
|---|---|
MqttDefaultFilePersistence()
+
++ |
+|
MqttDefaultFilePersistence(java.lang.String directory)
+
++ Create an file-based persistent data store within the specified directory. |
+|
| +Method Summary | +|
|---|---|
+ void |
+clear()
+
++ Clears persistence, so that it no longer contains any persisted data. |
+
+ void |
+close()
+
++ Close the persistent store that was previously opened. + |
+
+ boolean |
+containsKey(java.lang.String key)
+
++ Returns whether or not data is persisted using the specified key. |
+
+ MqttPersistable |
+get(java.lang.String key)
+
++ Gets the specified data out of the persistent store. |
+
+ java.util.Enumeration |
+keys()
+
++ Returns all of the persistent data from the previously specified persistence directory. |
+
+ void |
+open(java.lang.String clientId,
+ java.lang.String theConnection)
+
++ Initialise the persistent store. + |
+
+ void |
+put(java.lang.String key,
+ MqttPersistable message)
+
++ Writes the specified persistent data to the previously specified persistence directory. + |
+
+ void |
+remove(java.lang.String key)
+
++ Deletes the data with the specified key from the previously specified persistence directory. |
+
| Methods inherited from class java.lang.Object | +
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
| +Constructor Detail | +
+public MqttDefaultFilePersistence() + throws MqttPersistenceException+
+public MqttDefaultFilePersistence(java.lang.String directory) + throws MqttPersistenceException+
+
directory - the directory to use.| +Method Detail | +
+public void open(java.lang.String clientId, + java.lang.String theConnection) + throws MqttPersistenceException+
MqttClientPersistence+
open in interface MqttClientPersistenceclientId - The client for which the persistent store should be opened.theConnection - The connection string as specified when the MQTT client instance was created.
+MqttPersistenceException - if there was a problem opening the persistent store.+public void close() + throws MqttPersistenceException+
MqttClientPersistence+
close in interface MqttClientPersistenceMqttPersistenceException+public void put(java.lang.String key, + MqttPersistable message) + throws MqttPersistenceException+
+
put in interface MqttClientPersistencemessage - key - the key for the data, which will be used later to retrieve it.
+MqttPersistenceException+public MqttPersistable get(java.lang.String key) + throws MqttPersistenceException+
MqttClientPersistence+
get in interface MqttClientPersistencekey - the key for the data, which was used when originally saving it.
+MqttPersistenceException - if there was a problem getting the data
+ from the persistent store.+public void remove(java.lang.String key) + throws MqttPersistenceException+
+
remove in interface MqttClientPersistenceMqttPersistenceException+public java.util.Enumeration keys() + throws MqttPersistenceException+
+
keys in interface MqttClientPersistenceMqttPersistenceException+public boolean containsKey(java.lang.String key) + throws MqttPersistenceException+
MqttClientPersistence+
containsKey in interface MqttClientPersistencekey - the key for data, which was used when originally saving it.
+MqttPersistenceException+public void clear() + throws MqttPersistenceException+
MqttClientPersistence+
clear in interface MqttClientPersistenceMqttPersistenceException
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+Provides a mechanism for tracking the delivery of messages.
+
+ Calls to MqttTopic.publish(MqttMessage)
+ return after the message has been sent, but do not wait for acknowledgements
+ to be received. This allows the
+ client to have multiple messages in-flight at one time.
+
+ In order to track the delivery of a message, those methods
+ return an instance of this class which can be used in one of two ways:
+
waitForCompletion() to block the current thread
+ until delivery has completedMqttCallback.+ +
+
| +Method Summary | +|
|---|---|
+ MqttMessage |
+getMessage()
+
++ Returns the message associated with this token, or null if the message has
+ already been successfully sent. |
+
+ boolean |
+isComplete()
+
++ Returns whether or not the delivery has finished. |
+
+ void |
+waitForCompletion()
+
++ Blocks the current thread until the message this is the token + for completes delivery. |
+
+ void |
+waitForCompletion(long timeout)
+
++ Blocks the current thread until the message this is the token + for completes delivery. + |
+
| +Method Detail | +
+public void waitForCompletion() + throws MqttException, + MqttSecurityException+
+
MqttException - if there was a problem completing delivery of the message.
+MqttSecurityException+public void waitForCompletion(long timeout) + throws MqttException, + MqttSecurityException+
isComplete() method can be used to determine if the delivery is
+ complete, or if the wait has timed out.
++
timeout - the maximum amount of time to wait for, in milliseconds.
+MqttException - if there was a problem completing delivery of the message
+MqttSecurityException+public boolean isComplete()+
+
+public MqttMessage getMessage() + throws MqttException+
null if the message has
+ already been successfully sent.
++
MqttException - if there was a problem completing retrieving the message
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+java.lang.Object ++java.lang.Throwable +
java.lang.Exception +
org.eclipse.paho.client.mqttv3.MqttException +
+Thrown if an error occurs communicating with the server. +
+ +
+
| +Field Summary | +|
|---|---|
+static short |
+REASON_CODE_BROKER_UNAVAILABLE
+
++ The broker was not available to handle the request. |
+
+static short |
+REASON_CODE_CLIENT_ALREADY_CONNECTED
+
++ The client is already connected. |
+
+static short |
+REASON_CODE_CLIENT_ALREADY_DISCONNECTED
+
++ The client is already disconnected. |
+
+static short |
+REASON_CODE_CLIENT_DISCONNECT_PROHIBITED
+
++ Thrown when an attempt to call MqttClient.disconnect() has been
+ made from within a method on MqttCallback. |
+
+static short |
+REASON_CODE_CLIENT_DISCONNECTING
+
++ The client is currently disconnecting and cannot accept any new work. + |
+
+static short |
+REASON_CODE_CLIENT_EXCEPTION
+
++ Client encountered an exception. |
+
+static short |
+REASON_CODE_CLIENT_NOT_CONNECTED
+
++ The client is not connected to the server. |
+
+static short |
+REASON_CODE_CLIENT_TIMEOUT
+
++ Client timed out while waiting for a response from the server. + |
+
+static short |
+REASON_CODE_CONNECTION_LOST
+
++ The client has been unexpectedly disconnected from the server. |
+
+static short |
+REASON_CODE_FAILED_AUTHENTICATION
+
++ Authentication with the server has failed, due to a bad user name or password. |
+
+static short |
+REASON_CODE_INVALID_CLIENT_ID
+
++ The server has rejected the supplied client ID |
+
+static short |
+REASON_CODE_INVALID_MESSAGE
+
++ Protocol error: the message was not recognized as a valid MQTT packet. + |
+
+static short |
+REASON_CODE_INVALID_PROTOCOL_VERSION
+
++ The protocol version requested is not supported by the server. |
+
+static short |
+REASON_CODE_NO_MESSAGE_IDS_AVAILABLE
+
++ Internal error, caused by no new message IDs being available. |
+
+static short |
+REASON_CODE_NOT_AUTHORIZED
+
++ Not authorized to perform the requested operation |
+
+static short |
+REASON_CODE_SERVER_CONNECT_ERROR
+
++ Unable to connect to server |
+
+static short |
+REASON_CODE_SOCKET_FACTORY_MISMATCH
+
++ Server URI and supplied SocketFactory do not match.
+ |
+
+static short |
+REASON_CODE_SSL_CONFIG_ERROR
+
++ SSL configuration error. |
+
+static short |
+REASON_CODE_UNEXPECTED_ERROR
+
++ An unexpected error has occurred. |
+
| +Constructor Summary | +|
|---|---|
MqttException(int reasonCode)
+
++ Constructs a new MqttException with the specified code
+ as the underlying reason. |
+|
MqttException(int reason,
+ java.lang.Throwable cause)
+
++ Constructs a new MqttException with the specified
+ Throwable as the underlying reason. |
+|
MqttException(java.lang.Throwable cause)
+
++ Constructs a new MqttException with the specified
+ Throwable as the underlying reason. |
+|
| +Method Summary | +|
|---|---|
+ java.lang.Throwable |
+getCause()
+
++ Returns the underlying cause of this exception, if available. |
+
+ java.lang.String |
+getMessage()
+
++ Returns the detail message for this exception. |
+
+ int |
+getReasonCode()
+
++ Returns the reason code for this exception. |
+
+ java.lang.String |
+toString()
+
++ Returns a String representation of this exception. |
+
| Methods inherited from class java.lang.Throwable | +
|---|
fillInStackTrace, getLocalizedMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace |
+
| Methods inherited from class java.lang.Object | +
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
| +Field Detail | +
+public static final short REASON_CODE_CLIENT_EXCEPTION+
getCause()
+ method to get the underlying reason.
++
+public static final short REASON_CODE_INVALID_PROTOCOL_VERSION+
+
+public static final short REASON_CODE_INVALID_CLIENT_ID+
+
+public static final short REASON_CODE_BROKER_UNAVAILABLE+
+
+public static final short REASON_CODE_FAILED_AUTHENTICATION+
+
+public static final short REASON_CODE_NOT_AUTHORIZED+
+
+public static final short REASON_CODE_UNEXPECTED_ERROR+
+
+public static final short REASON_CODE_CLIENT_TIMEOUT+
+
+public static final short REASON_CODE_NO_MESSAGE_IDS_AVAILABLE+
+
+public static final short REASON_CODE_CLIENT_ALREADY_CONNECTED+
+
+public static final short REASON_CODE_CLIENT_ALREADY_DISCONNECTED+
+
+public static final short REASON_CODE_CLIENT_DISCONNECTING+
+
+public static final short REASON_CODE_SERVER_CONNECT_ERROR+
+
+public static final short REASON_CODE_CLIENT_NOT_CONNECTED+
MqttClient.connect()
+ or MqttClient.connect(MqttConnectOptions) method must be called
+ first. It is also possible that the connection was lost - see
+ MqttClient.setCallback(MqttCallback) for a way to track lost
+ connections.
++
+public static final short REASON_CODE_SOCKET_FACTORY_MISMATCH+
SocketFactory do not match.
+ URIs beginning tcp:// must use a javax.net.SocketFactory,
+ and URIs beginning ssl:// must use a javax.net.ssl.SSLSocketFactory.
++
+public static final short REASON_CODE_SSL_CONFIG_ERROR+
+
+public static final short REASON_CODE_CLIENT_DISCONNECT_PROHIBITED+
MqttClient.disconnect() has been
+ made from within a method on MqttCallback. These methods are invoked
+ by the client's thread, and must not be used to control disconnection.
++
MqttCallback.messageArrived(MqttTopic, MqttMessage),
+Constant Field Values+public static final short REASON_CODE_INVALID_MESSAGE+
+
+public static final short REASON_CODE_CONNECTION_LOST+
cause
+ will provide more details.
++
| +Constructor Detail | +
+public MqttException(int reasonCode)+
MqttException with the specified code
+ as the underlying reason.
++
reasonCode - the reason code for the exception.+public MqttException(java.lang.Throwable cause)+
MqttException with the specified
+ Throwable as the underlying reason.
++
cause - the underlying cause of the exception.+public MqttException(int reason, + java.lang.Throwable cause)+
MqttException with the specified
+ Throwable as the underlying reason.
++
reason - the reason code for the exception.cause - the underlying cause of the exception.| +Method Detail | +
+public int getReasonCode()+
+
+public java.lang.Throwable getCause()+
+
null.+public java.lang.String getMessage()+
+
null.+public java.lang.String toString()+
String representation of this exception.
++
String representation of this exception.
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+java.lang.Object ++org.eclipse.paho.client.mqttv3.MqttMessage +
+An MQTT message. The message includes a "payload" (the body of the message) + represented as a byte[]. +
+ +
+
| +Constructor Summary | +|
|---|---|
MqttMessage()
+
++ Constructs a message with an empty payload, and all other values + set to defaults. + + |
+|
MqttMessage(byte[] payload)
+
++ Constructs a message with the specified byte array as a payload, + and all other values set to defaults. |
+|
| +Method Summary | +|
|---|---|
+ void |
+clearPayload()
+
++ Clears the payload, resetting it to be empty. |
+
+ byte[] |
+getPayload()
+
++ Returns the payload as a byte array. |
+
+ int |
+getQos()
+
++ Returns the quality of service for this message. |
+
+ boolean |
+isDuplicate()
+
++ Returns whether or not this message might be a duplicate of one which has + already been received. |
+
+ boolean |
+isRetained()
+
++ Returns whether or not this message should be/was retained by the server. + |
+
+ void |
+setPayload(byte[] payload)
+
++ Sets the payload of this message to be the specified byte array. |
+
+ void |
+setQos(int qos)
+
++ Sets the quality of service for this message. + |
+
+ void |
+setRetained(boolean retained)
+
++ Whether or not the publish message should be retained by the messaging engine. + |
+
+ java.lang.String |
+toString()
+
++ Returns a string representation of this message. |
+
| Methods inherited from class java.lang.Object | +
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
| +Constructor Detail | +
+public MqttMessage()+
+
+public MqttMessage(byte[] payload)+
+
| +Method Detail | +
+public byte[] getPayload() + throws MqttException+
+
MqttException+public void clearPayload()+
+
java.lang.IllegalStateException - if this message cannot be edited+public void setPayload(byte[] payload)+
+
payload - the payload for this message.
+java.lang.IllegalStateException - if this message cannot be edited+public boolean isRetained()+
+
true if the message should be, or was, retained by
+ the server.setRetained(boolean)+public void setRetained(boolean retained)+
false will clear the
+ retained message from the server. The default value is false
++
retained - whether or not the messaging engine should retain the message.
+java.lang.IllegalStateException - if this message cannot be edited+public int getQos()+
+
setQos(int)+public void setQos(int qos)+
MqttCallback.deliveryComplete(MqttDeliveryToken).
+ Also known as "fire and forget".MqttConnectOptions.
+ If a persistence mechanism is not specified, the message will not be
+ delivered in the event of a client failure.
+ The message will be acknowledged across the network.
+ This is the default QoS.MqttConnectOptions.
+ If a persistence mechanism is not specified, the message will not be
+ delivered in the event of a client failure.+
qos - the "quality of service" to use. Set to 0, 1, 2.
+java.lang.IllegalArgumentException - if value of QoS is not 0, 1 or 2.
+java.lang.IllegalStateException - if this message cannot be edited+public java.lang.String toString()+
+
+public boolean isDuplicate()+
+
true if the message might be a duplicate.
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+Represents an object used to pass data to be persisted across the
+ MqttClientPersistence
+ interface.
+
+ When data is passed across the interface the header and payload are + separated, so that unnecessary message copies may be avoided. + For example, if a 10 MB payload was published it would be inefficient + to create a byte array a few bytes larger than 10 MB and copy the + MQTT message header and payload into a contiguous byte array.
++ When the request to persist data is made a separate byte array and offset + is passed for the header and payload. Only the data between + offset and length need be persisted. + So for example, a message to be persisted consists of a header byte + array starting at offset 1 and length 4, plus a payload byte array + starting at offset 30 and length 40000. There are three ways in which + the persistence implementation may return data to the client on + recovery: +
+ +
+
| +Method Summary | +|
|---|---|
+ byte[] |
+getHeaderBytes()
+
++ Returns the header bytes in an array. + |
+
+ int |
+getHeaderLength()
+
++ Returns the length of the header. |
+
+ int |
+getHeaderOffset()
+
++ Returns the offset of the header within the byte array returned by getHeaderBytes(). |
+
+ byte[] |
+getPayloadBytes()
+
++ Returns the payload bytes in an array. + |
+
+ int |
+getPayloadLength()
+
++ Returns the length of the payload. |
+
+ int |
+getPayloadOffset()
+
++ Returns the offset of the payload within the byte array returned by getPayloadBytes(). |
+
| +Method Detail | +
+public byte[] getHeaderBytes() + throws MqttPersistenceException+
getHeaderOffset()
+ and continue for getHeaderLength().
++
MqttPersistenceException+public int getHeaderLength() + throws MqttPersistenceException+
+
MqttPersistenceException+public int getHeaderOffset() + throws MqttPersistenceException+
getHeaderBytes().
++
MqttPersistenceException+public byte[] getPayloadBytes() + throws MqttPersistenceException+
getPayloadOffset()
+ and continue for getPayloadLength().
++
MqttPersistenceException+public int getPayloadLength() + throws MqttPersistenceException+
+
MqttPersistenceException+public int getPayloadOffset() + throws MqttPersistenceException+
getPayloadBytes().
++
MqttPersistenceException
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+java.lang.Object ++java.lang.Throwable +
java.lang.Exception +
org.eclipse.paho.client.mqttv3.MqttException +
org.eclipse.paho.client.mqttv3.MqttPersistenceException +
+This exception should be thrown by the implementor of the persistence + interface if there is a problem reading or writing persistent data. +
+ +
+
| +Field Summary | +|
|---|---|
+static short |
+REASON_CODE_PERSISTENCE_IN_USE
+
++ Persistence is already being used by another client. |
+
| +Constructor Summary | +|
|---|---|
MqttPersistenceException()
+
++ Constructs a new MqttPersistenceException |
+|
MqttPersistenceException(int reasonCode)
+
++ Constructs a new MqttPersistenceException with the specified code
+ as the underlying reason. |
+|
MqttPersistenceException(java.lang.Throwable cause)
+
++ Constructs a new MqttPersistenceException with the specified
+ Throwable as the underlying reason. |
+|
| Methods inherited from class org.eclipse.paho.client.mqttv3.MqttException | +
|---|
getCause, getMessage, getReasonCode, toString |
+
| Methods inherited from class java.lang.Throwable | +
|---|
fillInStackTrace, getLocalizedMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace |
+
| Methods inherited from class java.lang.Object | +
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
| +Field Detail | +
+public static final short REASON_CODE_PERSISTENCE_IN_USE+
+
| +Constructor Detail | +
+public MqttPersistenceException()+
MqttPersistenceException
++
+public MqttPersistenceException(int reasonCode)+
MqttPersistenceException with the specified code
+ as the underlying reason.
++
reasonCode - the reason code for the exception.+public MqttPersistenceException(java.lang.Throwable cause)+
MqttPersistenceException with the specified
+ Throwable as the underlying reason.
++
cause - the underlying cause of the exception.
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+java.lang.Object ++java.lang.Throwable +
java.lang.Exception +
org.eclipse.paho.client.mqttv3.MqttException +
org.eclipse.paho.client.mqttv3.MqttSecurityException +
+Thrown when a client is not authorized to perform an operation, or + if there is a problem with the security configuration. +
+ +
+
| +Field Summary | +
|---|
| +Constructor Summary | +|
|---|---|
MqttSecurityException(int reasonCode)
+
++ Constructs a new MqttSecurityException with the specified code
+ as the underlying reason. |
+|
MqttSecurityException(java.lang.Throwable cause)
+
++ Constructs a new MqttSecurityException with the specified
+ Throwable as the underlying reason. |
+|
| Methods inherited from class org.eclipse.paho.client.mqttv3.MqttException | +
|---|
getCause, getMessage, getReasonCode, toString |
+
| Methods inherited from class java.lang.Throwable | +
|---|
fillInStackTrace, getLocalizedMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace |
+
| Methods inherited from class java.lang.Object | +
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
| +Constructor Detail | +
+public MqttSecurityException(int reasonCode)+
MqttSecurityException with the specified code
+ as the underlying reason.
++
reasonCode - the reason code for the exception.+public MqttSecurityException(java.lang.Throwable cause)+
MqttSecurityException with the specified
+ Throwable as the underlying reason.
++
cause - the underlying cause of the exception.
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+java.lang.Object ++org.eclipse.paho.client.mqttv3.MqttTopic +
+Represents a topic destination, used for publish/subscribe messaging. +
+ +
+
| +Method Summary | +|
|---|---|
+ java.lang.String |
+getName()
+
++ Returns the name of the queue or topic. |
+
+ MqttDeliveryToken |
+publish(byte[] payload,
+ int qos,
+ boolean retained)
+
++ Publishes a message on the topic. |
+
+ MqttDeliveryToken |
+publish(MqttMessage message)
+
++ Publishes the specified message to this topic, but doesn't wait for + a response. |
+
+ java.lang.String |
+toString()
+
++ Returns a string representation of this topic. |
+
| Methods inherited from class java.lang.Object | +
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
| +Method Detail | +
+public MqttDeliveryToken publish(byte[] payload, + int qos, + boolean retained) + throws MqttException, + MqttPersistenceException+
MqttMessage object with a byte array payload and the
+ specified QoS, and then publish it. All other values in the
+ message will be set to the defaults.
++
payload - the byte array to use as the payloadqos - the Quality of Service. Valid values are 0, 1 or 2.retained - whether or not this message should be retained by the server.
+java.lang.IllegalArgumentException - if value of QoS is not 0, 1 or 2.
+MqttException
+MqttPersistenceExceptionpublish(MqttMessage),
+MqttMessage.setQos(int),
+MqttMessage.setRetained(boolean)+public MqttDeliveryToken publish(MqttMessage message) + throws MqttException, + MqttPersistenceException+
token can be used
+ to track the delivery status of the message. Once this message has
+ returned cleanly, the message has been accepted for publication by the
+ client - as long as a connection is available, it will try and deliver it.
++
message - the message to publish
+MqttException
+MqttPersistenceException+public java.lang.String getName()+
+
+public java.lang.String toString()+
+
+
+
|
++ + | +||||||||||
| + PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + | +||||||||||
| + SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +||||||||||
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
| +Uses of MqttCallback in org.eclipse.paho.client.mqttv3 | +
|---|
+ +
| Methods in org.eclipse.paho.client.mqttv3 with parameters of type MqttCallback + | |
+ void |
+MqttClient.setCallback(MqttCallback callback)
+
++ Sets the callback listener to use for asynchronously received + messages. + |
+
+
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
+
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
| +Uses of MqttClientPersistence in org.eclipse.paho.client.mqttv3 | +
|---|
+ +
| Classes in org.eclipse.paho.client.mqttv3 that implement MqttClientPersistence + | |
+ class |
+MqttDefaultFilePersistence
+
++ An implementation of the MqttClientPersistence interface that provides
+ file based persistence.
+
+ |
+
+ +
| Constructors in org.eclipse.paho.client.mqttv3 with parameters of type MqttClientPersistence + | |
MqttClient(java.lang.String serverURI,
+ java.lang.String clientId,
+ MqttClientPersistence persistence)
+
++ Creates an MqttClient to connect to the specified address, using the + specified client identifer and persistence implementation. |
+|
+
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
| +Uses of MqttConnectOptions in org.eclipse.paho.client.mqttv3 | +
|---|
+ +
| Methods in org.eclipse.paho.client.mqttv3 with parameters of type MqttConnectOptions + | |
+ void |
+MqttClient.connect(MqttConnectOptions options)
+
++ Connects to a server using the specified options. + |
+
+
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
+
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
| +Uses of MqttDeliveryToken in org.eclipse.paho.client.mqttv3 | +
|---|
+ +
| Methods in org.eclipse.paho.client.mqttv3 that return MqttDeliveryToken + | |
+ MqttDeliveryToken |
+MqttTopic.publish(byte[] payload,
+ int qos,
+ boolean retained)
+
++ Publishes a message on the topic. |
+
+ MqttDeliveryToken |
+MqttTopic.publish(MqttMessage message)
+
++ Publishes the specified message to this topic, but doesn't wait for + a response. |
+
+ MqttDeliveryToken[] |
+MqttClient.getPendingDeliveryTokens()
+
++ Returns the delivery tokens for any outstanding publish operations. |
+
+ +
| Methods in org.eclipse.paho.client.mqttv3 with parameters of type MqttDeliveryToken + | |
+ void |
+MqttCallback.deliveryComplete(MqttDeliveryToken token)
+
++ Called when delivery for a message has been completed, and all + acknowledgements have been received. |
+
+
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
| +Uses of MqttException in org.eclipse.paho.client.mqttv3 | +
|---|
+ +
| Subclasses of MqttException in org.eclipse.paho.client.mqttv3 + | |
+ class |
+MqttPersistenceException
+
++ This exception should be thrown by the implementor of the persistence + interface if there is a problem reading or writing persistent data. |
+
+ class |
+MqttSecurityException
+
++ Thrown when a client is not authorized to perform an operation, or + if there is a problem with the security configuration. |
+
+ +
| Methods in org.eclipse.paho.client.mqttv3 that throw MqttException + | |
+ MqttDeliveryToken |
+MqttTopic.publish(byte[] payload,
+ int qos,
+ boolean retained)
+
++ Publishes a message on the topic. |
+
+ MqttDeliveryToken |
+MqttTopic.publish(MqttMessage message)
+
++ Publishes the specified message to this topic, but doesn't wait for + a response. |
+
+ byte[] |
+MqttMessage.getPayload()
+
++ Returns the payload as a byte array. |
+
+ void |
+MqttDeliveryToken.waitForCompletion()
+
++ Blocks the current thread until the message this is the token + for completes delivery. |
+
+ void |
+MqttDeliveryToken.waitForCompletion(long timeout)
+
++ Blocks the current thread until the message this is the token + for completes delivery. + |
+
+ MqttMessage |
+MqttDeliveryToken.getMessage()
+
++ Returns the message associated with this token, or null if the message has
+ already been successfully sent. |
+
+ void |
+MqttClient.connect()
+
++ Connects to a server using the default options. + |
+
+ void |
+MqttClient.connect(MqttConnectOptions options)
+
++ Connects to a server using the specified options. + |
+
+ void |
+MqttClient.disconnect()
+
++ Disconnects from the server, which quiesces for up to a + maximum of thirty seconds, to allow the client to finish any work it + currently has. |
+
+ void |
+MqttClient.disconnect(long quiesceTimeout)
+
++ Disconnects from the server. + |
+
+ void |
+MqttClient.subscribe(java.lang.String topicFilter)
+
++ Subscribes to a topic, which may include wildcards, using the default + options. |
+
+ void |
+MqttClient.subscribe(java.lang.String[] topicFilters)
+
++ Subscribes to multiple topics, each of which may include wildcards, + using the default options. |
+
+ void |
+MqttClient.subscribe(java.lang.String topicFilter,
+ int qos)
+
++ Subscribes to a topic, which may include wildcards, using the specified + options. |
+
+ void |
+MqttClient.subscribe(java.lang.String[] topicFilters,
+ int[] qos)
+
++ Subscribes to multiple topics, each of which may include wildcards, + using the specified options. |
+
+ void |
+MqttClient.unsubscribe(java.lang.String topicFilter)
+
++ Unsubscribes from a topic. |
+
+ void |
+MqttClient.unsubscribe(java.lang.String[] topicFilters)
+
++ Unsubscribes from multiple topics. |
+
+ void |
+MqttClient.setCallback(MqttCallback callback)
+
++ Sets the callback listener to use for asynchronously received + messages. + |
+
+ +
| Constructors in org.eclipse.paho.client.mqttv3 that throw MqttException + | |
MqttClient(java.lang.String serverURI,
+ java.lang.String clientId)
+
++ Creates an MqttClient to connect to the specified address, using the + specified client identifier. |
+|
MqttClient(java.lang.String serverURI,
+ java.lang.String clientId,
+ MqttClientPersistence persistence)
+
++ Creates an MqttClient to connect to the specified address, using the + specified client identifer and persistence implementation. |
+|
+
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
| +Uses of MqttMessage in org.eclipse.paho.client.mqttv3 | +
|---|
+ +
| Methods in org.eclipse.paho.client.mqttv3 that return MqttMessage + | |
+ MqttMessage |
+MqttDeliveryToken.getMessage()
+
++ Returns the message associated with this token, or null if the message has
+ already been successfully sent. |
+
+ MqttMessage |
+MqttConnectOptions.getWillMessage()
+
++ Returns the message to be sent as last will and testament (LWT). + |
+
+ +
| Methods in org.eclipse.paho.client.mqttv3 with parameters of type MqttMessage + | |
+ MqttDeliveryToken |
+MqttTopic.publish(MqttMessage message)
+
++ Publishes the specified message to this topic, but doesn't wait for + a response. |
+
+ void |
+MqttCallback.messageArrived(MqttTopic topic,
+ MqttMessage message)
+
++ This method is called when a message arrives from the server. + + |
+
+
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
| +Uses of MqttPersistable in org.eclipse.paho.client.mqttv3 | +
|---|
+ +
| Methods in org.eclipse.paho.client.mqttv3 that return MqttPersistable + | |
+ MqttPersistable |
+MqttDefaultFilePersistence.get(java.lang.String key)
+
++ |
+
+ MqttPersistable |
+MqttClientPersistence.get(java.lang.String key)
+
++ Gets the specified data out of the persistent store. |
+
+ +
| Methods in org.eclipse.paho.client.mqttv3 with parameters of type MqttPersistable + | |
+ void |
+MqttDefaultFilePersistence.put(java.lang.String key,
+ MqttPersistable message)
+
++ Writes the specified persistent data to the previously specified persistence directory. + |
+
+ void |
+MqttClientPersistence.put(java.lang.String key,
+ MqttPersistable persistable)
+
++ Puts the specified data into the persistent store. |
+
+
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
| +Uses of MqttPersistenceException in org.eclipse.paho.client.mqttv3 | +
|---|
+ +
| Methods in org.eclipse.paho.client.mqttv3 that throw MqttPersistenceException + | |
+ MqttDeliveryToken |
+MqttTopic.publish(byte[] payload,
+ int qos,
+ boolean retained)
+
++ Publishes a message on the topic. |
+
+ MqttDeliveryToken |
+MqttTopic.publish(MqttMessage message)
+
++ Publishes the specified message to this topic, but doesn't wait for + a response. |
+
+ byte[] |
+MqttPersistable.getHeaderBytes()
+
++ Returns the header bytes in an array. + |
+
+ int |
+MqttPersistable.getHeaderLength()
+
++ Returns the length of the header. |
+
+ int |
+MqttPersistable.getHeaderOffset()
+
++ Returns the offset of the header within the byte array returned by MqttPersistable.getHeaderBytes(). |
+
+ byte[] |
+MqttPersistable.getPayloadBytes()
+
++ Returns the payload bytes in an array. + |
+
+ int |
+MqttPersistable.getPayloadLength()
+
++ Returns the length of the payload. |
+
+ int |
+MqttPersistable.getPayloadOffset()
+
++ Returns the offset of the payload within the byte array returned by MqttPersistable.getPayloadBytes(). |
+
+ void |
+MqttDefaultFilePersistence.open(java.lang.String clientId,
+ java.lang.String theConnection)
+
++ |
+
+ void |
+MqttDefaultFilePersistence.close()
+
++ |
+
+ void |
+MqttDefaultFilePersistence.put(java.lang.String key,
+ MqttPersistable message)
+
++ Writes the specified persistent data to the previously specified persistence directory. + |
+
+ MqttPersistable |
+MqttDefaultFilePersistence.get(java.lang.String key)
+
++ |
+
+ void |
+MqttDefaultFilePersistence.remove(java.lang.String key)
+
++ Deletes the data with the specified key from the previously specified persistence directory. |
+
+ java.util.Enumeration |
+MqttDefaultFilePersistence.keys()
+
++ Returns all of the persistent data from the previously specified persistence directory. |
+
+ boolean |
+MqttDefaultFilePersistence.containsKey(java.lang.String key)
+
++ |
+
+ void |
+MqttDefaultFilePersistence.clear()
+
++ |
+
+ void |
+MqttClientPersistence.open(java.lang.String clientId,
+ java.lang.String serverURI)
+
++ Initialise the persistent store. + |
+
+ void |
+MqttClientPersistence.close()
+
++ Close the persistent store that was previously opened. + |
+
+ void |
+MqttClientPersistence.put(java.lang.String key,
+ MqttPersistable persistable)
+
++ Puts the specified data into the persistent store. |
+
+ MqttPersistable |
+MqttClientPersistence.get(java.lang.String key)
+
++ Gets the specified data out of the persistent store. |
+
+ void |
+MqttClientPersistence.remove(java.lang.String key)
+
++ Remove the data for the specified key. |
+
+ java.util.Enumeration |
+MqttClientPersistence.keys()
+
++ Returns an Enumeration over the keys in this persistent data store. |
+
+ void |
+MqttClientPersistence.clear()
+
++ Clears persistence, so that it no longer contains any persisted data. |
+
+ boolean |
+MqttClientPersistence.containsKey(java.lang.String key)
+
++ Returns whether or not data is persisted using the specified key. |
+
+ +
| Constructors in org.eclipse.paho.client.mqttv3 that throw MqttPersistenceException + | |
MqttDefaultFilePersistence()
+
++ |
+|
MqttDefaultFilePersistence(java.lang.String directory)
+
++ Create an file-based persistent data store within the specified directory. |
+|
+
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
| +Uses of MqttSecurityException in org.eclipse.paho.client.mqttv3 | +
|---|
+ +
| Methods in org.eclipse.paho.client.mqttv3 that throw MqttSecurityException + | |
+ void |
+MqttDeliveryToken.waitForCompletion()
+
++ Blocks the current thread until the message this is the token + for completes delivery. |
+
+ void |
+MqttDeliveryToken.waitForCompletion(long timeout)
+
++ Blocks the current thread until the message this is the token + for completes delivery. + |
+
+ void |
+MqttClient.connect()
+
++ Connects to a server using the default options. + |
+
+ void |
+MqttClient.connect(MqttConnectOptions options)
+
++ Connects to a server using the specified options. + |
+
+ void |
+MqttClient.subscribe(java.lang.String topicFilter)
+
++ Subscribes to a topic, which may include wildcards, using the default + options. |
+
+ void |
+MqttClient.subscribe(java.lang.String[] topicFilters)
+
++ Subscribes to multiple topics, each of which may include wildcards, + using the default options. |
+
+ void |
+MqttClient.subscribe(java.lang.String topicFilter,
+ int qos)
+
++ Subscribes to a topic, which may include wildcards, using the specified + options. |
+
+ void |
+MqttClient.subscribe(java.lang.String[] topicFilters,
+ int[] qos)
+
++ Subscribes to multiple topics, each of which may include wildcards, + using the specified options. |
+
+
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
| +Uses of MqttTopic in org.eclipse.paho.client.mqttv3 | +
|---|
+ +
| Methods in org.eclipse.paho.client.mqttv3 that return MqttTopic + | |
+ MqttTopic |
+MqttConnectOptions.getWillDestination()
+
++ Returns the topic to be used for last will and testament (LWT). |
+
+ MqttTopic |
+MqttClient.getTopic(java.lang.String topic)
+
++ Gets a topic object which can be used to publish messages. + |
+
+ +
| Methods in org.eclipse.paho.client.mqttv3 with parameters of type MqttTopic + | |
+ void |
+MqttConnectOptions.setWill(MqttTopic topic,
+ byte[] payload,
+ int qos,
+ boolean retained)
+
++ Sets the "Last Will and Testament" (LWT) for the connection. + |
+
+ void |
+MqttCallback.messageArrived(MqttTopic topic,
+ MqttMessage message)
+
++ This method is called when a message arrives from the server. + + |
+
+
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
|
+Interfaces
+
+ +MqttCallback + +MqttClientPersistence + +MqttDeliveryToken + +MqttPersistable |
+
|
+Classes
+
+ +MqttClient + +MqttConnectOptions + +MqttDefaultFilePersistence + +MqttMessage + +MqttTopic |
+
|
+Exceptions
+
+ +MqttException + +MqttPersistenceException + +MqttSecurityException |
+
+
+
|
++ + | +||||||||||
| + PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + | +||||||||||
+See:
+
+ Description
+
+ +
| +Interface Summary | +|
|---|---|
| MqttCallback | +Asynchronous message listener. | +
| MqttClientPersistence | +Represents a persistent data store, used to store outbound and inbound messages while they + are in flight, enabling delivery to the QOS specified. | +
| MqttDeliveryToken | +Provides a mechanism for tracking the delivery of messages. + + | +
| MqttPersistable | +Represents an object used to pass data to be persisted across the
+ MqttClientPersistence
+ interface.
+ |
+
+ +
| +Class Summary | +|
|---|---|
| MqttClient | +Lightweight client for talking to a server via the MQTT version 3 + protocol. | +
| MqttConnectOptions | +Stores options used when connecting to a server. | +
| MqttDefaultFilePersistence | +An implementation of the MqttClientPersistence interface that provides
+ file based persistence.
+
+ |
+
| MqttMessage | +An MQTT message. | +
| MqttTopic | +Represents a topic destination, used for publish/subscribe messaging. | +
+ +
| +Exception Summary | +|
|---|---|
| MqttException | +Thrown if an error occurs communicating with the server. | +
| MqttPersistenceException | +This exception should be thrown by the implementor of the persistence + interface if there is a problem reading or writing persistent data. | +
| MqttSecurityException | +Thrown when a client is not authorized to perform an operation, or + if there is a problem with the security configuration. | +
+Contains an API for connecting to a server which implements the MQTT V3 +protocol. + +
+The MQ Telemetry Transport (MQTT) is a lightweight publish/subscribe protocol +flowing over TCP/IP for remote sensors and control devices through low +bandwidth communications. MQTT is used by specialized applications on +small footprint devices that require a low bandwidth communication, +typically for remote data acquisition and process control. +
++A typical system might comprise several hundred client devices communicating +with a single server or "broker", where each client is identified +by a unique ID. +
+The basic means of operating the client is as follows:
+MqttClient, providing
+ the address of the server and a unique client identifier.Connect to the servermessages to the server,
+ via topics.subscriptions,
+ combined with a callback.
+ Disconnect from the server.In the following code snippet, a simple message is published to the server, +using defaults wherever possible.
+ MqttClient client = new MqttClient("tcp://localhost:1883", "SampleClient");
+ client.connect();
+ MqttMessage message = new MqttMessage("Hello world");
+ message.setQos(0);
+ client.getTopic("foo/bar").publish(message);
+ client.disconnect();
+
+This is the fastest way of publishing messages, +but is also the least reliable. There is no assurance that the message will actually be +delivered, and no exception will be thrown if the server refuses the message, or if the +network connection fails.
+ +In the following code snippet, a message is published to the server
+at QoS 2, which is the most reliable delivery mechanism.
+In order to achieve this, the message needs to be persisted by the client.
+A default implementation of persistence is provided by MqttDefaultFilePersistence.
+This will be used by the client unless an alternative is supplied.
Publishing reliably is more complex, and most of the code is used to handle +error conditions. The key thing to notice is the two-stage delivery: the first +stage gives the message to the client. After this, the client is responsible for +delivering the message to the server. The second stage is about determining +success or failure.
+ +
+ MqttClient client = null;
+ try {
+ // Create a client to communicate with a broker at the specified address
+ client = new MqttClient("tcp://localhost:1883", "SampleClient");
+ // Connect to the broker
+ client.connect();
+ } catch (MqttException ex) {
+ System.err.println("Could not connect");
+ }
+
+ if ((client != null) && client.isConnected()) {
+ MqttTopic topic = client.getTopic("foo/bar");
+ MqttDeliveryToken token = null;
+ // Create message and set quality of service to deliver the message once
+ MqttMessage message = new MqttMessage("Hello world");
+ message.setQos(2);
+
+ try {
+ // Give the message to the client for publishing. For QoS 2,
+ // this will involve multiple network calls, which will happen
+ // asynchronously after this method has returned.
+ token = topic.publish(message);
+ }
+ catch (MqttException ex) {
+ // Client has not accepted the message due to a failure
+ // Depending on the exception's reason code, we could always retry
+ System.err.println("Failed to send message");
+ }
+
+ if (token != null) {
+ boolean keepTrying = true;
+ do {
+ try {
+ // Wait for the message delivery to complete
+ token.waitForCompletion();
+ System.out.println("Message delivery complete");
+ }
+ catch (MqttException deliveryException) {
+ int reasonCode = deliveryException.getReasonCode();
+ // TODO: Retry the message, or decide to stop trying
+ System.err.println("Message delivery failed");
+ if (client.isConnected() == false) {
+ try {
+ // Re-connect to the server
+ client.connect();
+ }
+ catch (MqttException connectException) {
+ // Can't reconnect, so give up. If and when the
+ // client does reconnect, the message delivery
+ // will automatically continue
+ keepTrying = false;
+ }
+ }
+ }
+ } while (!token.isComplete() && keepTrying);
+ }
+ }
+
+In the following code snippet, a message is published to the server
+at QoS 2, which is the most reliable delivery mechanism.
+The application uses a callback to asynchronously be notified
+when delivery of a message has been completed.
+A default implementation of persistence is provided by MqttDefaultFilePersistence.
+This will be used by the client unless an alternative is supplied.
+public class SampleClient implements MqttCallback {
+ public void run() {
+ MqttClient client = null;
+ try {
+ // Create a client to communicate with a broker at the specified address
+ client = new MqttClient("tcp://localhost:1883", "SampleClient");
+
+ // Connect to the broker
+ client.connect();
+
+ // Setup a callback
+ client.setCallback(this);
+
+ } catch (MqttException ex) {
+ System.err.println("Could not connect");
+ }
+
+ if ((client != null) && client.isConnected()) {
+ MqttTopic topic = client.getTopic("foo/bar");
+ // Create message and set quality of service to deliver the message once
+ MqttMessage message = new MqttMessage("Hello world");
+ message.setQos(2);
+
+ try {
+ // Give the message to the client for publishing. For QoS 2, this
+ // will involve multiple network calls, which will happen
+ // asynchronously after this method has returned.
+ topic.publish(message);
+ } catch (MqttException ex) {
+ // Client has not accepted the message due to a failure
+ // Depending on the exception's reason code, we could always retry
+ System.err.println("Failed to send message");
+ }
+ }
+ }
+
+ public void connectionLost(Throwable cause) {
+ // TODO: Implement reconnection logic
+ System.err.println("Connection lost");
+ }
+
+ public void deliveryComplete(MqttDeliveryToken token) {
+ System.out.println("Delivery complete");
+ }
+
+ public void messageArrived(MqttTopic topic, MqttMessage message) throws Exception {
+ }
+}
++ +
+
+
+
|
++ + | +||||||||||
| + PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + | +||||||||||
+
+
|
++ + | +||||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +||||||||||
+
+
|
++ + | +||||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +||||||||||
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||
| +Classes in org.eclipse.paho.client.mqttv3 used by org.eclipse.paho.client.mqttv3 | +|
|---|---|
| MqttCallback
+
+ + Asynchronous message listener. |
+|
| MqttClientPersistence
+
+ + Represents a persistent data store, used to store outbound and inbound messages while they + are in flight, enabling delivery to the QOS specified. |
+|
| MqttConnectOptions
+
+ + Stores options used when connecting to a server. |
+|
| MqttDeliveryToken
+
+ + Provides a mechanism for tracking the delivery of messages. + + |
+|
| MqttException
+
+ + Thrown if an error occurs communicating with the server. |
+|
| MqttMessage
+
+ + An MQTT message. |
+|
| MqttPersistable
+
+ + Represents an object used to pass data to be persisted across the + MqttClientPersistence
+ interface.
+ |
+|
| MqttPersistenceException
+
+ + This exception should be thrown by the implementor of the persistence + interface if there is a problem reading or writing persistent data. |
+|
| MqttSecurityException
+
+ + Thrown when a client is not authorized to perform an operation, or + if there is a problem with the security configuration. |
+|
| MqttTopic
+
+ + Represents a topic destination, used for publish/subscribe messaging. |
+|
+
+
+
|
++ + | +|||||||||
| + PREV + NEXT | ++ FRAMES + NO FRAMES + + + + | +|||||||||