@Override public void onSuccess(IMqttToken asyncActionToken) { service.callbackToActivity(clientHandle, Status.OK, resultBundle); }
private void handleException(final Bundle resultBundle, Exception e) { resultBundle.putString(MqttServiceConstants.CALLBACK_ERROR_MESSAGE, e.getLocalizedMessage()); resultBundle.putSerializable(MqttServiceConstants.CALLBACK_EXCEPTION, e); service.callbackToActivity(clientHandle, Status.ERROR, resultBundle); }
@Override public void onFailure(IMqttToken asyncActionToken, Throwable exception) { resultBundle.putString(MqttServiceConstants.CALLBACK_ERROR_MESSAGE, exception.getLocalizedMessage()); resultBundle.putSerializable( MqttServiceConstants.CALLBACK_EXCEPTION, exception); service.callbackToActivity(clientHandle, Status.ERROR, resultBundle); } }
@Override public void onFailure(IMqttToken asyncActionToken, Throwable exception) { resultBundle.putString( MqttServiceConstants.CALLBACK_ERROR_MESSAGE, exception.getLocalizedMessage()); resultBundle.putSerializable( MqttServiceConstants.CALLBACK_EXCEPTION, exception); service.callbackToActivity(clientHandle, Status.ERROR, resultBundle); doAfterConnectFail(resultBundle); } };
@Override public void connectComplete(boolean reconnect, String serverURI) { Bundle resultBundle = new Bundle(); resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.CONNECT_EXTENDED_ACTION); resultBundle.putBoolean(MqttServiceConstants.CALLBACK_RECONNECT, reconnect); resultBundle.putString(MqttServiceConstants.CALLBACK_SERVER_URI, serverURI); service.callbackToActivity(clientHandle, Status.OK, resultBundle); }
private void traceCallback(String severity, String tag, String message) { if ((traceCallbackId != null) && (traceEnabled)) { Bundle dataBundle = new Bundle(); dataBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.TRACE_ACTION); dataBundle.putString(MqttServiceConstants.CALLBACK_TRACE_SEVERITY, severity); dataBundle.putString(MqttServiceConstants.CALLBACK_TRACE_TAG, tag); //dataBundle.putString(MqttServiceConstants.CALLBACK_TRACE_ID, traceCallbackId); dataBundle.putString(MqttServiceConstants.CALLBACK_ERROR_MESSAGE, message); callbackToActivity(traceCallbackId, Status.ERROR, dataBundle); } }
/** * trace exceptions * * @param tag * identifier for the source of the trace * @param message * the text to be traced * @param e * the exception */ @Override public void traceException(String tag, String message, Exception e) { if (traceCallbackId != null) { Bundle dataBundle = new Bundle(); dataBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.TRACE_ACTION); dataBundle.putString(MqttServiceConstants.CALLBACK_TRACE_SEVERITY, MqttServiceConstants.TRACE_EXCEPTION); dataBundle.putString(MqttServiceConstants.CALLBACK_ERROR_MESSAGE, message); dataBundle.putSerializable(MqttServiceConstants.CALLBACK_EXCEPTION, e); //TODO: Check dataBundle.putString(MqttServiceConstants.CALLBACK_TRACE_TAG, tag); //dataBundle.putString(MqttServiceConstants.CALLBACK_TRACE_ID, traceCallbackId); callbackToActivity(traceCallbackId, Status.ERROR, dataBundle); } }
invocationContext); service.callbackToActivity(clientHandle, Status.OK, resultBundle); service.callbackToActivity(clientHandle, Status.OK, resultBundle);
public void subscribe(String[] topicFilters, int[] qos, String invocationContext, String activityToken, IMqttMessageListener[] messageListeners) { service.traceDebug(TAG, "subscribe({" + Arrays.toString(topicFilters) + "}," + Arrays.toString(qos) + ",{" + invocationContext + "}, {" + activityToken + "}"); final Bundle resultBundle = new Bundle(); resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.SUBSCRIBE_ACTION); resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, activityToken); resultBundle.putString(MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, invocationContext); if((myClient != null) && (myClient.isConnected())){ IMqttActionListener listener = new MqttConnectionListener(resultBundle); try { myClient.subscribe(topicFilters, qos,messageListeners); } catch (Exception e){ handleException(resultBundle, e); } } else { resultBundle.putString(MqttServiceConstants.CALLBACK_ERROR_MESSAGE, NOT_CONNECTED); service.traceError("subscribe", NOT_CONNECTED); service.callbackToActivity(clientHandle, Status.ERROR, resultBundle); } }
private void doAfterConnectFail(final Bundle resultBundle){ // acquireWakeLock(); disconnected = true; setConnectingState(false); service.callbackToActivity(clientHandle, Status.ERROR, resultBundle); releaseWakeLock(); }
/** * Attempt to deliver any outstanding messages we've received but which the * application hasn't acknowledged. If "cleanSession" was specified, we'll * have already purged any such messages from our messageStore. */ private void deliverBacklog() { Iterator<StoredMessage> backlog = service.messageStore .getAllArrivedMessages(clientHandle); while (backlog.hasNext()) { StoredMessage msgArrived = backlog.next(); Bundle resultBundle = messageToBundle(msgArrived.getMessageId(), msgArrived.getTopic(), msgArrived.getMessage()); resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.MESSAGE_ARRIVED_ACTION); service.callbackToActivity(clientHandle, Status.OK, resultBundle); } }
/** * Callback when a message is received * * @param topic * the topic on which the message was received * @param message * the message itself */ @Override public void messageArrived(String topic, MqttMessage message) throws Exception { service.traceDebug(TAG, "messageArrived(" + topic + ",{" + message.toString() + "})"); String messageId = service.messageStore.storeArrived(clientHandle, topic, message); Bundle resultBundle = messageToBundle(messageId, topic, message); resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.MESSAGE_ARRIVED_ACTION); resultBundle.putString(MqttServiceConstants.CALLBACK_MESSAGE_ID, messageId); service.callbackToActivity(clientHandle, Status.OK, resultBundle); }
Log.getStackTraceString(why)); service.callbackToActivity(clientHandle, Status.OK, resultBundle);
service.callbackToActivity(clientHandle, Status.ERROR, resultBundle);
NOT_CONNECTED); service.traceError("subscribe", NOT_CONNECTED); service.callbackToActivity(clientHandle, Status.ERROR, resultBundle);
private void doAfterConnectSuccess(final Bundle resultBundle) { //since the device's cpu can go to sleep, acquire a wakelock and drop it later. acquireWakeLock(); service.callbackToActivity(clientHandle, Status.OK, resultBundle); deliverBacklog(); setConnectingState(false); disconnected = false; releaseWakeLock(); }
NOT_CONNECTED); service.traceError("subscribe", NOT_CONNECTED); service.callbackToActivity(clientHandle, Status.ERROR, resultBundle);
service.callbackToActivity(clientHandle, Status.ERROR, resultBundle);
service.traceError(MqttServiceConstants.DISCONNECT_ACTION, NOT_CONNECTED); service.callbackToActivity(clientHandle, Status.ERROR, resultBundle);
service.traceError(MqttServiceConstants.DISCONNECT_ACTION, NOT_CONNECTED); service.callbackToActivity(clientHandle, Status.ERROR, resultBundle);