From ca3f1b44b14ae14f304c0398ee616cf0dedaf8dc Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Tue, 27 Aug 2024 08:05:09 +0200 Subject: [PATCH] Tokenlist with mutableList --- .../mqtt/android/service/MqttAndroidClient.kt | 76 +++++++++---------- .../mqtt/android/service/MqttConnection.kt | 53 +++++++------ .../info/mqtt/android/service/MqttService.kt | 21 +++-- 3 files changed, 73 insertions(+), 77 deletions(-) diff --git a/serviceLibrary/src/main/java/info/mqtt/android/service/MqttAndroidClient.kt b/serviceLibrary/src/main/java/info/mqtt/android/service/MqttAndroidClient.kt index 1c21a7c8..3cf376ab 100755 --- a/serviceLibrary/src/main/java/info/mqtt/android/service/MqttAndroidClient.kt +++ b/serviceLibrary/src/main/java/info/mqtt/android/service/MqttAndroidClient.kt @@ -7,7 +7,6 @@ import android.content.* import android.os.Build import android.os.Bundle import android.os.IBinder -import android.util.SparseArray import info.mqtt.android.service.extension.parcelable import info.mqtt.android.service.extension.serializable import kotlinx.coroutines.CoroutineScope @@ -51,7 +50,7 @@ class MqttAndroidClient @JvmOverloads constructor( private val serviceConnection = MyServiceConnection() // We hold the various tokens in a collection and pass identifiers for them to the service - private val tokenMap = SparseArray() + private val tokenList = mutableListOf() //The acknowledgment that a message has been processed by the application private val messageAck = ackType @@ -61,7 +60,6 @@ class MqttAndroidClient @JvmOverloads constructor( // An identifier for the underlying client connection, which we can pass to the service private var clientHandle: String? = null - private var tokenNumber = 0 private var clientConnectOptions: MqttConnectOptions? = null private var connectToken: IMqttToken? = null @@ -258,9 +256,9 @@ class MqttAndroidClient @JvmOverloads constructor( } mqttService!!.isTraceEnabled = traceEnabled mqttService!!.setTraceCallbackId(clientHandle) - val activityToken = storeToken(connectToken) + storeToken(connectToken) try { - mqttService!!.connect(clientHandle!!, clientConnectOptions, activityToken) + mqttService!!.connect(clientHandle!!, clientConnectOptions, connectToken) } catch (e: Exception) { val listener = connectToken!!.actionCallback listener?.onFailure(connectToken, e) @@ -279,8 +277,8 @@ class MqttAndroidClient @JvmOverloads constructor( */ override fun disconnect(): IMqttToken { val token: IMqttToken = MqttTokenAndroid(this, null, null) - val activityToken = storeToken(token) - mqttService!!.disconnect(clientHandle!!, null, activityToken) + storeToken(token) + mqttService!!.disconnect(clientHandle!!, null, token) return token } @@ -299,8 +297,8 @@ class MqttAndroidClient @JvmOverloads constructor( */ override fun disconnect(quiesceTimeout: Long): IMqttToken { val token: IMqttToken = MqttTokenAndroid(this, null, null) - val activityToken = storeToken(token) - mqttService!!.disconnect(clientHandle!!, quiesceTimeout, null, activityToken) + storeToken(token) + mqttService!!.disconnect(clientHandle!!, quiesceTimeout, null, token) return token } @@ -317,8 +315,8 @@ class MqttAndroidClient @JvmOverloads constructor( */ override fun disconnect(userContext: Any?, callback: IMqttActionListener?): IMqttToken { val token: IMqttToken = MqttTokenAndroid(this, userContext, callback) - val activityToken = storeToken(token) - mqttService!!.disconnect(clientHandle!!, null, activityToken) + storeToken(token) + mqttService!!.disconnect(clientHandle!!, null, token) return token } @@ -351,8 +349,8 @@ class MqttAndroidClient @JvmOverloads constructor( */ override fun disconnect(quiesceTimeout: Long, userContext: Any?, callback: IMqttActionListener): IMqttToken { val token: IMqttToken = MqttTokenAndroid(this, userContext, callback) - val activityToken = storeToken(token) - mqttService!!.disconnect(clientHandle!!, quiesceTimeout, null, activityToken) + storeToken(token) + mqttService!!.disconnect(clientHandle!!, quiesceTimeout, null, token) return token } @@ -412,8 +410,8 @@ class MqttAndroidClient @JvmOverloads constructor( message.qos = qos message.isRetained = retained val token = MqttDeliveryTokenAndroid(this, userContext, callback, message) - val activityToken = storeToken(token) - val internalToken = mqttService!!.publish(clientHandle!!, topic, payload, QoS.valueOf(qos), retained, null, activityToken) + storeToken(token) + val internalToken = mqttService!!.publish(clientHandle!!, topic, payload, QoS.valueOf(qos), retained, null, token) token.setDelegate(internalToken) return token } @@ -474,8 +472,8 @@ class MqttAndroidClient @JvmOverloads constructor( */ override fun publish(topic: String, message: MqttMessage, userContext: Any?, callback: IMqttActionListener?): IMqttDeliveryToken { val token = MqttDeliveryTokenAndroid(this, userContext, callback, message) - val activityToken = storeToken(token) - val internalToken = mqttService!!.publish(clientHandle!!, topic, message, null, activityToken) + storeToken(token) + val internalToken = mqttService!!.publish(clientHandle!!, topic, message, null, token) token.setDelegate(internalToken) return token } @@ -526,8 +524,8 @@ class MqttAndroidClient @JvmOverloads constructor( */ override fun subscribe(topic: String, qos: Int, userContext: Any?, callback: IMqttActionListener?): IMqttToken { val token: IMqttToken = MqttTokenAndroid(this, userContext, callback, arrayOf(topic)) - val activityToken = storeToken(token) - mqttService!!.subscribe(clientHandle!!, topic, QoS.valueOf(qos), null, activityToken) + storeToken(token) + mqttService!!.subscribe(clientHandle!!, topic, QoS.valueOf(qos), null, token) return token } @@ -630,8 +628,8 @@ class MqttAndroidClient @JvmOverloads constructor( */ override fun subscribe(topic: Array, qos: IntArray, userContext: Any?, callback: IMqttActionListener?): IMqttToken { val token: IMqttToken = MqttTokenAndroid(this, userContext, callback, topic) - val activityToken = storeToken(token) - mqttService!!.subscribe(clientHandle!!, topic, qos, null, activityToken) + storeToken(token) + mqttService!!.subscribe(clientHandle!!, topic, qos, null, token) return token } @@ -709,8 +707,8 @@ class MqttAndroidClient @JvmOverloads constructor( Array ): IMqttToken { val token: IMqttToken = MqttTokenAndroid(this, userContext, callback, topicFilters) - val activityToken = storeToken(token) - mqttService!!.subscribe(clientHandle!!, topicFilters, qos.map { QoS.valueOf(it) }.toTypedArray(), null, activityToken, messageListeners) + storeToken(token) + mqttService!!.subscribe(clientHandle!!, topicFilters, qos.map { QoS.valueOf(it) }.toTypedArray(), null, token, messageListeners) return token } @@ -747,8 +745,8 @@ class MqttAndroidClient @JvmOverloads constructor( */ override fun unsubscribe(topic: String, userContext: Any?, callback: IMqttActionListener?): IMqttToken { val token: IMqttToken = MqttTokenAndroid(this, userContext, callback) - val activityToken = storeToken(token) - mqttService!!.unsubscribe(clientHandle!!, topic, null, activityToken) + storeToken(token) + mqttService!!.unsubscribe(clientHandle!!, topic, null, token) return token } @@ -778,8 +776,8 @@ class MqttAndroidClient @JvmOverloads constructor( */ override fun unsubscribe(topic: Array, userContext: Any?, callback: IMqttActionListener?): IMqttToken { val token: IMqttToken = MqttTokenAndroid(this, userContext, callback) - val activityToken = storeToken(token) - mqttService!!.unsubscribe(clientHandle!!, topic, null, activityToken) + storeToken(token) + mqttService!!.unsubscribe(clientHandle!!, topic, null, token) return token } @@ -1106,16 +1104,15 @@ class MqttAndroidClient @JvmOverloads constructor( /** * @param token identifying an operation - * @return an identifier for the token which can be passed to the Android - * Service */ @Synchronized - private fun storeToken(token: IMqttToken?): String { + private fun storeToken(token: IMqttToken?) { token?.let { - tokenMap.put(tokenNumber, token) - return (tokenNumber++).toString() - } ?: run { - return tokenNumber.toString() + val tokenFound = tokenList.find { it == token } + if (tokenFound == null) { + tokenList.add(token) + Timber.d("$token size=${tokenList.size}") + } } } @@ -1127,10 +1124,10 @@ class MqttAndroidClient @JvmOverloads constructor( @Synchronized private fun removeMqttToken(data: Bundle): IMqttToken? { val activityToken = data.getString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN) - if (activityToken != null) { - val tokenNumber = activityToken.toInt() - val token = tokenMap[tokenNumber] - tokenMap.delete(tokenNumber) + if (activityToken != null && activityToken != "null") { + val token = tokenList.find { it.toString() == activityToken } + tokenList.remove(token) + Timber.d("search=$activityToken ${tokenList.size}") return token } return null @@ -1144,7 +1141,8 @@ class MqttAndroidClient @JvmOverloads constructor( @Synchronized private fun getMqttToken(data: Bundle): IMqttToken? { val activityToken = data.getString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN) - return tokenMap[activityToken!!.toInt()] + val token = tokenList.find { it.toString() == activityToken } + return token } /** diff --git a/serviceLibrary/src/main/java/info/mqtt/android/service/MqttConnection.kt b/serviceLibrary/src/main/java/info/mqtt/android/service/MqttConnection.kt index 5d3e92ce..18124847 100755 --- a/serviceLibrary/src/main/java/info/mqtt/android/service/MqttConnection.kt +++ b/serviceLibrary/src/main/java/info/mqtt/android/service/MqttConnection.kt @@ -63,7 +63,7 @@ internal class MqttConnection( private var connectOptions: MqttConnectOptions? = null //store connect ActivityToken for reconnect - private var reconnectActivityToken: String? = null + private var reconnectActivityToken: IMqttToken? = null // our client object - instantiated on connect private var myClient: MqttAsyncClient? = null @@ -87,7 +87,7 @@ internal class MqttConnection( * @param invocationContext arbitrary data to be passed back to the application * @param activityToken arbitrary identifier to be passed back to the Activity */ - fun connect(options: MqttConnectOptions?, invocationContext: String?, activityToken: String?) { + fun connect(options: MqttConnectOptions?, invocationContext: String?, activityToken: IMqttToken?) { connectOptions = options reconnectActivityToken = activityToken options?.let { @@ -104,7 +104,7 @@ internal class MqttConnection( } service.traceDebug("Connecting {$serverURI} as {$clientId}") val resultBundle = Bundle() - resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken) + resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken.toString()) resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, invocationContext) resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.CONNECT_ACTION) try { @@ -264,11 +264,11 @@ internal class MqttConnection( * @param invocationContext arbitrary data to be passed back to the application * @param activityToken arbitrary string to be passed back to the activity */ - fun disconnect(quiesceTimeout: Long, invocationContext: String?, activityToken: String) { + fun disconnect(quiesceTimeout: Long, invocationContext: String?, activityToken: IMqttToken) { service.traceDebug("disconnect()") disconnected = true val resultBundle = Bundle() - resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken) + resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken.toString()) resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, invocationContext) resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.DISCONNECT_ACTION) if (myClient != null && myClient!!.isConnected) { @@ -298,11 +298,11 @@ internal class MqttConnection( * @param invocationContext arbitrary data to be passed back to the application * @param activityToken arbitrary string to be passed back to the activity */ - fun disconnect(invocationContext: String?, activityToken: String?) { + fun disconnect(invocationContext: String?, activityToken: IMqttToken?) { service.traceDebug("disconnect()") disconnected = true val resultBundle = Bundle() - resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken) + resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken.toString()) resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, invocationContext) resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.DISCONNECT_ACTION) if (myClient != null && myClient!!.isConnected) { @@ -350,11 +350,11 @@ internal class MqttConnection( qos: QoS, retained: Boolean, invocationContext: String?, - activityToken: String + activityToken: IMqttToken ): IMqttDeliveryToken? { val resultBundle = Bundle() resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.SEND_ACTION) - resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken) + resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken.toString()) resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, invocationContext) var sendToken: IMqttDeliveryToken? = null if (myClient != null && myClient!!.isConnected) { @@ -386,10 +386,10 @@ internal class MqttConnection( * @param activityToken arbitrary string to be passed back to the activity * @return token for tracking the operation */ - fun publish(topic: String, message: MqttMessage, invocationContext: String?, activityToken: String): IMqttDeliveryToken? { + fun publish(topic: String, message: MqttMessage, invocationContext: String?, activityToken: IMqttToken): IMqttDeliveryToken? { val resultBundle = Bundle() resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.SEND_ACTION) - resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken) + resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken.toString()) resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, invocationContext) var sendToken: IMqttDeliveryToken? = null if (myClient != null && myClient!!.isConnected) { @@ -426,11 +426,11 @@ internal class MqttConnection( * @param invocationContext arbitrary data to be passed back to the application * @param activityToken arbitrary identifier to be passed back to the Activity */ - fun subscribe(topic: String, qos: QoS, invocationContext: String?, activityToken: String) { + fun subscribe(topic: String, qos: QoS, invocationContext: String?, activityToken: IMqttToken) { service.traceDebug("subscribe({$topic},$qos,{$invocationContext}, {$activityToken}") val resultBundle = Bundle() resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.SUBSCRIBE_ACTION) - resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken) + resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken.toString()) resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, invocationContext) if (myClient != null && myClient!!.isConnected) { val listener: IMqttActionListener = MqttConnectionListener(resultBundle) @@ -454,14 +454,13 @@ internal class MqttConnection( * @param invocationContext arbitrary data to be passed back to the application * @param activityToken arbitrary identifier to be passed back to the Activity */ - fun subscribe(topic: Array, qos: IntArray?, invocationContext: String?, activityToken: String) { + fun subscribe(topic: Array, qos: IntArray?, invocationContext: String?, activityToken: IMqttToken) { service.traceDebug( - "subscribe({" + topic.contentToString() + "}," + Arrays - .toString(qos) + ",{" + invocationContext + "}, {" + activityToken + "}" + "subscribe({" + topic.contentToString() + "}," + qos.contentToString() + ",{" + invocationContext + "}, {" + activityToken + "}" ) val resultBundle = Bundle() resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.SUBSCRIBE_ACTION) - resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken) + resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken.toString()) resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, invocationContext) if (myClient != null && myClient!!.isConnected) { val listener: IMqttActionListener = MqttConnectionListener(resultBundle) @@ -481,7 +480,7 @@ internal class MqttConnection( topicFilters: Array, qos: Array, invocationContext: String?, - activityToken: String, + activityToken: IMqttToken, messageListeners: Array? ) { service.traceDebug( @@ -490,7 +489,7 @@ internal class MqttConnection( ) val resultBundle = Bundle() resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.SUBSCRIBE_ACTION) - resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken) + resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken.toString()) resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, invocationContext) if (myClient != null && myClient!!.isConnected) { val listener: IMqttActionListener = MqttConnectionListener(resultBundle) @@ -513,11 +512,11 @@ internal class MqttConnection( * @param invocationContext arbitrary data to be passed back to the application * @param activityToken arbitrary identifier to be passed back to the Activity */ - fun unsubscribe(topic: String, invocationContext: String?, activityToken: String) { + fun unsubscribe(topic: String, invocationContext: String?, activityToken: IMqttToken) { service.traceDebug("unsubscribe({$topic},{$invocationContext}, {$activityToken})") val resultBundle = Bundle() resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.UNSUBSCRIBE_ACTION) - resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken) + resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken.toString()) resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, invocationContext) if (myClient != null && myClient!!.isConnected) { val listener: IMqttActionListener = MqttConnectionListener(resultBundle) @@ -540,11 +539,11 @@ internal class MqttConnection( * @param invocationContext arbitrary data to be passed back to the application * @param activityToken arbitrary identifier to be passed back to the Activity */ - fun unsubscribe(topic: Array, invocationContext: String?, activityToken: String) { + fun unsubscribe(topic: Array, invocationContext: String?, activityToken: IMqttToken) { service.traceDebug("unsubscribe({" + topic.contentToString() + "},{" + invocationContext + "}, {" + activityToken + "})") val resultBundle = Bundle() resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.UNSUBSCRIBE_ACTION) - resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken) + resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken.toString()) resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, invocationContext) if (myClient != null && myClient!!.isConnected) { val listener: IMqttActionListener = MqttConnectionListener(resultBundle) @@ -674,11 +673,11 @@ internal class MqttConnection( @Synchronized private fun storeSendDetails( topic: String, msg: MqttMessage, messageToken: IMqttDeliveryToken?, - invocationContext: String?, activityToken: String + invocationContext: String?, activityToken: IMqttToken ) { savedTopics[messageToken] = topic savedSentMessages[messageToken] = msg - savedActivityTokens[messageToken] = activityToken + savedActivityTokens[messageToken] = activityToken.toString() invocationContext?.let { savedInvocationContexts[messageToken] = it } @@ -740,7 +739,7 @@ internal class MqttConnection( //The Automatic reconnect functionality is enabled here Timber.i("Requesting Automatic reconnect using New Java AC") val resultBundle = Bundle() - resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, reconnectActivityToken) + resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, reconnectActivityToken.toString()) resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, null) resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.CONNECT_ACTION) CoroutineScope(Dispatchers.IO).launch { @@ -758,7 +757,7 @@ internal class MqttConnection( // use the activityToke the same with action connect service.traceDebug("Do Real Reconnect!") val resultBundle = Bundle() - resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, reconnectActivityToken) + resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, reconnectActivityToken.toString()) resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, null) resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.CONNECT_ACTION) try { diff --git a/serviceLibrary/src/main/java/info/mqtt/android/service/MqttService.kt b/serviceLibrary/src/main/java/info/mqtt/android/service/MqttService.kt index 99c4059c..4119d005 100644 --- a/serviceLibrary/src/main/java/info/mqtt/android/service/MqttService.kt +++ b/serviceLibrary/src/main/java/info/mqtt/android/service/MqttService.kt @@ -287,7 +287,7 @@ class MqttService : Service(), MqttTraceHandler { * @param activityToken arbitrary identifier to be passed back to the Activity */ @Throws(MqttException::class) - fun connect(clientHandle: String, connectOptions: MqttConnectOptions?, activityToken: String?) { + fun connect(clientHandle: String, connectOptions: MqttConnectOptions?, activityToken: IMqttToken?) { val client = getConnection(clientHandle) CoroutineScope(Dispatchers.IO).launch { client.connect(connectOptions, null, activityToken) @@ -334,12 +334,11 @@ class MqttService : Service(), MqttTraceHandler { * @param invocationContext arbitrary data to be passed back to the application * @param activityToken arbitrary identifier to be passed back to the Activity */ - fun disconnect(clientHandle: String, invocationContext: String?, activityToken: String?) { + fun disconnect(clientHandle: String, invocationContext: String?, activityToken: IMqttToken?) { val client = getConnection(clientHandle) client.disconnect(invocationContext, activityToken) connections.remove(clientHandle) - // the activity has finished using us, so we can stop the service // the activities are bound with BIND_AUTO_CREATE, so the service will // remain around until the last activity disconnects @@ -354,7 +353,7 @@ class MqttService : Service(), MqttTraceHandler { * @param invocationContext arbitrary data to be passed back to the application * @param activityToken arbitrary identifier to be passed back to the Activity */ - fun disconnect(clientHandle: String, quiesceTimeout: Long, invocationContext: String?, activityToken: String) { + fun disconnect(clientHandle: String, quiesceTimeout: Long, invocationContext: String?, activityToken: IMqttToken) { val client = getConnection(clientHandle) client.disconnect(quiesceTimeout, invocationContext, activityToken) connections.remove(clientHandle) @@ -386,7 +385,7 @@ class MqttService : Service(), MqttTraceHandler { * @return token for tracking the operation */ fun publish( - clientHandle: String, topic: String, payload: ByteArray, qos: QoS, retained: Boolean, invocationContext: String?, activityToken: String? + clientHandle: String, topic: String, payload: ByteArray, qos: QoS, retained: Boolean, invocationContext: String?, activityToken: IMqttToken? ): IMqttDeliveryToken? { return getConnection(clientHandle).publish(topic, payload, qos, retained, invocationContext, activityToken!!) } @@ -406,7 +405,7 @@ class MqttService : Service(), MqttTraceHandler { topic: String, message: MqttMessage, invocationContext: String?, - activityToken: String + activityToken: IMqttToken ): IMqttDeliveryToken? { return getConnection(clientHandle).publish(topic, message, invocationContext, activityToken) } @@ -420,7 +419,7 @@ class MqttService : Service(), MqttTraceHandler { * @param invocationContext arbitrary data to be passed back to the application * @param activityToken arbitrary identifier to be passed back to the Activity */ - fun subscribe(clientHandle: String, topic: String, qos: QoS, invocationContext: String?, activityToken: String) { + fun subscribe(clientHandle: String, topic: String, qos: QoS, invocationContext: String?, activityToken: IMqttToken) { getConnection(clientHandle).subscribe(topic, qos, invocationContext, activityToken) } @@ -433,7 +432,7 @@ class MqttService : Service(), MqttTraceHandler { * @param invocationContext arbitrary data to be passed back to the application * @param activityToken arbitrary identifier to be passed back to the Activity */ - fun subscribe(clientHandle: String, topic: Array, qos: IntArray?, invocationContext: String?, activityToken: String) { + fun subscribe(clientHandle: String, topic: Array, qos: IntArray?, invocationContext: String?, activityToken: IMqttToken) { getConnection(clientHandle).subscribe(topic, qos, invocationContext, activityToken) } @@ -448,7 +447,7 @@ class MqttService : Service(), MqttTraceHandler { * @param messageListeners a callback to handle incoming messages */ fun subscribe( - clientHandle: String, topicFilters: Array, qos: Array, invocationContext: String?, activityToken: String?, + clientHandle: String, topicFilters: Array, qos: Array, invocationContext: String?, activityToken: IMqttToken?, messageListeners: Array? ) { getConnection(clientHandle).subscribe(topicFilters, qos, invocationContext, activityToken!!, messageListeners) @@ -462,7 +461,7 @@ class MqttService : Service(), MqttTraceHandler { * @param invocationContext arbitrary data to be passed back to the application * @param activityToken arbitrary identifier to be passed back to the Activity */ - fun unsubscribe(clientHandle: String, topic: String, invocationContext: String?, activityToken: String) { + fun unsubscribe(clientHandle: String, topic: String, invocationContext: String?, activityToken: IMqttToken) { getConnection(clientHandle).unsubscribe(topic, invocationContext, activityToken) } @@ -474,7 +473,7 @@ class MqttService : Service(), MqttTraceHandler { * @param invocationContext arbitrary data to be passed back to the application * @param activityToken arbitrary identifier to be passed back to the Activity */ - fun unsubscribe(clientHandle: String, topic: Array, invocationContext: String?, activityToken: String?) { + fun unsubscribe(clientHandle: String, topic: Array, invocationContext: String?, activityToken: IMqttToken?) { getConnection(clientHandle).unsubscribe(topic, invocationContext, activityToken!!) }