|
|
|
@ -282,7 +282,6 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer |
|
|
|
if (sessionSubscriptions != null) { |
|
|
|
TbSubscription<?> subscription = sessionSubscriptions.remove(subscriptionId); |
|
|
|
if (subscription != null) { |
|
|
|
|
|
|
|
if (sessionSubscriptions.isEmpty()) { |
|
|
|
subscriptionsBySessionId.remove(sessionId); |
|
|
|
} |
|
|
|
@ -304,22 +303,26 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer |
|
|
|
@Override |
|
|
|
public void cancelAllSessionSubscriptions(TenantId tenantId, String sessionId) { |
|
|
|
log.debug("[{}][{}] Going to remove session subscriptions.", tenantId, sessionId); |
|
|
|
List<SubscriptionModificationResult> results = new ArrayList<>(); |
|
|
|
Lock subsLock = getSubsLock(tenantId); |
|
|
|
subsLock.lock(); |
|
|
|
try { |
|
|
|
Map<Integer, TbSubscription<?>> sessionSubscriptions = subscriptionsBySessionId.remove(sessionId); |
|
|
|
if (sessionSubscriptions != null) { |
|
|
|
for (TbSubscription<?> subscription : sessionSubscriptions.values()) { |
|
|
|
results.add(modifySubscription(tenantId, subscription.getEntityId(), subscription, false)); |
|
|
|
} |
|
|
|
Map<EntityId, List<TbSubscription<?>>> entitySubscriptions = |
|
|
|
sessionSubscriptions.values().stream().collect(Collectors.groupingBy(TbSubscription::getEntityId)); |
|
|
|
|
|
|
|
entitySubscriptions.forEach((entityId, subscriptions) -> { |
|
|
|
TbEntitySubEvent event = removeAllSubscriptions(tenantId, entityId, subscriptions); |
|
|
|
if (event != null) { |
|
|
|
pushSubscriptionsEvent(tenantId, entityId, event); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
log.debug("[{}][{}] No session subscriptions found!", tenantId, sessionId); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
subsLock.unlock(); |
|
|
|
} |
|
|
|
results.stream().filter(SubscriptionModificationResult::hasEvent).forEach(this::pushSubscriptionEvent); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -500,6 +503,30 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer |
|
|
|
return new SubscriptionModificationResult(tenantId, entityId, subscription, missedUpdatesCandidate, event); |
|
|
|
} |
|
|
|
|
|
|
|
private TbEntitySubEvent removeAllSubscriptions(TenantId tenantId, EntityId entityId, List<TbSubscription<?>> subscriptions) { |
|
|
|
TbEntitySubEvent event = null; |
|
|
|
try { |
|
|
|
TbEntityLocalSubsInfo entitySubs = subscriptionsByEntityId.get(entityId.getId()); |
|
|
|
event = entitySubs.removeAll(subscriptions); |
|
|
|
if (entitySubs.isEmpty()) { |
|
|
|
subscriptionsByEntityId.remove(entityId.getId()); |
|
|
|
entityUpdates.remove(entityId.getId()); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("[{}][{}] Failed to remove all subscriptions {} due to ", tenantId, entityId, subscriptions, e); |
|
|
|
} |
|
|
|
return event; |
|
|
|
} |
|
|
|
|
|
|
|
private void pushSubscriptionsEvent(TenantId tenantId, EntityId entityId, TbEntitySubEvent event) { |
|
|
|
try { |
|
|
|
log.trace("[{}][{}] Event: {}", tenantId, entityId, event); |
|
|
|
pushSubEventToManagerService(tenantId, entityId, event); |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("[{}][{}] Failed to push subscription event {} due to ", tenantId, entityId, event, e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void pushSubscriptionEvent(SubscriptionModificationResult modificationResult) { |
|
|
|
try { |
|
|
|
TbEntitySubEvent event = modificationResult.getEvent(); |
|
|
|
|