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");
}
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");
}
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);
}
}
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();
}
}
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");
}
Aggregations