Java 类io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader 实例源码

项目:lannister    文件:MqttMessageFactory.java   
public static MqttPubAckMessage puback(int messageId) {
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBACK, false, MqttQoS.AT_MOST_ONCE, false,
            2);
    MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);

    return new MqttPubAckMessage(fixedHeader, variableHeader);
}
项目:lannister    文件:MqttMessageFactory.java   
public static MqttMessage pubrec(int messageId) {
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBREC, false, MqttQoS.AT_MOST_ONCE, false,
            2);
    MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);

    return new MqttMessage(fixedHeader, variableHeader);
}
项目:lannister    文件:MqttMessageFactory.java   
public static MqttMessage pubrel(int messageId) {
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBREL, false, MqttQoS.AT_LEAST_ONCE, false,
            2);
    MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);

    return new MqttMessage(fixedHeader, variableHeader);
}
项目:lannister    文件:MqttMessageFactory.java   
public static MqttMessage pubcomp(int messageId) {
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBCOMP, false, MqttQoS.AT_MOST_ONCE, false,
            2);
    MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);

    return new MqttMessage(fixedHeader, variableHeader);
}
项目:lannister    文件:MqttMessageFactory.java   
public static MqttSubscribeMessage subscribe(int messageId, MqttTopicSubscription... topicSubscriptions) {
    int topicNameSize = 0;
    int topicCount = topicSubscriptions.length;

    for (MqttTopicSubscription item : topicSubscriptions) {
        topicNameSize += item.topicName().getBytes(CharsetUtil.UTF_8).length;
    }

    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.SUBSCRIBE, false, MqttQoS.AT_LEAST_ONCE,
            false, 2 + topicNameSize + topicCount);
    MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);
    MqttSubscribePayload payload = new MqttSubscribePayload(Lists.newArrayList(topicSubscriptions));

    return new MqttSubscribeMessage(fixedHeader, variableHeader, payload);
}
项目:lannister    文件:MqttMessageFactory.java   
public static MqttSubAckMessage suback(int messageId, List<Integer> grantedQoSLevels) {
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false,
            2 + grantedQoSLevels.size());
    MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);
    MqttSubAckPayload payload = new MqttSubAckPayload(grantedQoSLevels);

    return new MqttSubAckMessage(fixedHeader, variableHeader, payload);
}
项目:lannister    文件:MqttMessageFactory.java   
public static MqttUnsubAckMessage unsuback(int messageId) {
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.UNSUBACK, false, MqttQoS.AT_MOST_ONCE, false,
            2);
    MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);

    return new MqttUnsubAckMessage(fixedHeader, variableHeader);
}
项目:lannister    文件:MqttPacketReceiver.java   
@Override
protected void channelRead0(ChannelHandlerContext ctx, MqttMessage msg) throws Exception {
    switch (msg.fixedHeader().messageType()) {
    case PUBLISH:
        if (receiver != null) {
            receiver.messageReceived(Message.newMessage(client.clientId(), (MqttPublishMessage) msg));
        }

        int messageId = ((MqttPublishMessage) msg).variableHeader().messageId();
        if (((MqttPublishMessage) msg).fixedHeader().qosLevel() == MqttQoS.AT_LEAST_ONCE) {
            client.send(MqttMessageFactory.puback(messageId));
        }
        else if (((MqttPublishMessage) msg).fixedHeader().qosLevel() == MqttQoS.EXACTLY_ONCE) {
            client.send(MqttMessageFactory.pubrec(messageId));
        }
        break;

    case CONNACK:
        sharedObject.receivedMessage(msg);

        synchronized (sharedObject.locker()) {
            sharedObject.locker().notify();
        }
        break;

    case PUBREC:
        client.send(MqttMessageFactory.pubrel(((MqttMessageIdVariableHeader) msg.variableHeader()).messageId()));
        break;

    case SUBACK:
    case PUBACK:
    case PUBCOMP:
    default:
        break;
    }
}
项目:vertx-mqtt    文件:MqttClientImpl.java   
/**
 * Sends PUBREC packet to server
 *
 * @param publishMessage a PUBLISH message to acknowledge
 */
void publishReceived(MqttPublishMessage publishMessage) {

  MqttFixedHeader fixedHeader =
    new MqttFixedHeader(MqttMessageType.PUBREC, false, AT_MOST_ONCE, false, 0);

  MqttMessageIdVariableHeader variableHeader =
    MqttMessageIdVariableHeader.from(publishMessage.messageId());

  io.netty.handler.codec.mqtt.MqttMessage pubrec = MqttMessageFactory.newMessage(fixedHeader, variableHeader, null);

  qos2inbound.put(publishMessage.messageId(), publishMessage);
  this.write(pubrec);
}
项目:vertx-mqtt    文件:MqttClientImpl.java   
/**
 * Sends the PUBREL message to server
 *
 * @param publishMessageId  identifier of the PUBLISH message to acknowledge
 */
void publishRelease(int publishMessageId) {

  MqttFixedHeader fixedHeader =
    new MqttFixedHeader(MqttMessageType.PUBREL, false, MqttQoS.AT_LEAST_ONCE, false, 0);

  MqttMessageIdVariableHeader variableHeader =
    MqttMessageIdVariableHeader.from(publishMessageId);

  io.netty.handler.codec.mqtt.MqttMessage pubrel = MqttMessageFactory.newMessage(fixedHeader, variableHeader, null);

  qos2outbound.put(publishMessageId, pubrel);
  this.write(pubrel);
}
项目:activemq-artemis    文件:MQTTProtocolHandler.java   
void sendPublishProtocolControlMessage(int messageId, MqttMessageType messageType) {
   MqttQoS qos = (messageType == MqttMessageType.PUBREL) ? MqttQoS.AT_LEAST_ONCE : MqttQoS.AT_MOST_ONCE;
   MqttFixedHeader fixedHeader = new MqttFixedHeader(messageType, false, qos, // Spec requires 01 in header for rel
                                                     false, 0);
   MqttPubAckMessage rel = new MqttPubAckMessage(fixedHeader, MqttMessageIdVariableHeader.from(messageId));
   sendToClient(rel);
}
项目:iothub    文件:MqttTransportHandler.java   
private MqttMessage createUnSubAckMessage(int msgId) {
  MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(UNSUBACK, false, AT_LEAST_ONCE, false, 0);
  MqttMessageIdVariableHeader mqttMessageIdVariableHeader = MqttMessageIdVariableHeader.from(msgId);
  return new MqttMessage(mqttFixedHeader, mqttMessageIdVariableHeader);
}
项目:iothub    文件:MqttTransportHandler.java   
private static MqttSubAckMessage createSubAckMessage(Integer msgId, List<Integer> grantedQoSList) {
  MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(SUBACK, false, AT_LEAST_ONCE, false, 0);
  MqttMessageIdVariableHeader mqttMessageIdVariableHeader = MqttMessageIdVariableHeader.from(msgId);
  MqttSubAckPayload mqttSubAckPayload = new MqttSubAckPayload(grantedQoSList);
  return new MqttSubAckMessage(mqttFixedHeader, mqttMessageIdVariableHeader, mqttSubAckPayload);
}
项目:iothub    文件:MqttTransportHandler.java   
public static MqttPubAckMessage createMqttPubAckMsg(int requestId) {
  MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(PUBACK, false, AT_LEAST_ONCE, false, 0);
  MqttMessageIdVariableHeader mqttMsgIdVariableHeader = MqttMessageIdVariableHeader.from(requestId);
  return new MqttPubAckMessage(mqttFixedHeader, mqttMsgIdVariableHeader);
}
项目:iotplatform    文件:MqttTransportHandler.java   
private MqttMessage createUnSubAckMessage(int msgId) {
  MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(UNSUBACK, false, AT_LEAST_ONCE, false, 0);
  MqttMessageIdVariableHeader mqttMessageIdVariableHeader = MqttMessageIdVariableHeader.from(msgId);
  return new MqttMessage(mqttFixedHeader, mqttMessageIdVariableHeader);
}
项目:iotplatform    文件:MqttTransportHandler.java   
private static MqttSubAckMessage createSubAckMessage(Integer msgId, List<Integer> grantedQoSList) {
  MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(SUBACK, false, AT_LEAST_ONCE, false, 0);
  MqttMessageIdVariableHeader mqttMessageIdVariableHeader = MqttMessageIdVariableHeader.from(msgId);
  MqttSubAckPayload mqttSubAckPayload = new MqttSubAckPayload(grantedQoSList);
  return new MqttSubAckMessage(mqttFixedHeader, mqttMessageIdVariableHeader, mqttSubAckPayload);
}
项目:iotplatform    文件:MqttTransportHandler.java   
public static MqttPubAckMessage createMqttPubAckMsg(int requestId) {
  MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(PUBACK, false, AT_LEAST_ONCE, false, 0);
  MqttMessageIdVariableHeader mqttMsgIdVariableHeader = MqttMessageIdVariableHeader.from(requestId);
  return new MqttPubAckMessage(mqttFixedHeader, mqttMsgIdVariableHeader);
}
项目:iotplatform    文件:JsonMqttAdaptor.java   
private static MqttPubAckMessage createMqttPubAckMsg(int requestId) {
  MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(PUBACK, false, AT_LEAST_ONCE, false, 0);
  MqttMessageIdVariableHeader mqttMsgIdVariableHeader = MqttMessageIdVariableHeader.from(requestId);
  return new MqttPubAckMessage(mqttFixedHeader, mqttMsgIdVariableHeader);
}
项目:vertx-mqtt    文件:MqttEndpointImpl.java   
public MqttEndpointImpl subscribeAcknowledge(int subscribeMessageId, List<MqttQoS> grantedQoSLevels) {

    this.checkConnected();

    MqttFixedHeader fixedHeader =
      new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
    MqttMessageIdVariableHeader variableHeader =
      MqttMessageIdVariableHeader.from(subscribeMessageId);

    MqttSubAckPayload payload = new MqttSubAckPayload(grantedQoSLevels.stream().mapToInt(MqttQoS::value).toArray());

    io.netty.handler.codec.mqtt.MqttMessage suback = MqttMessageFactory.newMessage(fixedHeader, variableHeader, payload);

    this.write(suback);

    return this;
  }
项目:activemq-artemis    文件:MQTTProtocolHandler.java   
private int getMessageId(MqttMessage message) {
   return ((MqttMessageIdVariableHeader) message.variableHeader()).messageId();
}
项目:moquette    文件:Utils.java   
public static int messageId(MqttMessage msg) {
    return ((MqttMessageIdVariableHeader) msg.variableHeader()).messageId();
}
项目:vertx-mqtt    文件:MqttClientImpl.java   
/**
 * Sends PUBACK packet to server
 *
 * @param publishMessageId identifier of the PUBLISH message to acknowledge
 */
void publishAcknowledge(int publishMessageId) {

  MqttFixedHeader fixedHeader =
    new MqttFixedHeader(MqttMessageType.PUBACK, false, AT_MOST_ONCE, false, 0);

  MqttMessageIdVariableHeader variableHeader =
    MqttMessageIdVariableHeader.from(publishMessageId);

  io.netty.handler.codec.mqtt.MqttMessage puback = MqttMessageFactory.newMessage(fixedHeader, variableHeader, null);

  this.write(puback);
}
项目:vertx-mqtt    文件:MqttClientImpl.java   
/**
 * Sends PUBCOMP packet to server
 *
 * @param publishMessageId identifier of the PUBLISH message to acknowledge
 */
void publishComplete(int publishMessageId) {

  MqttFixedHeader fixedHeader =
    new MqttFixedHeader(MqttMessageType.PUBCOMP, false, AT_MOST_ONCE, false, 0);

  MqttMessageIdVariableHeader variableHeader =
    MqttMessageIdVariableHeader.from(publishMessageId);

  io.netty.handler.codec.mqtt.MqttMessage pubcomp = MqttMessageFactory.newMessage(fixedHeader, variableHeader, null);

  this.write(pubcomp);
}
项目:vertx-mqtt    文件:MqttEndpointImpl.java   
public MqttEndpointImpl unsubscribeAcknowledge(int unsubscribeMessageId) {

    this.checkConnected();

    MqttFixedHeader fixedHeader =
      new MqttFixedHeader(MqttMessageType.UNSUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
    MqttMessageIdVariableHeader variableHeader =
      MqttMessageIdVariableHeader.from(unsubscribeMessageId);

    io.netty.handler.codec.mqtt.MqttMessage unsuback = MqttMessageFactory.newMessage(fixedHeader, variableHeader, null);

    this.write(unsuback);

    return this;
  }
项目:vertx-mqtt    文件:MqttEndpointImpl.java   
public MqttEndpointImpl publishAcknowledge(int publishMessageId) {

    this.checkConnected();

    MqttFixedHeader fixedHeader =
      new MqttFixedHeader(MqttMessageType.PUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
    MqttMessageIdVariableHeader variableHeader =
      MqttMessageIdVariableHeader.from(publishMessageId);

    io.netty.handler.codec.mqtt.MqttMessage puback = MqttMessageFactory.newMessage(fixedHeader, variableHeader, null);

    this.write(puback);

    return this;
  }
项目:vertx-mqtt    文件:MqttEndpointImpl.java   
public MqttEndpointImpl publishReceived(int publishMessageId) {

    this.checkConnected();

    MqttFixedHeader fixedHeader =
      new MqttFixedHeader(MqttMessageType.PUBREC, false, MqttQoS.AT_MOST_ONCE, false, 0);
    MqttMessageIdVariableHeader variableHeader =
      MqttMessageIdVariableHeader.from(publishMessageId);

    io.netty.handler.codec.mqtt.MqttMessage pubrec = MqttMessageFactory.newMessage(fixedHeader, variableHeader, null);

    this.write(pubrec);

    return this;
  }
项目:vertx-mqtt    文件:MqttEndpointImpl.java   
public MqttEndpointImpl publishRelease(int publishMessageId) {

    this.checkConnected();

    MqttFixedHeader fixedHeader =
      new MqttFixedHeader(MqttMessageType.PUBREL, false, MqttQoS.AT_LEAST_ONCE, false, 0);
    MqttMessageIdVariableHeader variableHeader =
      MqttMessageIdVariableHeader.from(publishMessageId);

    io.netty.handler.codec.mqtt.MqttMessage pubrel = MqttMessageFactory.newMessage(fixedHeader, variableHeader, null);

    this.write(pubrel);

    return this;
  }
项目:vertx-mqtt    文件:MqttEndpointImpl.java   
public MqttEndpointImpl publishComplete(int publishMessageId) {

    this.checkConnected();

    MqttFixedHeader fixedHeader =
      new MqttFixedHeader(MqttMessageType.PUBCOMP, false, MqttQoS.AT_MOST_ONCE, false, 0);
    MqttMessageIdVariableHeader variableHeader =
      MqttMessageIdVariableHeader.from(publishMessageId);

    io.netty.handler.codec.mqtt.MqttMessage pubcomp = MqttMessageFactory.newMessage(fixedHeader, variableHeader, null);

    this.write(pubcomp);

    return this;
  }