-
public class ClientCommsHandles client communications with the server. Sends and receives MQTT V3 messages.
-
-
Field Summary
Fields Modifier and Type Field Description public static StringVERSIONpublic static StringBUILD_LEVELprivate IMqttAsyncClientclientprivate intnetworkModuleIndexprivate Array<NetworkModule>networkModulesICommsCallbackcallbackClientStateclientStateMqttConnectOptionsconOptionsprivate MqttClientPersistencepersistenceprivate DisconnectedMessageBufferdisconnectedMessageBuffer
-
Constructor Summary
Constructors Constructor Description ClientComms(IMqttAsyncClient client, MqttClientPersistence persistence, MqttPingSender pingSender, int maxInflightMsgs, ILogger logger, IExperimentsConfig experimentsConfig, List<MqttInterceptor> mqttInterceptorList, IPahoEvents pahoEvents)Creates a new ClientComms object, using the specified module to handle the network calls.
-
Method Summary
Modifier and Type Method Description IMqttAsyncClientgetClient()intgetNetworkModuleIndex()voidsetNetworkModuleIndex(int index)Array<NetworkModule>getNetworkModules()voidsetNetworkModules(Array<NetworkModule> networkModules)voidsetCallback(MqttCallback mqttCallback)ClientStategetClientState()MqttConnectOptionsgetConOptions()voidsetPersistence(MqttClientPersistence persistence)voidsetDisconnectedMessageBuffer(DisconnectedMessageBuffer disconnectedMessageBuffer)voidsendNoWait(MqttWireMessage message, MqttToken token)Sends a message to the broker if in connected state, but only waits for the message to be stored, before returning. voidclose()Close and tidy up. voidconnect(MqttConnectOptions options, MqttToken token, IPahoEvents pahoEvents)Sends a connect message and waits for an ACK or NACK. voidconnectComplete(MqttConnack cack, MqttException mex)voidshutdownConnection(MqttToken token, MqttException reason)Shuts down the connection to the server. voiddisconnect(MqttDisconnect disconnect, long quiesceTimeout, MqttToken token)voiddisconnectForcibly(long quiesceTimeout, long disconnectTimeout)Disconnect the connection and reset all the states. booleanisConnected()booleanisConnecting()booleanisDisconnected()booleanisDisconnecting()booleanisClosed()Array<MqttDeliveryToken>getPendingDeliveryTokens()longgetKeepAlive()PropertiesgetDebug()voidclear()MqttTokencheckForActivity()MqttTokensendPingRequest()voidcheckActivity()This fucntion will check if there is an ack or incoming message in out - in window If no msg or ack then we disconnect and reconnect. intgetBufferedMessageCount()MqttMessagegetBufferedMessage(int bufferIndex)voiddeleteBufferedMessage(int bufferIndex)voidnotifyConnect()When the client connects, we want to send all messages from the buffer first before allowing the user to send any messages intgetActualInFlight()-
-
Constructor Detail
-
ClientComms
ClientComms(IMqttAsyncClient client, MqttClientPersistence persistence, MqttPingSender pingSender, int maxInflightMsgs, ILogger logger, IExperimentsConfig experimentsConfig, List<MqttInterceptor> mqttInterceptorList, IPahoEvents pahoEvents)
Creates a new ClientComms object, using the specified module to handle the network calls.
-
-
Method Detail
-
getClient
IMqttAsyncClient getClient()
-
getNetworkModuleIndex
int getNetworkModuleIndex()
-
setNetworkModuleIndex
void setNetworkModuleIndex(int index)
-
getNetworkModules
Array<NetworkModule> getNetworkModules()
-
setNetworkModules
void setNetworkModules(Array<NetworkModule> networkModules)
-
setCallback
void setCallback(MqttCallback mqttCallback)
-
getClientState
ClientState getClientState()
-
getConOptions
MqttConnectOptions getConOptions()
-
setPersistence
void setPersistence(MqttClientPersistence persistence)
-
setDisconnectedMessageBuffer
void setDisconnectedMessageBuffer(DisconnectedMessageBuffer disconnectedMessageBuffer)
-
sendNoWait
void sendNoWait(MqttWireMessage message, MqttToken token)
Sends a message to the broker if in connected state, but only waits for the message to be stored, before returning.
-
close
void close()
Close and tidy up.
Call each main class and let it tidy up e.g. releasing the token store which normally survives a disconnect.
-
connect
void connect(MqttConnectOptions options, MqttToken token, IPahoEvents pahoEvents)
Sends a connect message and waits for an ACK or NACK. Connecting is a special case which will also start up the network connection, receive thread, and keep alive thread.
-
connectComplete
void connectComplete(MqttConnack cack, MqttException mex)
-
shutdownConnection
void shutdownConnection(MqttToken token, MqttException reason)
Shuts down the connection to the server. This may have been invoked as a result of a user calling disconnect or an abnormal disconnection. The method may be invoked multiple times in parallel as each thread when it receives an error uses this method to ensure that shutdown completes successfully.
-
disconnect
void disconnect(MqttDisconnect disconnect, long quiesceTimeout, MqttToken token)
-
disconnectForcibly
void disconnectForcibly(long quiesceTimeout, long disconnectTimeout)
Disconnect the connection and reset all the states.
-
isConnected
boolean isConnected()
-
isConnecting
boolean isConnecting()
-
isDisconnected
boolean isDisconnected()
-
isDisconnecting
boolean isDisconnecting()
-
isClosed
boolean isClosed()
-
getPendingDeliveryTokens
Array<MqttDeliveryToken> getPendingDeliveryTokens()
-
getKeepAlive
long getKeepAlive()
-
getDebug
Properties getDebug()
-
clear
void clear()
-
checkForActivity
MqttToken checkForActivity()
-
sendPingRequest
MqttToken sendPingRequest()
-
checkActivity
void checkActivity()
This fucntion will check if there is an ack or incoming message in out - in window If no msg or ack then we disconnect and reconnect.
-
getBufferedMessageCount
int getBufferedMessageCount()
-
getBufferedMessage
MqttMessage getBufferedMessage(int bufferIndex)
-
deleteBufferedMessage
void deleteBufferedMessage(int bufferIndex)
-
notifyConnect
void notifyConnect()
When the client connects, we want to send all messages from the buffer first before allowing the user to send any messages
-
getActualInFlight
int getActualInFlight()
-
-
-
-