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

项目:j1st-mqtt    文件:Converter.java   
/**
 * Convert Map to InternalMessage
 *
 * @param map Map
 * @return InternalMessage
 */
public static InternalMessage mapToInternal(Map<String, String> map) {
    if (map == null || map.isEmpty()) return null;

    int type = Integer.parseInt(map.get("type"));
    if (type == MqttMessageType.PUBLISH.value()) {
        byte[] payload = null;
        if (map.get("payload") != null) try {
            payload = map.get("payload").getBytes("ISO-8859-1");
        } catch (UnsupportedEncodingException ignore) {
        }
        return new InternalMessage<>(
                MqttMessageType.PUBLISH,
                BooleanUtils.toBoolean(map.getOrDefault("dup", "0"), "1", "0"),
                MqttQoS.valueOf(Integer.parseInt(map.getOrDefault("qos", "0"))),
                BooleanUtils.toBoolean(map.getOrDefault("retain", "0"), "1", "0"),
                MqttVersion.valueOf(map.getOrDefault("version", MqttVersion.MQTT_3_1_1.toString())),
                map.get("clientId"),
                map.get("userName"),
                null,
                new Publish(
                        map.get("topicName"),
                        Integer.parseInt(map.getOrDefault("packetId", "0")),
                        payload
                ));
    } else if (type == MqttMessageType.PUBREL.value()) {
        return new InternalMessage<>(
                MqttMessageType.PUBREL,
                false,
                MqttQoS.AT_LEAST_ONCE,
                false,
                MqttVersion.valueOf(map.getOrDefault("version", MqttVersion.MQTT_3_1_1.toString())),
                map.get("clientId"),
                map.get("userName"),
                null,
                new PacketId(Integer.parseInt(map.getOrDefault("packetId", "0"))));
    } else {
        throw new IllegalArgumentException("Invalid in-flight MQTT message type: " + MqttMessageType.valueOf(type));
    }
}
项目:lannister    文件:ConnectOptions.java   
public ConnectOptions() {
    this.version = MqttVersion.MQTT_3_1_1;
    this.clientId = null;
    this.cleanSession = true;
    this.will = null;
    this.userName = null;
    this.password = null;
    this.keepAliveTimeSeconds = 120;
}
项目:lannister    文件:ConnectOptions.java   
public ConnectOptions(MqttVersion version, String clientId, boolean cleanSession, Message will, String userName,
        String password, int keepAliveTimeSeconds) {
    this.version = version;
    this.clientId = clientId;
    this.cleanSession = cleanSession;
    this.will = will;
    this.userName = userName;
    this.password = password;
    this.keepAliveTimeSeconds = keepAliveTimeSeconds;
}
项目:mithqtt    文件:MqttAdditionalHeader.java   
public MqttAdditionalHeader(
        MqttVersion version,
        String clientId,
        String userName,
        String brokerId) {
    this.version = version;
    this.clientId = clientId;
    this.userName = userName;
    this.brokerId = brokerId;
}
项目:j1st-mqtt    文件:MqttUnsubscribeResource.java   
@PermitAll
@POST
/**
 * Handle MQTT Un-Subscribe Request in RESTful style
 */
public ResultEntity<Boolean> unsubscribe(@PathParam("clientId") String clientId, @Auth UserPrincipal user, @QueryParam("protocol") @DefaultValue("4") byte protocol,
                                         @QueryParam("packetId") @DefaultValue("0") int packetId,
                                         List<String> topics) {
    String userName = user.getName();
    MqttVersion version = MqttVersion.fromProtocolLevel(protocol);

    // HTTP interface require valid Client Id
    if (!this.validator.isClientIdValid(clientId)) {
        logger.debug("Protocol violation: Client id {} not valid based on configuration", clientId);
        throw new ValidateException(new ErrorEntity(ErrorCode.INVALID));
    }

    // Validate Topic Filter based on configuration
    for (String topic : topics) {
        if (!this.validator.isTopicFilterValid(topic)) {
            logger.debug("Protocol violation: Client {} un-subscription {} is not valid based on configuration", clientId, topic);
            throw new ValidateException(new ErrorEntity(ErrorCode.INVALID));
        }
    }

    logger.debug("Message received: Received UNSUBSCRIBE message from client {} user {} topics {}", clientId, userName, ArrayUtils.toString(topics));

    // The Topic Filters (whether they contain wildcards or not) supplied in an UNSUBSCRIBE packet MUST be
    // compared character-by-character with the current set of Topic Filters held by the Server for the Client. If
    // any filter matches exactly then its owning Subscription is deleted, otherwise no additional processing
    // occurs
    // If a Server deletes a Subscription:
    // It MUST stop adding any new messages for delivery to the Client.
    //1 It MUST complete the delivery of any QoS 1 or QoS 2 messages which it has started to send to
    // the Client.
    // It MAY continue to deliver any existing messages buffered for delivery to the Client.
    topics.forEach(topic -> {
        logger.trace("Remove subscription: Remove client {} subscription with topic {}", clientId, topic);
        this.redis.removeSubscription(clientId, Topics.sanitize(topic));
    });

    // Pass message to 3rd party application
    Unsubscribe us = new Unsubscribe(packetId, topics);
    InternalMessage<Unsubscribe> m = new InternalMessage<>(MqttMessageType.UNSUBSCRIBE, false, MqttQoS.AT_LEAST_ONCE, false, version, clientId, null, null, us);
    this.communicator.sendToApplication(m);

    return new ResultEntity<>(true);
}
项目:lannister    文件:ConnectOptions.java   
public MqttVersion version() {
    return version;
}
项目:mithqtt    文件:MqttAdditionalHeader.java   
public MqttVersion version() {
    return version;
}