|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.paho.client.mqttv3.internal.ClientState
public class ClientState
The core of the client, which holds the state information for pending and in-flight messages. Messages that have been accepted for delivery are moved between several objects while being delivered. 1) When the client is not running messages are stored in a persistent store that implements the MqttClientPersistent Interface. The default is MqttDefaultFilePersistencew which stores messages safely across failures and system restarts. If no persistence is specified there is a fall back to MemoryPersistence which will maintain the messages while the Mqtt client is instantiated. 2) When the client or specifically ClientState is instantiated the messages are read from the persistent store into: - outboundqos2 hashtable if a QoS 2 PUBLISH or PUBREL - outboundqos1 hashtable if a QoS 1 PUBLISH (see restoreState) 3) On Connect, copy messages from the outbound hashtables to the pendingMessages or pendingFlows vector in messageid order. - Initial message publish goes onto the pendingmessages buffer. - PUBREL goes onto the pendingflows buffer (see restoreInflightMessages) 4) Sender thread reads messages from the pendingflows and pendingmessages buffer one at a time. The message is removed from the pendingbuffer but remains on the outbound* hashtable. The hashtable is the place where the full set of outstanding messages are stored in memory. (Persistence is only used at start up) 5) Receiver thread - receives wire messages: - if QoS 1 then remove from persistence and outboundqos1 - if QoS 2 PUBREC send PUBREL. Updating the outboundqos2 entry with the PUBREL and update persistence. - if QoS 2 PUBCOMP remove from persistence and outboundqos2 Notes: because of the multithreaded nature of the client it is vital that any changes to this class take concurrency into account. For instance as soon as a flow / message is put on the wire it is possible for the receiving thread to receive the ack and to be processing the response before the sending side has finished processing. For instance a connect may be sent, the conack received before the connect notify send has been processed!
Constructor Summary | |
---|---|
protected |
ClientState(MqttClientPersistence persistence,
CommsTokenStore tokenStore,
CommsCallback callback,
ClientComms clientComms)
|
Method Summary | |
---|---|
protected boolean |
checkQuiesceLock()
|
protected void |
clearState()
|
protected void |
close()
Tidy up - ensure that tokens are released as they are maintained over a disconnect / connect cycle. |
void |
connected()
Called when the client has successfully connected to the broker |
protected void |
deliveryComplete(MqttPublish message)
|
void |
disconnected(MqttException reason)
Called when the client has been disconnected from the broker. |
protected MqttWireMessage |
get()
This returns the next piece of work, ie message, for the CommsSender to send over the network. |
Properties |
getDebug()
|
protected long |
getKeepAlive()
|
protected void |
notifyComplete(MqttToken token)
Called when waiters and callbacks have processed the message. |
protected void |
notifyQueueLock()
|
protected void |
notifyReceivedAck(MqttAck ack)
Called by the CommsReceiver when an ack has arrived. |
protected void |
notifyReceivedMsg(MqttWireMessage message)
Called by the CommsReceiver when a message has been received. |
protected void |
notifyResult(MqttWireMessage ack,
MqttToken token,
MqttException ex)
|
protected void |
notifySent(MqttWireMessage message)
Called by the CommsSender when a message has been sent |
void |
quiesce(long timeout)
Quiesce the client state, preventing any new messages getting sent, and preventing the callback on any newly received messages. |
Vector |
resolveOldTokens(MqttException reason)
Called during shutdown to work out if there are any tokens still to be notified and waiters to be unblocked. |
protected void |
restoreState()
Restores the state information from persistence. |
void |
send(MqttWireMessage message,
MqttToken token)
Submits a message for delivery. |
protected void |
setCleanSession(boolean cleanSession)
|
void |
setKeepAliveInterval(long interval)
|
protected void |
setKeepAliveSecs(long keepAliveSecs)
|
protected void |
undo(MqttPublish message)
This removes the MqttSend message from the outbound queue and persistence. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected ClientState(MqttClientPersistence persistence, CommsTokenStore tokenStore, CommsCallback callback, ClientComms clientComms) throws MqttException
MqttException
Method Detail |
---|
protected void setKeepAliveSecs(long keepAliveSecs)
protected long getKeepAlive()
protected void setCleanSession(boolean cleanSession)
protected void clearState() throws MqttException
MqttException
protected void restoreState() throws MqttException
MqttException
public void send(MqttWireMessage message, MqttToken token) throws MqttException
message
- the message to sendtoken
- the token that can be used to track delivery of the message
MqttException
protected void undo(MqttPublish message) throws MqttPersistenceException
message
-
MqttPersistenceException
protected MqttWireMessage get() throws MqttException
#disconnected(MqttException, boolean)
is called
MqttException
public void setKeepAliveInterval(long interval)
protected void notifySent(MqttWireMessage message)
message
- protected boolean checkQuiesceLock()
protected void notifyReceivedAck(MqttAck ack) throws MqttException
message
-
MqttException
protected void notifyReceivedMsg(MqttWireMessage message) throws MqttException
message
-
MqttException
protected void notifyComplete(MqttToken token) throws MqttException
message
-
MqttException
protected void notifyResult(MqttWireMessage ack, MqttToken token, MqttException ex)
public void connected()
public Vector resolveOldTokens(MqttException reason)
reason
- The root cause of the disconnection, or null if it is a clean disconnectpublic void disconnected(MqttException reason)
reason
- The root cause of the disconnection, or null if it is a clean disconnectpublic void quiesce(long timeout)
protected void notifyQueueLock()
protected void deliveryComplete(MqttPublish message) throws MqttPersistenceException
MqttPersistenceException
protected void close()
public Properties getDebug()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |