Package org.fusesource.mqtt.client

Examples of org.fusesource.mqtt.client.QoS


    private void restoreDurableSubs(List<SubscriptionInfo> subs) {
        try {
            for (SubscriptionInfo sub : subs) {
                String name = sub.getSubcriptionName();
                String[] split = name.split(":", 2);
                QoS qoS = QoS.valueOf(split[0]);
                onSubscribe(new Topic(split[1], qoS));
                // mark this durable subscription as restored by Broker
                restoredSubs.add(split[1]);
            }
        } catch (IOException e) {
View Full Code Here


    }

    public PUBLISH convertMessage(ActiveMQMessage message) throws IOException, JMSException, DataFormatException {
        PUBLISH result = new PUBLISH();
        // packet id is set in MQTTSubscription
        QoS qoS;
        if (message.propertyExists(QOS_PROPERTY_NAME)) {
            int ordinal = message.getIntProperty(QOS_PROPERTY_NAME);
            qoS = QoS.values()[ordinal];

        } else {
View Full Code Here

        }
        return 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);
    }
View Full Code Here

    public void restoreDurableSubs(List<SubscriptionInfo> subs) {
        try {
            for (SubscriptionInfo sub : subs) {
                String name = sub.getSubcriptionName();
                String[] split = name.split(":", 2);
                QoS qoS = QoS.valueOf(split[0]);
                onSubscribe(new Topic(split[1], qoS));
                // mark this durable subscription as restored by Broker
                restoredSubs.add(split[1]);
            }
        } catch (IOException e) {
View Full Code Here

    }

    byte onSubscribe(final Topic topic) throws MQTTProtocolException {

        final UTF8Buffer topicName = topic.name();
        final QoS topicQoS = topic.qos();
        ActiveMQDestination destination = new ActiveMQTopic(convertMQTTToActiveMQ(topicName.toString()));

        if( mqttSubscriptionByTopic.containsKey(topicName)) {
            final MQTTSubscription mqttSubscription = mqttSubscriptionByTopic.get(topicName);
            if (topicQoS != mqttSubscription.qos()) {
                // remove old subscription as the QoS has changed
                onUnSubscribe(topicName);
            } else {
                // duplicate SUBSCRIBE packet, find all matching topics and resend retained messages
                resendRetainedMessages(topicName, destination, mqttSubscription);

                return (byte) topicQoS.ordinal();
            }
            onUnSubscribe(topicName);
        }

        ConsumerId id = new ConsumerId(sessionId, consumerIdGenerator.getNextSequenceId());
        ConsumerInfo consumerInfo = new ConsumerInfo(id);
        consumerInfo.setDestination(destination);
        consumerInfo.setPrefetchSize(getActiveMQSubscriptionPrefetch());
        consumerInfo.setRetroactive(true);
        consumerInfo.setDispatchAsync(true);
        // create durable subscriptions only when cleansession is false
        if ( !connect.cleanSession() && connect.clientId() != null && topicQoS.ordinal() >= QoS.AT_LEAST_ONCE.ordinal() ) {
            consumerInfo.setSubscriptionName(topicQoS + ":" + topicName.toString());
        }
        MQTTSubscription mqttSubscription = new MQTTSubscription(this, topicQoS, consumerInfo);

        // optimistic add to local maps first to be able to handle commands in onActiveMQCommand
        subscriptionsByConsumerId.put(id, mqttSubscription);
        mqttSubscriptionByTopic.put(topicName, mqttSubscription);

        final byte[] qos = {-1};
        sendToActiveMQ(consumerInfo, new ResponseHandler() {
            @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);
                    qos[0] = SUBSCRIBE_ERROR;
                } else {
                    qos[0] = (byte) topicQoS.ordinal();
                }
            }
        });

        if (qos[0] == SUBSCRIBE_ERROR) {
View Full Code Here

TOP

Related Classes of org.fusesource.mqtt.client.QoS

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.