public PUBLISH() { qos(QoS.AT_LEAST_ONCE); }
@Override public String toString() { return "PUBLISH{" + "dup=" + dup() + ", qos=" + qos() + ", retain=" + retain() + ", messageId=" + messageId + ", topicName=" + topicName + ", payload=" + payload + '}'; } }
public void publish(UTF8Buffer topic, Buffer payload, QoS qos, boolean retain, Callback<Void> cb) { queue.assertExecuting(); if( disconnected ) { cb.onFailure(createDisconnectedError()); return; } PUBLISH command = new PUBLISH().qos(qos).retain(retain); command.topicName(topic).payload(payload); send(command, cb); }
public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(); MessageSupport.writeUTF(os, topicName); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { os.writeShort(messageId); } MQTTFrame frame = new MQTTFrame(); frame.header(header()); frame.commandType(TYPE); if(payload!=null && payload.length!=0) { os.write(payload); } frame.buffer(os.toBuffer()); return frame; } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }
public PUBLISH decode(MQTTFrame frame) throws ProtocolException { assert(frame.buffers.length == 1); header(frame.header()); DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]); topicName = MessageSupport.readUTF(is); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { messageId = is.readShort(); } payload = is.readBuffer(is.available()); if( payload == null ) { payload = new Buffer(0); } return this; }
try { Callback<Callback<Void>> cb = null; switch( publish.qos() ) { case AT_LEAST_ONCE: cb = new Callback<Callback<Void>>() {
public PUBLISH() { qos(QoS.AT_LEAST_ONCE); }
@Override public String toString() { return "PUBLISH{" + "dup=" + dup() + ", qos=" + qos() + ", retain=" + retain() + ", messageId=" + messageId + ", topicName=" + topicName + ", payload=" + payload + '}'; } }
/** * Given a PUBLISH command determine if it will expect an ACK based on the * QoS of the Publish command and the QoS of this subscription. * * @param publish The publish command to inspect. * @return true if the client will expect an PUBACK for this PUBLISH. */ public boolean expectAck(PUBLISH publish) { QoS publishQoS = publish.qos(); if (publishQoS.compareTo(this.qos) > 0) { publishQoS = this.qos; } return !publishQoS.equals(QoS.AT_MOST_ONCE); }
/** * Given a PUBLISH command determine if it will expect an ACK based on the * QoS of the Publish command and the QoS of this subscription. * * @param publish The publish command to inspect. * @return true if the client will expect an PUBACK for this PUBLISH. */ public boolean expectAck(PUBLISH publish) { QoS publishQoS = publish.qos(); if (publishQoS.compareTo(this.qos) > 0) { publishQoS = this.qos; } return !publishQoS.equals(QoS.AT_MOST_ONCE); }
/** * Given a PUBLISH command determine if it will expect an ACK based on the * QoS of the Publish command and the QoS of this subscription. * * @param publish * The publish command to inspect. * * @return true if the client will expect an PUBACK for this PUBLISH. */ public boolean expectAck(PUBLISH publish) { QoS publishQoS = publish.qos(); if (publishQoS.compareTo(this.qos) > 0){ publishQoS = this.qos; } return !publishQoS.equals(QoS.AT_MOST_ONCE); }
/** * Given a PUBLISH command determine if it will expect an ACK based on the * QoS of the Publish command and the QoS of this subscription. * * @param publish * The publish command to inspect. * * @return true if the client will expect an PUBACK for this PUBLISH. */ public boolean expectAck(PUBLISH publish) { QoS publishQoS = publish.qos(); if (publishQoS.compareTo(this.qos) > 0){ publishQoS = this.qos; } return !publishQoS.equals(QoS.AT_MOST_ONCE); }
/** * Given a PUBLISH command determine if it will expect an ACK based on the * QoS of the Publish command and the QoS of this subscription. * * @param publish * The publish command to inspect. * * @return true if the client will expect an PUBACK for this PUBLISH. */ public boolean expectAck(PUBLISH publish) { QoS publishQoS = publish.qos(); if (publishQoS.compareTo(this.qos) > 0){ publishQoS = this.qos; } return !publishQoS.equals(QoS.AT_MOST_ONCE); }
/** * Creates a PUBLISH command that can be sent to a remote client from an * incoming {@link ActiveMQMessage} instance. * * @param message the message to convert to a PUBLISH command. * @return a new PUBLISH command that is populated from the {@link ActiveMQMessage}. * @throws DataFormatException * @throws IOException * @throws JMSException */ public PUBLISH createPublish(ActiveMQMessage message) throws DataFormatException, IOException, JMSException { PUBLISH publish = protocolConverter.convertMessage(message); if (publish.qos().ordinal() > this.qos.ordinal()) { publish.qos(this.qos); } switch (publish.qos()) { case AT_LEAST_ONCE: case EXACTLY_ONCE: // set packet id, and optionally dup flag MQTTPacketIdGenerator.setPacketId(protocolConverter.getClientId(), this, message, publish); case AT_MOST_ONCE: } return publish; }
/** * Creates a PUBLISH command that can be sent to a remote client from an * incoming {@link ActiveMQMessage} instance. * * @param message the message to convert to a PUBLISH command. * @return a new PUBLISH command that is populated from the {@link ActiveMQMessage}. * @throws DataFormatException * @throws IOException * @throws JMSException */ public PUBLISH createPublish(ActiveMQMessage message) throws DataFormatException, IOException, JMSException { PUBLISH publish = protocolConverter.convertMessage(message); if (publish.qos().ordinal() > this.qos.ordinal()) { publish.qos(this.qos); } switch (publish.qos()) { case AT_LEAST_ONCE: case EXACTLY_ONCE: // set packet id, and optionally dup flag MQTTPacketIdGenerator.setPacketId(protocolConverter.getClientId(), this, message, publish); case AT_MOST_ONCE: } return publish; }
public void publish(UTF8Buffer topic, Buffer payload, QoS qos, boolean retain, Callback<Void> cb) { queue.assertExecuting(); if( disconnected ) { cb.onFailure(createDisconnectedError()); return; } PUBLISH command = new PUBLISH().qos(qos).retain(retain); command.topicName(topic).payload(payload); send(command, cb); }
public PUBLISH decode(MQTTFrame frame) throws ProtocolException { assert(frame.buffers.length == 1); header(frame.header()); DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]); topicName = MessageSupport.readUTF(is); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { messageId = is.readShort(); } payload = is.readBuffer(is.available()); if( payload == null ) { payload = new Buffer(0); } return this; }
public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(); MessageSupport.writeUTF(os, topicName); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { os.writeShort(messageId); } MQTTFrame frame = new MQTTFrame(); frame.header(header()); frame.commandType(TYPE); if(payload!=null && payload.length!=0) { os.write(payload); } frame.buffer(os.toBuffer()); return frame; } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }
public void onTransportError() { if (connect != null) { if (connected.get()) { if (connect.willTopic() != null && connect.willMessage() != null && !willSent) { willSent = true; try { PUBLISH publish = new PUBLISH(); publish.topicName(connect.willTopic()); publish.qos(connect.willQos()); publish.messageId(MQTTPacketIdGenerator.getNextSequenceId(getClientId())); publish.payload(connect.willMessage()); ActiveMQMessage message = convertMessage(publish); message.setProducerId(producerId); message.onSend(); sendToActiveMQ(message, null); } catch (Exception e) { LOG.warn("Failed to publish Will Message " + connect.willMessage()); } } // remove connection info sendToActiveMQ(connectionInfo.createRemoveCommand(), null); } } }
public void onTransportError() { if (connect != null) { if (connected.get()) { if (connect.willTopic() != null && connect.willMessage() != null && !willSent) { willSent = true; try { PUBLISH publish = new PUBLISH(); publish.topicName(connect.willTopic()); publish.qos(connect.willQos()); publish.messageId(packetIdGenerator.getNextSequenceId(getClientId())); publish.payload(connect.willMessage()); publish.retain(connect.willRetain()); ActiveMQMessage message = convertMessage(publish); message.setProducerId(producerId); message.onSend(); sendToActiveMQ(message, null); } catch (Exception e) { LOG.warn("Failed to publish Will Message " + connect.willMessage()); } } // remove connection info sendToActiveMQ(connectionInfo.createRemoveCommand(), null); } } }