Add sequenceNumber to notification subscription updates

This commit is contained in:
ViacheslavKlimov 2023-12-06 17:21:44 +02:00
parent fb92aef8cb
commit e52782ee0e
5 changed files with 15 additions and 2 deletions

View File

@ -21,6 +21,7 @@ import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@Data @Data
@ -35,6 +36,8 @@ public abstract class TbSubscription<T> {
private final TbSubscriptionType type; private final TbSubscriptionType type;
private final BiConsumer<TbSubscription<T>, T> updateProcessor; private final BiConsumer<TbSubscription<T>, T> updateProcessor;
protected final AtomicInteger sequence = new AtomicInteger();
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -28,14 +28,17 @@ import org.thingsboard.server.service.ws.telemetry.cmd.v2.CmdUpdateType;
public class UnreadNotificationsCountUpdate extends CmdUpdate { public class UnreadNotificationsCountUpdate extends CmdUpdate {
private final int totalUnreadCount; private final int totalUnreadCount;
private final int sequenceNumber;
@Builder @Builder
@JsonCreator @JsonCreator
public UnreadNotificationsCountUpdate(@JsonProperty("cmdId") int cmdId, @JsonProperty("errorCode") int errorCode, public UnreadNotificationsCountUpdate(@JsonProperty("cmdId") int cmdId, @JsonProperty("errorCode") int errorCode,
@JsonProperty("errorMsg") String errorMsg, @JsonProperty("errorMsg") String errorMsg,
@JsonProperty("totalUnreadCount") int totalUnreadCount) { @JsonProperty("totalUnreadCount") int totalUnreadCount,
@JsonProperty("sequenceNumber") int sequenceNumber) {
super(cmdId, errorCode, errorMsg); super(cmdId, errorCode, errorMsg);
this.totalUnreadCount = totalUnreadCount; this.totalUnreadCount = totalUnreadCount;
this.sequenceNumber = sequenceNumber;
} }
@Override @Override

View File

@ -33,6 +33,7 @@ public class UnreadNotificationsUpdate extends CmdUpdate {
private final Collection<Notification> notifications; private final Collection<Notification> notifications;
private final Notification update; private final Notification update;
private final int totalUnreadCount; private final int totalUnreadCount;
private final int sequenceNumber;
@Builder @Builder
@JsonCreator @JsonCreator
@ -40,11 +41,13 @@ public class UnreadNotificationsUpdate extends CmdUpdate {
@JsonProperty("errorMsg") String errorMsg, @JsonProperty("errorMsg") String errorMsg,
@JsonProperty("notifications") Collection<Notification> notifications, @JsonProperty("notifications") Collection<Notification> notifications,
@JsonProperty("update") Notification update, @JsonProperty("update") Notification update,
@JsonProperty("totalUnreadCount") int totalUnreadCount) { @JsonProperty("totalUnreadCount") int totalUnreadCount,
@JsonProperty("sequenceNumber") int sequenceNumber) {
super(cmdId, errorCode, errorMsg); super(cmdId, errorCode, errorMsg);
this.notifications = notifications; this.notifications = notifications;
this.update = update; this.update = update;
this.totalUnreadCount = totalUnreadCount; this.totalUnreadCount = totalUnreadCount;
this.sequenceNumber = sequenceNumber;
} }
@Override @Override

View File

@ -41,6 +41,7 @@ public class NotificationsCountSubscription extends TbSubscription<Notifications
return UnreadNotificationsCountUpdate.builder() return UnreadNotificationsCountUpdate.builder()
.cmdId(getSubscriptionId()) .cmdId(getSubscriptionId())
.totalUnreadCount(unreadCounter.get()) .totalUnreadCount(unreadCounter.get())
.sequenceNumber(sequence.incrementAndGet())
.build(); .build();
} }

View File

@ -54,6 +54,7 @@ public class NotificationsSubscription extends TbSubscription<NotificationsSubsc
.cmdId(getSubscriptionId()) .cmdId(getSubscriptionId())
.notifications(getSortedNotifications()) .notifications(getSortedNotifications())
.totalUnreadCount(totalUnreadCounter.get()) .totalUnreadCount(totalUnreadCounter.get())
.sequenceNumber(sequence.incrementAndGet())
.build(); .build();
} }
@ -68,6 +69,7 @@ public class NotificationsSubscription extends TbSubscription<NotificationsSubsc
.cmdId(getSubscriptionId()) .cmdId(getSubscriptionId())
.update(notification) .update(notification)
.totalUnreadCount(totalUnreadCounter.get()) .totalUnreadCount(totalUnreadCounter.get())
.sequenceNumber(sequence.incrementAndGet())
.build(); .build();
} }
@ -75,6 +77,7 @@ public class NotificationsSubscription extends TbSubscription<NotificationsSubsc
return UnreadNotificationsUpdate.builder() return UnreadNotificationsUpdate.builder()
.cmdId(getSubscriptionId()) .cmdId(getSubscriptionId())
.totalUnreadCount(totalUnreadCounter.get()) .totalUnreadCount(totalUnreadCounter.get())
.sequenceNumber(sequence.incrementAndGet())
.build(); .build();
} }