public void unsubscribe(final UTF8Buffer[] topics, Callback<Void> cb) { queue.assertExecuting(); if( disconnected ) { cb.onFailure(createDisconnectedError()); return; } send(new UNSUBSCRIBE().topics(topics), new ProxyCallback(cb){ @Override public void onSuccess(Object value) { for (UTF8Buffer topic : topics) { activeSubs.remove(topic); } if(next!=null) { next.onSuccess(value); } } }); }
public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { os.writeShort(messageId); } for(UTF8Buffer topic: topics) { MessageSupport.writeUTF(os, topic); } MQTTFrame frame = new MQTTFrame(); frame.header(header()); frame.commandType(TYPE); return frame.buffer(os.toBuffer()); } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }
break; case UNSUBSCRIBE.TYPE: onUnSubscribe(new UNSUBSCRIBE().decode(frame)); break; case PUBLISH.TYPE:
public void onUnSubscribe(UNSUBSCRIBE command) throws MQTTProtocolException { checkConnected(); if (command.qos() != QoS.AT_LEAST_ONCE && (version != V3_1 || publishDollarTopics != true)) { throw new MQTTProtocolException("Failed to process unsubscribe request", true, new Exception("UNSUBSCRIBE frame not properly formatted, QoS")); } UTF8Buffer[] topics = command.topics(); if (topics != null) { for (UTF8Buffer topic : topics) { MQTTProtocolSupport.validate(topic.toString()); try { findSubscriptionStrategy().onUnSubscribe(topic.toString()); } catch (IOException e) { throw new MQTTProtocolException("Failed to process unsubscribe request", true, e); } } UNSUBACK ack = new UNSUBACK(); ack.messageId(command.messageId()); sendToMQTT(ack.encode()); } else { LOG.warn("No topics defined for Subscription " + command); throw new MQTTProtocolException("UNSUBSCRIBE command received with no topic filter"); } }
static private String toString(MQTTFrame frame) { if( frame == null ) return null; try { switch (frame.messageType()) { case PINGREQ.TYPE: return new PINGREQ().decode(frame).toString(); case PINGRESP.TYPE: return new PINGRESP().decode(frame).toString(); case CONNECT.TYPE: return new CONNECT().decode(frame).toString(); case DISCONNECT.TYPE: return new DISCONNECT().decode(frame).toString(); case SUBSCRIBE.TYPE: return new SUBSCRIBE().decode(frame).toString(); case UNSUBSCRIBE.TYPE: return new UNSUBSCRIBE().decode(frame).toString(); case PUBLISH.TYPE: return new PUBLISH().decode(frame).toString(); case PUBACK.TYPE: return new PUBACK().decode(frame).toString(); case PUBREC.TYPE: return new PUBREC().decode(frame).toString(); case PUBREL.TYPE: return new PUBREL().decode(frame).toString(); case PUBCOMP.TYPE: return new PUBCOMP().decode(frame).toString(); case CONNACK.TYPE: return new CONNACK().decode(frame).toString(); case SUBACK.TYPE: return new SUBACK().decode(frame).toString(); default: return frame.toString(); } } catch (Throwable e) { LOG.warn(e.getMessage(), e); return frame.toString(); } }
public void onUnSubscribe(UNSUBSCRIBE command) throws MQTTProtocolException { checkConnected(); UTF8Buffer[] topics = command.topics(); if (topics != null) { for (UTF8Buffer topic : topics) { try { onUnSubscribe(topic.toString()); } catch (IOException e) { throw new MQTTProtocolException("Failed to process unsubscribe request", true, e); } } } UNSUBACK ack = new UNSUBACK(); ack.messageId(command.messageId()); sendToMQTT(ack.encode()); }
public void on_mqtt_unsubscribe(final UNSUBSCRIBE unsubscribe) { ArrayList<BindAddress> addressesList = Scala2Java.flatMap(Arrays.asList(unsubscribe.topics()), new Fn1<UTF8Buffer, Option<BindAddress>>() { @Override public Option<BindAddress> apply(UTF8Buffer topicName) {
public UNSUBSCRIBE() { qos(QoS.AT_LEAST_ONCE); }
break; case UNSUBSCRIBE.TYPE: onUnSubscribe(new UNSUBSCRIBE().decode(frame)); break; case PUBLISH.TYPE:
public void onUnSubscribe(UNSUBSCRIBE command) throws MQTTProtocolException { checkConnected(); if (command.qos() != QoS.AT_LEAST_ONCE && (version != V3_1 || publishDollarTopics != true)) { throw new MQTTProtocolException("Failed to process unsubscribe request", true, new Exception("UNSUBSCRIBE frame not properly formatted, QoS")); } UTF8Buffer[] topics = command.topics(); if (topics != null) { for (UTF8Buffer topic : topics) { MQTTProtocolSupport.validate(topic.toString()); try { findSubscriptionStrategy().onUnSubscribe(topic.toString()); } catch (IOException e) { throw new MQTTProtocolException("Failed to process unsubscribe request", true, e); } } UNSUBACK ack = new UNSUBACK(); ack.messageId(command.messageId()); sendToMQTT(ack.encode()); } else { LOG.warn("No topics defined for Subscription " + command); throw new MQTTProtocolException("UNSUBSCRIBE command received with no topic filter"); } }
static private String toString(MQTTFrame frame) { if( frame == null ) return null; try { switch (frame.messageType()) { case PINGREQ.TYPE: return new PINGREQ().decode(frame).toString(); case PINGRESP.TYPE: return new PINGRESP().decode(frame).toString(); case CONNECT.TYPE: return new CONNECT().decode(frame).toString(); case DISCONNECT.TYPE: return new DISCONNECT().decode(frame).toString(); case SUBSCRIBE.TYPE: return new SUBSCRIBE().decode(frame).toString(); case UNSUBSCRIBE.TYPE: return new UNSUBSCRIBE().decode(frame).toString(); case PUBLISH.TYPE: return new PUBLISH().decode(frame).toString(); case PUBACK.TYPE: return new PUBACK().decode(frame).toString(); case PUBREC.TYPE: return new PUBREC().decode(frame).toString(); case PUBREL.TYPE: return new PUBREL().decode(frame).toString(); case PUBCOMP.TYPE: return new PUBCOMP().decode(frame).toString(); case CONNACK.TYPE: return new CONNACK().decode(frame).toString(); case SUBACK.TYPE: return new SUBACK().decode(frame).toString(); default: return frame.toString(); } } catch (Throwable e) { LOG.warn(e.getMessage(), e); return frame.toString(); } }
public void onUnSubscribe(UNSUBSCRIBE command) throws MQTTProtocolException { checkConnected(); UTF8Buffer[] topics = command.topics(); if (topics != null) { for (UTF8Buffer topic : topics) { try { onUnSubscribe(topic.toString()); } catch (IOException e) { throw new MQTTProtocolException("Failed to process unsubscribe request", true, e); } } } UNSUBACK ack = new UNSUBACK(); ack.messageId(command.messageId()); sendToMQTT(ack.encode()); }
public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { os.writeShort(messageId); } for(UTF8Buffer topic: topics) { MessageSupport.writeUTF(os, topic); } MQTTFrame frame = new MQTTFrame(); frame.header(header()); frame.commandType(TYPE); return frame.buffer(os.toBuffer()); } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }
public UNSUBSCRIBE() { qos(QoS.AT_LEAST_ONCE); }
break; case UNSUBSCRIBE.TYPE: onUnSubscribe(new UNSUBSCRIBE().decode(frame)); break; case PUBLISH.TYPE:
public void onUnSubscribe(UNSUBSCRIBE command) throws MQTTProtocolException { checkConnected(); if (command.qos() != QoS.AT_LEAST_ONCE && (version != V3_1 || publishDollarTopics != true)) { throw new MQTTProtocolException("Failed to process unsubscribe request", true, new Exception("UNSUBSCRIBE frame not properly formatted, QoS")); } UTF8Buffer[] topics = command.topics(); if (topics != null) { for (UTF8Buffer topic : topics) { MQTTProtocolSupport.validate(topic.toString()); try { findSubscriptionStrategy().onUnSubscribe(topic.toString()); } catch (IOException e) { throw new MQTTProtocolException("Failed to process unsubscribe request", true, e); } } UNSUBACK ack = new UNSUBACK(); ack.messageId(command.messageId()); sendToMQTT(ack.encode()); } else { LOG.warn("No topics defined for Subscription " + command); throw new MQTTProtocolException("UNSUBSCRIBE command received with no topic filter"); } }
static private String toString(MQTTFrame frame) { if( frame == null ) return null; try { switch (frame.messageType()) { case PINGREQ.TYPE: return new PINGREQ().decode(frame).toString(); case PINGRESP.TYPE: return new PINGRESP().decode(frame).toString(); case CONNECT.TYPE: return new CONNECT().decode(frame).toString(); case DISCONNECT.TYPE: return new DISCONNECT().decode(frame).toString(); case SUBSCRIBE.TYPE: return new SUBSCRIBE().decode(frame).toString(); case UNSUBSCRIBE.TYPE: return new UNSUBSCRIBE().decode(frame).toString(); case PUBLISH.TYPE: return new PUBLISH().decode(frame).toString(); case PUBACK.TYPE: return new PUBACK().decode(frame).toString(); case PUBREC.TYPE: return new PUBREC().decode(frame).toString(); case PUBREL.TYPE: return new PUBREL().decode(frame).toString(); case PUBCOMP.TYPE: return new PUBCOMP().decode(frame).toString(); case CONNACK.TYPE: return new CONNACK().decode(frame).toString(); case SUBACK.TYPE: return new SUBACK().decode(frame).toString(); default: return frame.toString(); } } catch (Throwable e) { LOG.warn(e.getMessage(), e); return frame.toString(); } }
public void unsubscribe(final UTF8Buffer[] topics, Callback<Void> cb) { queue.assertExecuting(); if( disconnected ) { cb.onFailure(createDisconnectedError()); return; } send(new UNSUBSCRIBE().topics(topics), new ProxyCallback(cb){ @Override public void onSuccess(Object value) { for (UTF8Buffer topic : topics) { activeSubs.remove(topic); } if(next!=null) { next.onSuccess(value); } } }); }