Search in sources :

Example 1 with Subscription

use of com.swiftmq.impl.mqtt.pubsub.Subscription in project swiftmq-ce by iitsoftware.

the class MQTTSession method destroy.

public void destroy(boolean removeUsage) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", destroy ...");
    for (Iterator<Map.Entry<String, Subscription>> iter = subscriptions.entrySet().iterator(); iter.hasNext(); ) {
        Subscription subscription = iter.next().getValue();
        subscription.close();
    }
    subscriptions.clear();
    try {
        if (removeUsage && persistent)
            ctx.sessionStore.remove(clientId);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", destroy done");
}
Also used : SubscriptionStoreEntry(com.swiftmq.impl.mqtt.pubsub.SubscriptionStoreEntry) Subscription(com.swiftmq.impl.mqtt.pubsub.Subscription) EntityAddException(com.swiftmq.mgmt.EntityAddException) QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException)

Example 2 with Subscription

use of com.swiftmq.impl.mqtt.pubsub.Subscription in project swiftmq-ce by iitsoftware.

the class MQTTSession method destroy.

public void destroy(ActiveLogin activeLogin, boolean removeUsage) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", destroy ...");
    for (Iterator<Map.Entry<String, Subscription>> iter = subscriptions.entrySet().iterator(); iter.hasNext(); ) {
        Subscription subscription = iter.next().getValue();
        subscription.close(activeLogin);
    }
    subscriptions.clear();
    try {
        if (removeUsage && persistent)
            ctx.sessionStore.remove(clientId);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", destroy done");
}
Also used : SubscriptionStoreEntry(com.swiftmq.impl.mqtt.pubsub.SubscriptionStoreEntry) Subscription(com.swiftmq.impl.mqtt.pubsub.Subscription) EntityAddException(com.swiftmq.mgmt.EntityAddException) QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException)

Example 3 with Subscription

use of com.swiftmq.impl.mqtt.pubsub.Subscription in project swiftmq-ce by iitsoftware.

the class MQTTSession method unsubscribe.

public void unsubscribe(String topicFilter, ActiveLogin activeLogin) throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", unsubscribe: " + topicFilter);
    Subscription subscription = subscriptions.remove(topicFilter);
    if (subscription != null) {
        subscription.close(activeLogin);
    }
    if (persistent) {
        ctx.sessionStore.remove(clientId);
        ctx.sessionStore.add(clientId, this);
    }
}
Also used : Subscription(com.swiftmq.impl.mqtt.pubsub.Subscription)

Example 4 with Subscription

use of com.swiftmq.impl.mqtt.pubsub.Subscription in project swiftmq-ce by iitsoftware.

the class MQTTSession method subscribe.

private int subscribe(MqttTopicSubscription subscription) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", subscribe: " + subscription.topicName());
    try {
        Subscription sub = subscriptions.remove(subscription.topicName());
        if (sub != null) {
            sub.stop();
            sub.close();
            if (registryUsage != null) {
                registryUsage.getEntity("subscriptions").removeEntity(registryUsage.getEntity("subscriptions").getEntity(sub.getTopicName()));
            }
            if (connectionUsage != null) {
                connectionUsage.getEntity("subscriptions").removeEntity(connectionUsage.getEntity("subscriptions").getEntity(sub.getTopicName()));
            }
        }
        String topicNameTranslated = topicFilterTranslate(subscription.topicName());
        sub = new Subscription(ctx, this, subscription.topicName(), topicNameTranslated, subscription.qualityOfService());
        subscriptions.put(subscription.topicName(), sub);
        sub.start();
        if (persistent) {
            ctx.sessionStore.remove(clientId);
            ctx.sessionStore.add(clientId, this);
            createRegistryUsage(sub);
        }
        if (connectionUsage != null)
            createConnectionUsage(sub);
        return subscription.qualityOfService().value();
    } catch (Exception e) {
        ctx.logSwiftlet.logError(ctx.mqttSwiftlet.getName(), toString() + "/Subscribe exception: " + e.getMessage());
        return MqttQoS.FAILURE.value();
    }
}
Also used : Subscription(com.swiftmq.impl.mqtt.pubsub.Subscription) EntityAddException(com.swiftmq.mgmt.EntityAddException) QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException)

Example 5 with Subscription

use of com.swiftmq.impl.mqtt.pubsub.Subscription in project swiftmq-ce by iitsoftware.

the class MQTTSession method stop.

public void stop() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", stop ...");
    for (Iterator<Map.Entry<String, Subscription>> iter = subscriptions.entrySet().iterator(); iter.hasNext(); ) {
        Subscription subscription = iter.next().getValue();
        subscription.stop();
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", stop done");
}
Also used : SubscriptionStoreEntry(com.swiftmq.impl.mqtt.pubsub.SubscriptionStoreEntry) Subscription(com.swiftmq.impl.mqtt.pubsub.Subscription)

Aggregations

Subscription (com.swiftmq.impl.mqtt.pubsub.Subscription)9 SubscriptionStoreEntry (com.swiftmq.impl.mqtt.pubsub.SubscriptionStoreEntry)6 EntityAddException (com.swiftmq.mgmt.EntityAddException)6 QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)6 Property (com.swiftmq.mgmt.Property)1