protected HeaderBase qos(QoS qos) { this.header &= 0xF9; this.header |= (qos.ordinal() << 1) & 0x06; return this; }
public CONNECT willQos(QoS willQos) { this.willQos = (byte) willQos.ordinal(); return this; }
public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { os.writeShort(messageId); } for(Topic topic: topics) { MessageSupport.writeUTF(os, topic.name()); os.writeByte(topic.qos().ordinal()); } MQTTFrame frame = new MQTTFrame(); frame.header(header()); frame.commandType(TYPE); return frame.buffer(os.toBuffer()); } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }
protected HeaderBase qos(QoS qos) { this.header &= 0xF9; this.header |= (qos.ordinal() << 1) & 0x06; return this; }
public CONNECT willQos(QoS willQos) { this.willQos = (byte) willQos.ordinal(); return this; }
@Override public void onResponse(MQTTProtocolConverter converter, Response response) throws IOException { // validate subscription request if (response.isException()) { final Throwable throwable = ((ExceptionResponse) response).getException(); LOG.warn("Error subscribing to {}", topicName, throwable); // version 3.1 don't supports silent fail // version 3.1.1 send "error" qos if (protocol.version == MQTTProtocolConverter.V3_1_1) { qos[0] = SUBSCRIBE_ERROR; } else { qos[0] = (byte) qoS.ordinal(); } } else { qos[0] = (byte) qoS.ordinal(); } } });
@Override public void onResponse(MQTTProtocolConverter converter, Response response) throws IOException { // validate subscription request if (response.isException()) { final Throwable throwable = ((ExceptionResponse) response).getException(); LOG.warn("Error subscribing to {}", topicName, throwable); // version 3.1 don't supports silent fail // version 3.1.1 send "error" qos if (protocol.version == MQTTProtocolConverter.V3_1_1) { qos[0] = SUBSCRIBE_ERROR; } else { qos[0] = (byte) qoS.ordinal(); } } else { qos[0] = (byte) qoS.ordinal(); } } });
@Override public void onResponse(MQTTProtocolConverter converter, Response response) throws IOException { // validate subscription request if (response.isException()) { final Throwable throwable = ((ExceptionResponse) response).getException(); LOG.warn("Error subscribing to {}", topicName, throwable); // version 3.1 don't supports silent fail // version 3.1.1 send "error" qos if (protocol.version == MQTTProtocolConverter.V3_1_1) { qos[0] = SUBSCRIBE_ERROR; } else { qos[0] = (byte) qoS.ordinal(); } } else { qos[0] = (byte) qoS.ordinal(); } } });
/** * 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; }
@Override public void onReceive(MQTTFrame frame) { // validate the QoS if (frame.messageType() == PUBLISH.TYPE) { actualQoS[0] = frame.qos().ordinal(); } } });
@Override public void onReceive(MQTTFrame frame) { // validate the QoS if (frame.messageType() == PUBLISH.TYPE) { actualQoS[0] = frame.qos().ordinal(); } } });
private byte onSubscribe(final Topic topic) throws MQTTProtocolException { final String destinationName = topic.name().toString(); final QoS requestedQoS = topic.qos(); final MQTTSubscription mqttSubscription = mqttSubscriptionByTopic.get(destinationName); if (mqttSubscription != null) { if (requestedQoS != mqttSubscription.getQoS()) { // remove old subscription as the QoS has changed onUnSubscribe(destinationName); } else { return (byte) requestedQoS.ordinal(); } } try { return onSubscribe(destinationName, requestedQoS); } catch (IOException e) { throw new MQTTProtocolException("Failed while intercepting subscribe", true, e); } } }
private byte onSubscribe(final Topic topic) throws MQTTProtocolException { final String destinationName = topic.name().toString(); final QoS requestedQoS = topic.qos(); final MQTTSubscription mqttSubscription = mqttSubscriptionByTopic.get(destinationName); if (mqttSubscription != null) { if (requestedQoS != mqttSubscription.getQoS()) { // remove old subscription as the QoS has changed onUnSubscribe(destinationName); } else { return (byte) requestedQoS.ordinal(); } } try { return onSubscribe(destinationName, requestedQoS); } catch (IOException e) { throw new MQTTProtocolException("Failed while intercepting subscribe", true, e); } } }
@Override public byte onSubscribe(final Topic topic) throws MQTTProtocolException { final String destinationName = topic.name().toString(); final QoS requestedQoS = topic.qos(); final MQTTSubscription mqttSubscription = mqttSubscriptionByTopic.get(destinationName); if (mqttSubscription != null) { if (requestedQoS != mqttSubscription.getQoS()) { // remove old subscription as the QoS has changed onUnSubscribe(destinationName); } else { try { onReSubscribe(mqttSubscription); } catch (IOException e) { throw new MQTTProtocolException("Failed to find subscription strategy", true, e); } return (byte) requestedQoS.ordinal(); } } try { return onSubscribe(destinationName, requestedQoS); } catch (IOException e) { throw new MQTTProtocolException("Failed while intercepting subscribe", true, e); } }
private byte onSubscribe(String topicName, QoS requestedQoS) throws MQTTProtocolException { ActiveMQDestination destination = new ActiveMQTopic(MQTTProtocolSupport.convertMQTTToActiveMQ(topicName)); ConsumerInfo consumerInfo = new ConsumerInfo(getNextConsumerId()); consumerInfo.setDestination(destination); consumerInfo.setPrefetchSize(ActiveMQPrefetchPolicy.DEFAULT_TOPIC_PREFETCH); consumerInfo.setRetroactive(true); consumerInfo.setDispatchAsync(true); // create durable subscriptions only when clean session is false if (!isCleanSession() && getClientId() != null && requestedQoS.ordinal() >= QoS.AT_LEAST_ONCE.ordinal()) { consumerInfo.setSubscriptionName(requestedQoS + ":" + topicName); consumerInfo.setPrefetchSize(ActiveMQPrefetchPolicy.DEFAULT_DURABLE_TOPIC_PREFETCH); } if (getActiveMQSubscriptionPrefetch() > 0) { consumerInfo.setPrefetchSize(getActiveMQSubscriptionPrefetch()); } return doSubscribe(consumerInfo, topicName, requestedQoS); }
private byte onSubscribe(String topicName, QoS requestedQoS) throws MQTTProtocolException { ActiveMQDestination destination = new ActiveMQTopic(MQTTProtocolSupport.convertMQTTToActiveMQ(topicName)); ConsumerInfo consumerInfo = new ConsumerInfo(getNextConsumerId()); consumerInfo.setDestination(destination); consumerInfo.setPrefetchSize(ActiveMQPrefetchPolicy.DEFAULT_TOPIC_PREFETCH); consumerInfo.setRetroactive(true); consumerInfo.setDispatchAsync(true); // create durable subscriptions only when clean session is false if (!isCleanSession() && getClientId() != null && requestedQoS.ordinal() >= QoS.AT_LEAST_ONCE.ordinal()) { consumerInfo.setSubscriptionName(requestedQoS + ":" + topicName); consumerInfo.setPrefetchSize(ActiveMQPrefetchPolicy.DEFAULT_DURABLE_TOPIC_PREFETCH); } if (getActiveMQSubscriptionPrefetch() > 0) { consumerInfo.setPrefetchSize(getActiveMQSubscriptionPrefetch()); } return doSubscribe(consumerInfo, topicName, requestedQoS); }
@Override public byte onSubscribe(String topicName, QoS requestedQoS) throws MQTTProtocolException { ActiveMQDestination destination = new ActiveMQTopic(MQTTProtocolSupport.convertMQTTToActiveMQ(topicName)); ConsumerInfo consumerInfo = new ConsumerInfo(getNextConsumerId()); consumerInfo.setDestination(destination); consumerInfo.setPrefetchSize(ActiveMQPrefetchPolicy.DEFAULT_TOPIC_PREFETCH); consumerInfo.setRetroactive(true); consumerInfo.setDispatchAsync(true); // create durable subscriptions only when clean session is false if (!protocol.isCleanSession() && protocol.getClientId() != null && requestedQoS.ordinal() >= QoS.AT_LEAST_ONCE.ordinal()) { consumerInfo.setSubscriptionName(requestedQoS + ":" + topicName); consumerInfo.setPrefetchSize(ActiveMQPrefetchPolicy.DEFAULT_DURABLE_TOPIC_PREFETCH); } if (protocol.getActiveMQSubscriptionPrefetch() > 0) { consumerInfo.setPrefetchSize(protocol.getActiveMQSubscriptionPrefetch()); } return doSubscribe(consumerInfo, topicName, requestedQoS); }
@Override public byte onSubscribe(String topicName, QoS requestedQoS) throws MQTTProtocolException { ActiveMQDestination destination = new ActiveMQTopic(MQTTProtocolSupport.convertMQTTToActiveMQ(topicName)); ConsumerInfo consumerInfo = new ConsumerInfo(getNextConsumerId()); consumerInfo.setDestination(destination); consumerInfo.setPrefetchSize(ActiveMQPrefetchPolicy.DEFAULT_TOPIC_PREFETCH); consumerInfo.setRetroactive(true); consumerInfo.setDispatchAsync(true); // create durable subscriptions only when clean session is false if (!protocol.isCleanSession() && protocol.getClientId() != null && requestedQoS.ordinal() >= QoS.AT_LEAST_ONCE.ordinal()) { consumerInfo.setSubscriptionName(requestedQoS + ":" + topicName); consumerInfo.setPrefetchSize(ActiveMQPrefetchPolicy.DEFAULT_DURABLE_TOPIC_PREFETCH); } if (protocol.getActiveMQSubscriptionPrefetch() > 0) { consumerInfo.setPrefetchSize(protocol.getActiveMQSubscriptionPrefetch()); } return doSubscribe(consumerInfo, topicName, requestedQoS); }
@Override public byte onSubscribe(String topicName, QoS requestedQoS) throws MQTTProtocolException { ActiveMQDestination destination = new ActiveMQTopic(MQTTProtocolSupport.convertMQTTToActiveMQ(topicName)); ConsumerInfo consumerInfo = new ConsumerInfo(getNextConsumerId()); consumerInfo.setDestination(destination); consumerInfo.setPrefetchSize(ActiveMQPrefetchPolicy.DEFAULT_TOPIC_PREFETCH); consumerInfo.setRetroactive(true); consumerInfo.setDispatchAsync(true); // create durable subscriptions only when clean session is false if (!protocol.isCleanSession() && protocol.getClientId() != null && requestedQoS.ordinal() >= QoS.AT_LEAST_ONCE.ordinal()) { consumerInfo.setSubscriptionName(requestedQoS + ":" + topicName); consumerInfo.setPrefetchSize(ActiveMQPrefetchPolicy.DEFAULT_DURABLE_TOPIC_PREFETCH); } if (protocol.getActiveMQSubscriptionPrefetch() > 0) { consumerInfo.setPrefetchSize(protocol.getActiveMQSubscriptionPrefetch()); } return doSubscribe(consumerInfo, topicName, requestedQoS); }
public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { os.writeShort(messageId); } for(Topic topic: topics) { MessageSupport.writeUTF(os, topic.name()); os.writeByte(topic.qos().ordinal()); } MQTTFrame frame = new MQTTFrame(); frame.header(header()); frame.commandType(TYPE); return frame.buffer(os.toBuffer()); } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }