本文整理匯總了Java中org.eclipse.paho.client.mqttv3.IMqttDeliveryToken類的典型用法代碼示例。如果您正苦於以下問題:Java IMqttDeliveryToken類的具體用法?Java IMqttDeliveryToken怎麽用?Java IMqttDeliveryToken使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IMqttDeliveryToken類屬於org.eclipse.paho.client.mqttv3包,在下文中一共展示了IMqttDeliveryToken類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deliveryComplete
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
/**
* Callback method which gets triggered upon successful completion of a message delivery to the broker.
*
* @param iMqttDeliveryToken the MQTT-DeliveryToken which includes the details about the specific message delivery.
*/
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
String topic = iMqttDeliveryToken.getTopics()[0];
String client = iMqttDeliveryToken.getClient().getClientId();
try {
if (iMqttDeliveryToken.isComplete()) {
if (iMqttDeliveryToken.getMessage() != null) {
String message = iMqttDeliveryToken.getMessage().toString();
Log.d(TAG, "Message to client [" + client + "] under topic (" + topic +
") was delivered successfully with the delivery message: '" + message + "'");
} else {
Log.d(TAG, "Message to client [" + client + "] under topic (" + topic +
") was delivered successfully.");
}
} else {
Log.w(TAG, "FAILED: Delivery of MQTT message to [" + client + "] under topic [" + topic + "] failed.");
}
} catch (MqttException e) {
Log.w(TAG, "Error occurred whilst trying to read the message from the MQTT delivery token.");
}
}
示例2: mqttCallback
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
protected void mqttCallback() {
client.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable cause) {
msg("Connection lost...");
}
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
TextView tvMessage = (TextView) findViewById(R.id.tvMessage);
tvMessage.setText(message.toString());
}
@Override
public void deliveryComplete(IMqttDeliveryToken token) {
}
});
}
示例3: deliveryComplete
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
/**
* @see MqttCallback#deliveryComplete(IMqttDeliveryToken)
*/
@Override
public void deliveryComplete(IMqttDeliveryToken token) {
// Called when a message has been delivered to the
// server. The token passed in here is the same one
// that was returned from the original call to publish.
// This allows applications to perform asynchronous
// delivery without blocking until delivery completes.
//
// This sample demonstrates asynchronous deliver, registering
// a callback to be notified on each call to publish.
//
// The deliveryComplete method will also be called if
// the callback is set on the client
//
// note that token.getTopics() returns an array so we convert to a
// string
// before printing it on the console
log.info("Delivery complete callback: Publish Completed " + Arrays.toString(token.getTopics()));
}
示例4: deliveryComplete
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
/**
* Callback method which gets triggered upon successful completion of a message delivery to
* the broker.
*
* @param iMqttDeliveryToken the MQTT-DeliveryToken which includes the details about the
* specific message delivery.
*/
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
String message = "";
try {
message = iMqttDeliveryToken.getMessage().toString();
} catch (MqttException e) {
log.error(
"Error occurred whilst trying to read the message from the MQTT delivery " +
"token.");
}
String topic = iMqttDeliveryToken.getTopics()[0];
String client = iMqttDeliveryToken.getClient().getClientId();
if (log.isDebugEnabled()) {
log.debug("Message - '" + message + "' of client [" + client + "] for the topic (" +
topic +
") was delivered successfully.");
}
}
示例5: blockForAllTokens
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
private void blockForAllTokens(MqttClient client) {
IMqttDeliveryToken[] tokens = client.getPendingDeliveryTokens();
int j = tokens.length;
while (--j>=0) {
try {
if (!tokens[j].isComplete()) {
tokens[j].waitForCompletion();
}
if (null!=tokens[j].getException()) {
tokens[j].getException().printStackTrace();
}
} catch (MqttException e) {
throw new RuntimeException(e);
}
}
}
示例6: attachCallback
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
/** Attaches the callback used when configuration changes occur. */
public static void attachCallback(MqttClient client, String deviceId) throws MqttException {
mCallback = new MqttCallback() {
@Override
public void connectionLost(Throwable cause) {
// Do nothing...
}
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
String payload = new String(message.getPayload());
System.out.println("Payload : " + payload);
// TODO: Insert your parsing / handling of the configuration message here.
}
@Override
public void deliveryComplete(IMqttDeliveryToken token) {
// Do nothing;
}
};
String configTopic = String.format("/devices/%s/config", deviceId);
client.subscribe(configTopic, 1);
client.setCallback(mCallback);
}
示例7: testMqtt
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
@Test
public void testMqtt() throws MqttException, InterruptedException {
final CountDownLatch messageReceived = new CountDownLatch(1);
MqttClient client = new MqttClient(mqttServer.getConnectString(), UUID.randomUUID().toString(), new MemoryPersistence());
client.connect();
client.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable cause) {
}
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
messageReceived.countDown();
}
@Override
public void deliveryComplete(IMqttDeliveryToken token) {
}
});
client.subscribe(TOPIC_NAME_TEST);
client.publish(TOPIC_NAME_TEST, UUID.randomUUID().toString().getBytes(), 0, false);
assertTrue(messageReceived.await(MQTT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
client.disconnect();
}
示例8: createCallback
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
private MqttCallback createCallback() {
return new MqttCallback() {
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
messageIds.add(message.getId());
messageArrived = true;
}
@Override
public void deliveryComplete(IMqttDeliveryToken token) {
}
@Override
public void connectionLost(Throwable cause) {
}
};
}
示例9: deliveryComplete
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
/**
* Callback method which gets triggered upon successful completion of a message delivery to
* the broker.
*
* @param iMqttDeliveryToken the MQTT-DeliveryToken which includes the details about the
* specific message delivery.
*/
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
String message = "";
try {
message = iMqttDeliveryToken.getMessage().toString();
} catch (MqttException e) {
//TODO:: Throw errors
log.error(
"Error occurred whilst trying to read the message from the MQTT delivery " +
"token.");
}
String topic = iMqttDeliveryToken.getTopics()[0];
String client = iMqttDeliveryToken.getClient().getClientId();
if (log.isDebugEnabled()) {
log.debug("Message - '" + message + "' of client [" + client + "] for the topic (" +
topic + ") was delivered successfully.");
}
}
示例10: deliveryComplete
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
/**
* Callback method which gets triggered upon successful completion of a message delivery to
* the broker.
*
* @param iMqttDeliveryToken the MQTT-DeliveryToken which includes the details about the
* specific message delivery.
*/
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
String message = "";
try {
message = iMqttDeliveryToken.getMessage().toString();
} catch (MqttException e) {
log.error(
"Error occurred whilst trying to read the message from the MQTT delivery " +
"token.");
}
String topic = iMqttDeliveryToken.getTopics()[0];
String client = iMqttDeliveryToken.getClient().getClientId();
if (log.isDebugEnabled()) {
log.debug("Message - '" + message + "' of client [" + client + "] for the topic (" +
topic + ") was delivered successfully.");
}
}
示例11: deliveryComplete
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
/**
* @see MqttCallback#deliveryComplete(IMqttDeliveryToken)
*/
public void deliveryComplete(IMqttDeliveryToken token) {
// Called when a message has been delivered to the
// server. The token passed in here is the same one
// that was passed to or returned from the original call to publish.
// This allows applications to perform asynchronous
// delivery without blocking until delivery completes.
//
// This sample demonstrates asynchronous deliver and
// uses the token.waitForCompletion() call in the main thread which
// blocks until the delivery has completed.
// Additionally the deliveryComplete method will be called if
// the callback is set on the client
//
// If the connection to the server breaks before delivery has completed
// delivery of a message will complete after the client has re-connected.
// The getPendingTokens method will provide tokens for any messages
// that are still to be delivered.
}
示例12: deliveryComplete
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
/**
* @see MqttCallback#deliveryComplete(IMqttDeliveryToken)
*/
@Override
public void deliveryComplete(IMqttDeliveryToken token) {
// Called when a message has been delivered to the
// server. The token passed in here is the same one
// that was returned from the original call to publish.
// This allows applications to perform asynchronous
// delivery without blocking until delivery completes.
//
// This sample demonstrates asynchronous deliver, registering
// a callback to be notified on each call to publish.
//
// The deliveryComplete method will also be called if
// the callback is set on the client
//
// note that token.getTopics() returns an array so we convert to a
// string
// before printing it on the console
log.info("Delivery complete callback: Publish Completed " + Arrays.toString(token.getTopics()));
}
示例13: deliveryComplete
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
/**
* @see MqttCallback#deliveryComplete(IMqttDeliveryToken)
*/
public void deliveryComplete(IMqttDeliveryToken token) {
// Called when a message has been delivered to the
// server. The token passed in here is the same one
// that was returned from the original call to publish.
// This allows applications to perform asynchronous
// delivery without blocking until delivery completes.
//
// This sample demonstrates asynchronous deliver, registering
// a callback to be notified on each call to publish.
//
// The deliveryComplete method will also be called if
// the callback is set on the client
//
log("Delivery complete callback: Publish Completed " + token.getTopics());
}
示例14: update
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
protected void update(MqttAsyncClient mqttClient, AnIntent intent) throws MqttException {
for (Content content : this.getValueMap().values()) {
String property = content.getProperty();
if (property != null) {
Content intentContent = intent.getContent(property);
if (intentContent != null) {
IMqttDeliveryToken token = publish(property, toJSONMQTTMessage(intentContent.getValue(intentContent.description.typeOfClass)), mqttClient);
try {
token.waitForCompletion(10);
} catch (Exception ex) {
System.out.println(token.getException());
}
}
}
}
}
示例15: GUIApplication
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; //導入依賴的package包/類
public GUIApplication() throws MqttException {
empf = builder.uri("tcp://" + BarometerApplication.BROKER + ":1883").clientUID("ch.quantasy.knr1.GUIApplication").build();
empf.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable throwable) {
}
@Override
public void messageArrived(String str, MqttMessage mqttMessage)
throws Exception {
byte[] payload = mqttMessage.getPayload();
ByteBuffer bb = ByteBuffer.wrap(payload);
AltitudeProfileView.addBarometricAltitudeData(bb.getInt());
}
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
}
});
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(true);
empf.connect(options);
empf.subscribe(BarometerApplication.TOPIC + "+", 0);
}