/** * Disconnects from the server. * <p> * An attempt is made to quiesce the client allowing outstanding work to * complete before disconnecting. It will wait for a maximum of 30 seconds * for work to quiesce before disconnecting. This method must not be called * from inside {@link MqttCallback} methods. * </p> * * @return token used to track and wait for disconnect to complete. The * token will be passed to any callback that has been set. * @throws MqttException * for problems encountered while disconnecting * @see #disconnect(long, Object, IMqttActionListener) */ @Override public IMqttToken disconnect() throws MqttException { IMqttToken token = new MqttTokenAndroid(this, null, null); String activityToken = storeToken(token); mqttService.disconnect(clientHandle, null, activityToken); return token; }
/** * Common processing for many notifications * * @param token * the token associated with the action being undertake * @param data * the result data */ private void simpleAction(IMqttToken token, Bundle data) { if (token != null) { Status status = (Status) data .getSerializable(MqttServiceConstants.CALLBACK_STATUS); if (status == Status.OK) { ((MqttTokenAndroid) token).notifyComplete(); } else { Exception exceptionThrown = (Exception) data.getSerializable(MqttServiceConstants.CALLBACK_EXCEPTION); ((MqttTokenAndroid) token).notifyFailure(exceptionThrown); } } else { mqttService.traceError(MqttService.TAG, "simpleAction : token is null"); } }
/** * Common processing for many notifications * * @param token * the token associated with the action being undertake * @param data * the result data */ private void simpleAction(IMqttToken token, Bundle data) { if (token != null) { Status status = (Status) data .getSerializable(MqttServiceConstants.CALLBACK_STATUS); if (status == Status.OK) { ((MqttTokenAndroid) token).notifyComplete(); } else if(status == Status.INTERMEDIATE){ ((MqttTokenAndroid) token).notifyIntermediate(); } else { Exception exceptionThrown = (Exception) data.getSerializable(MqttServiceConstants.CALLBACK_EXCEPTION); ((MqttTokenAndroid) token).notifyFailure(exceptionThrown); } } else { mqttService.traceError(MqttService.TAG, "simpleAction : token is null"); } }
void notifyDelivery(MqttMessage delivered) { message = delivered; super.notifyComplete(); }
/** * Process a notification that we have disconnected * * @param data */ private void disconnected(Bundle data) { clientHandle = null; // avoid reuse! IMqttToken token = removeMqttToken(data); if (token != null) { ((MqttTokenAndroid) token).notifyComplete(); } if (callback != null) { callback.connectionLost(null); } }
/** * Requests the server to unsubscribe the client from a topics. * * @param topic * the topic to unsubscribe from. It must match a topic specified * on an earlier subscribe. * @param userContext * optional object used to pass context to the callback. Use null * if not required. * @param callback * optional listener that will be notified when unsubscribe has * completed * @return token used to track and wait for the unsubscribe to complete. The * token will be passed to callback methods if set. * @throws MqttException * if there was an error unregistering the subscription. * * @see #unsubscribe(String[], Object, IMqttActionListener) */ @Override public IMqttToken unsubscribe(String topic, Object userContext, IMqttActionListener callback) throws MqttException { IMqttToken token = new MqttTokenAndroid(this, userContext, callback); String activityToken = storeToken(token); mqttService.unsubscribe(clientHandle, topic, null, activityToken); return token; }
/** * Common processing for many notifications * * @param token * the token associated with the action being undertake * @param data * the result data */ private void simpleAction(IMqttToken token, Bundle data) { if (token != null) { Status status = (Status) data .getSerializable(MqttServiceConstants.CALLBACK_STATUS); if (status == Status.OK) { ((MqttTokenAndroid) token).notifyComplete(); } else { Exception exceptionThrown = (Exception) data.getSerializable(MqttServiceConstants.CALLBACK_EXCEPTION); ((MqttTokenAndroid) token).notifyFailure(exceptionThrown); } } else { mqttService.traceError(MqttService.TAG, "simpleAction : token is null"); } }
void notifyDelivery(MqttMessage delivered) { message = delivered; super.notifyComplete(); }
/** * Disconnects from the server. * <p> * An attempt is made to quiesce the client allowing outstanding work to * complete before disconnecting. It will wait for a maximum of the * specified quiesce time for work to complete before disconnecting. This * method must not be called from inside {@link MqttCallback} methods. * </p> * * @param 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. * @return token used to track and wait for disconnect to complete. The * token will be passed to the callback methods if a callback is * set. * @throws MqttException * for problems encountered while disconnecting * @see #disconnect(long, Object, IMqttActionListener) */ @Override public IMqttToken disconnect(long quiesceTimeout) throws MqttException { IMqttToken token = new MqttTokenAndroid(this, null, null); String activityToken = storeToken(token); mqttService.disconnect(clientHandle, quiesceTimeout, null, activityToken); return token; }
void notifyDelivery(MqttMessage delivered) { message = delivered; super.notifyComplete(); }
/** * Subscribe to multiple topics, each of which may include wildcards. * * <p>Provides an optimized way to subscribe to multiple topics compared to * subscribing to each one individually.</p> * * @see #subscribe(String[], int[], Object, IMqttActionListener) * * @param topicFilters one or more topics to subscribe to, which can include wildcards * @param qos the maximum quality of service at which to subscribe. Messages * published at a lower quality of service will be received at the published * QoS. Messages published at a higher quality of service will be received using * the QoS specified on the subscribe. * @param userContext optional object used to pass context to the callback. Use * null if not required. * @param callback optional listener that will be notified when subscribe * has completed * @param messageListeners an array of callbacks to handle incoming messages * @return token used to track and wait for the subscribe to complete. The token * will be passed to callback methods if set. * @throws MqttException if there was an error registering the subscription. */ public IMqttToken subscribe(String[] topicFilters, int[] qos, Object userContext, IMqttActionListener callback, IMqttMessageListener[] messageListeners) throws MqttException { IMqttToken token = new MqttTokenAndroid(this, userContext, callback, topicFilters); String activityToken = storeToken(token); mqttService.subscribe(clientHandle, topicFilters, qos, null, activityToken, messageListeners); return null; }
/** * Process a notification that we have disconnected * * @param data */ private void disconnected(Bundle data) { clientHandle = null; // avoid reuse! IMqttToken token = removeMqttToken(data); if (token != null) { ((MqttTokenAndroid) token).notifyComplete(); } if (callback != null) { callback.connectionLost(null); } }
/** * Disconnects from the server. * <p> * An attempt is made to quiesce the client allowing outstanding work to * complete before disconnecting. It will wait for a maximum of 30 seconds * for work to quiesce before disconnecting. This method must not be called * from inside {@link MqttCallback} methods. * </p> * * @param userContext * optional object used to pass context to the callback. Use null * if not required. * @param callback * optional listener that will be notified when the disconnect * completes. Use null if not required. * @return token used to track and wait for the disconnect to complete. The * token will be passed to any callback that has been set. * @throws MqttException * for problems encountered while disconnecting * @see #disconnect(long, Object, IMqttActionListener) */ @Override public IMqttToken disconnect(Object userContext, IMqttActionListener callback) throws MqttException { IMqttToken token = new MqttTokenAndroid(this, userContext, callback); String activityToken = storeToken(token); mqttService.disconnect(clientHandle, null, activityToken); return token; }
/** * Process a notification that we have disconnected * * @param data */ private void disconnected(Bundle data) { clientHandle = null; // avoid reuse! IMqttToken token = removeMqttToken(data); if (token != null) { ((MqttTokenAndroid) token).notifyComplete(); } if (callback != null) { callback.connectionLost(null); } }
public IMqttToken subscribe(String topic, int qos, Object userContext, IMqttActionListener callback) throws MqttException { IMqttToken token = new MqttTokenAndroid(this, userContext, callback, new String[]{topic}); String activityToken = storeToken(token);
public IMqttToken unsubscribe(String[] topic, Object userContext, IMqttActionListener callback) throws MqttException { IMqttToken token = new MqttTokenAndroid(this, userContext, callback); String activityToken = storeToken(token);
public IMqttToken disconnect(long quiesceTimeout, Object userContext, IMqttActionListener callback) throws MqttException { IMqttToken token = new MqttTokenAndroid(this, userContext, callback); String activityToken = storeToken(token);
IMqttActionListener callback) throws MqttException { IMqttToken token = new MqttTokenAndroid(this, userContext, callback);
public IMqttToken subscribe(String[] topic, int[] qos, Object userContext, IMqttActionListener callback) throws MqttException { IMqttToken token = new MqttTokenAndroid(this, userContext, callback, topic); String activityToken = storeToken(token);
/** * Disconnects from the server. * <p> * An attempt is made to quiesce the client allowing outstanding work to * complete before disconnecting. It will wait for a maximum of 30 seconds * for work to quiesce before disconnecting. This method must not be called * from inside {@link MqttCallback} methods. * </p> * * @return token used to track and wait for disconnect to complete. The * token will be passed to any callback that has been set. * @throws MqttException * for problems encountered while disconnecting * @see #disconnect(long, Object, IMqttActionListener) */ @Override public IMqttToken disconnect() throws MqttException { IMqttToken token = new MqttTokenAndroid(this, null, null); String activityToken = storeToken(token); mqttService.disconnect(clientHandle, null, activityToken); return token; }