/** * Publishes a message on the topic. This is a convenience method, which will * create a new {@link MqttMessage} object with a byte array payload and the * specified QoS, and then publish it. All other values in the * message will be set to the defaults. * @param payload the byte array to use as the payload * @param qos the Quality of Service. Valid values are 0, 1 or 2. * @param retained whether or not this message should be retained by the server. * @return {@link MqttDeliveryToken} * @throws MqttException If an error occurs publishing the message * @throws MqttPersistenceException If an error occurs persisting the message * @throws IllegalArgumentException if value of QoS is not 0, 1 or 2. * @see #publish(MqttMessage) * @see MqttMessage#setQos(int) * @see MqttMessage#setRetained(boolean) */ public MqttDeliveryToken publish(byte[] payload, int qos, boolean retained) throws MqttException, MqttPersistenceException { MqttMessage message = new MqttMessage(payload); message.setQos(qos); message.setRetained(retained); return this.publish(message); }
/** * Returns a string representation of this topic. * @return a string representation of this topic. */ public String toString() { return getName(); }
/** * Validates the will fields. */ private void validateWill(String dest, Object payload) { if ((dest == null) || (payload == null)) { throw new IllegalArgumentException(); } MqttTopic.validate(dest, false/*wildcards NOT allowed*/); }
protected MqttTopic getTopic(String topic) { return new MqttTopic(topic, this); } public void setNetworkModuleIndex(int index) {
/** * Publishes the specified message to this topic, but does not wait for delivery * of the message to complete. The returned {@link MqttDeliveryToken token} can be used * to track the delivery status of the message. Once this method has * returned cleanly, the message has been accepted for publication by the * client. Message delivery will be completed in the background when a connection * is available. * * @param message the message to publish * @return an MqttDeliveryToken for tracking the delivery of the message * @throws MqttException if an error occurs publishing the message * @throws MqttPersistenceException if an error occurs persisting the message */ public MqttDeliveryToken publish(MqttMessage message) throws MqttException, MqttPersistenceException { MqttDeliveryToken token = new MqttDeliveryToken(comms.getClient().getClientId()); token.setMessage(message); comms.sendNoWait(createPublish(message), token); token.internalTok.waitUntilSent(); return token; }
protected boolean deliverMessage(String topicName, int messageId, MqttMessage aMessage) throws Exception { boolean delivered = false; Enumeration keys = callbacks.keys(); while (keys.hasMoreElements()) { String topicFilter = (String)keys.nextElement(); if (MqttTopic.isMatched(topicFilter, topicName)) { aMessage.setId(messageId); ((IMqttMessageListener)(callbacks.get(topicFilter))).messageArrived(topicName, aMessage); delivered = true; } } /* if the message hasn't been delivered to a per subscription handler, give it to the default handler */ if (mqttCallback != null && !delivered) { aMessage.setId(messageId); mqttCallback.messageArrived(topicName, aMessage); delivered = true; } return delivered; }
protected MqttTopic getTopic(String topic) { return new MqttTopic(topic, this); } public void setNetworkModuleIndex(int index) {
/** * Publishes the specified message to this topic, but does not wait for delivery * of the message to complete. The returned {@link MqttDeliveryToken token} can be used * to track the delivery status of the message. Once this method has * returned cleanly, the message has been accepted for publication by the * client. Message delivery will be completed in the background when a connection * is available. * * @param message the message to publish * @return an MqttDeliveryToken for tracking the delivery of the message */ public MqttDeliveryToken publish(MqttMessage message) throws MqttException, MqttPersistenceException { MqttDeliveryToken token = new MqttDeliveryToken(comms.getClient().getClientId()); token.setMessage(message); comms.sendNoWait(createPublish(message), token); token.internalTok.waitUntilSent(); return token; }
protected boolean deliverMessage(String topicName, int messageId, MqttMessage aMessage) throws Exception { boolean delivered = false; Enumeration keys = callbacks.keys(); while (keys.hasMoreElements()) { String topicFilter = (String)keys.nextElement(); if (MqttTopic.isMatched(topicFilter, topicName)) { aMessage.setId(messageId); ((IMqttMessageListener)(callbacks.get(topicFilter))).messageArrived(topicName, aMessage); delivered = true; } } /* if the message hasn't been delivered to a per subscription handler, give it to the default handler */ if (mqttCallback != null && !delivered) { aMessage.setId(messageId); mqttCallback.messageArrived(topicName, aMessage); delivered = true; } return delivered; }
MqttTopic.validate(topicFilters[i], true/* allow wildcards */);
MqttTopic mqttTopic = client.getTopic(topic); mqttTopic.publish(message.getBytes(), 0, false);
/** * Create a PUBLISH packet from the specified message. */ private MqttPublish createPublish(MqttMessage message) { return new MqttPublish(this.getName(), message); }
protected MqttTopic getTopic(String topic) { return new MqttTopic(topic, this); } public void setNetworkModuleIndex(int index) {
/** * Publishes the specified message to this topic, but does not wait for delivery * of the message to complete. The returned {@link MqttDeliveryToken token} can be used * to track the delivery status of the message. Once this method has * returned cleanly, the message has been accepted for publication by the * client. Message delivery will be completed in the background when a connection * is available. * * @param message the message to publish * @return an MqttDeliveryToken for tracking the delivery of the message * @throws MqttException if an error occurs publishing the message * @throws MqttPersistenceException if an error occurs persisting the message */ public MqttDeliveryToken publish(MqttMessage message) throws MqttException, MqttPersistenceException { MqttDeliveryToken token = new MqttDeliveryToken(comms.getClient().getClientId()); token.setMessage(message); comms.sendNoWait(createPublish(message), token); token.internalTok.waitUntilSent(); return token; }
protected boolean deliverMessage(String topicName, int messageId, MqttMessage aMessage) throws Exception { boolean delivered = false; Enumeration keys = callbacks.keys(); while (keys.hasMoreElements()) { String topicFilter = (String)keys.nextElement(); if (MqttTopic.isMatched(topicFilter, topicName)) { aMessage.setId(messageId); ((IMqttMessageListener)(callbacks.get(topicFilter))).messageArrived(topicName, aMessage); delivered = true; } } /* if the message hasn't been delivered to a per subscription handler, give it to the default handler */ if (mqttCallback != null && !delivered) { aMessage.setId(messageId); mqttCallback.messageArrived(topicName, aMessage); delivered = true; } return delivered; }