當前位置: 首頁>>代碼示例>>Java>>正文


Java IMqttDeliveryToken類代碼示例

本文整理匯總了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.");
    }
}
 
開發者ID:wso2-incubator,項目名稱:iot-server-agents,代碼行數:28,代碼來源:MQTTTransportHandler.java

示例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) {

        }
    });
}
 
開發者ID:chooka888,項目名稱:ConAir,代碼行數:20,代碼來源:ACController.java

示例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()));
}
 
開發者ID:glaudiston,項目名稱:project-bianca,代碼行數:23,代碼來源:MQTT.java

示例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.");
	}
}
 
開發者ID:wso2-incubator,項目名稱:iot-server-appliances,代碼行數:27,代碼來源:MQTTCommunicationHandler.java

示例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);
		}
	}
}
 
開發者ID:nathantippy,項目名稱:PublishLoadGenerator-For-MQTT,代碼行數:19,代碼來源:MQTTStage.java

示例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);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:27,代碼來源:MqttExample.java

示例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();
}
 
開發者ID:ggear,項目名稱:cloudera-framework,代碼行數:25,代碼來源:TestMqttServer.java

示例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) {
      }
   };
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:19,代碼來源:MqttAcknowledgementTest.java

示例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.");
    }
}
 
開發者ID:wso2-incubator,項目名稱:iot-server-agents,代碼行數:27,代碼來源:MQTTTransportHandler.java

示例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.");
	}
}
 
開發者ID:wso2-incubator,項目名稱:iot-server-agents,代碼行數:26,代碼來源:MQTTCommunicationHandler.java

示例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.
}
 
開發者ID:MyRobotLab,項目名稱:myrobotlab,代碼行數:22,代碼來源:Sample.java

示例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()));
}
 
開發者ID:MyRobotLab,項目名稱:myrobotlab,代碼行數:23,代碼來源:Mqtt.java

示例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());
}
 
開發者ID:MyRobotLab,項目名稱:myrobotlab,代碼行數:19,代碼來源:SampleAsyncCallback.java

示例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());
	    }
	}
    }
}
   }
 
開發者ID:knr1,項目名稱:ch.bfh.mobicomp,代碼行數:17,代碼來源:AMessage.java

示例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);
   }
 
開發者ID:knr1,項目名稱:ch.bfh.mobicomp,代碼行數:25,代碼來源:GUIApplication.java


注:本文中的org.eclipse.paho.client.mqttv3.IMqttDeliveryToken類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。