Browse Source

revert changes that are not related to this PR

pull/11498/head
YevhenBondarenko 2 years ago
parent
commit
399c072595
  1. 2
      application/src/main/java/org/thingsboard/server/service/subscription/DefaultTbLocalSubscriptionService.java
  2. 8
      application/src/main/java/org/thingsboard/server/service/subscription/TbAlarmsSubscription.java
  3. 8
      application/src/main/java/org/thingsboard/server/service/subscription/TbAttributeSubscription.java
  4. 28
      application/src/main/java/org/thingsboard/server/service/subscription/TbEntityLocalSubsInfo.java
  5. 23
      application/src/main/java/org/thingsboard/server/service/subscription/TbSubscription.java
  6. 5
      application/src/main/java/org/thingsboard/server/service/subscription/TbSubscriptionUtils.java
  7. 7
      application/src/main/java/org/thingsboard/server/service/subscription/TbSubscriptionsInfo.java
  8. 8
      application/src/main/java/org/thingsboard/server/service/subscription/TbTimeSeriesSubscription.java
  9. 5
      application/src/main/java/org/thingsboard/server/service/ws/notification/sub/AbstractNotificationSubscription.java
  10. 5
      application/src/main/java/org/thingsboard/server/service/ws/notification/sub/NotificationsCountSubscription.java
  11. 5
      application/src/main/java/org/thingsboard/server/service/ws/notification/sub/NotificationsSubscription.java

2
application/src/main/java/org/thingsboard/server/service/subscription/DefaultTbLocalSubscriptionService.java

@ -227,7 +227,7 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer
onSubEventCallback(tenantId, entityId.getId(), seqNumber, entityUpdatesInfo, callback); onSubEventCallback(tenantId, entityId.getId(), seqNumber, entityUpdatesInfo, callback);
} }
public void onSubEventCallback(TenantId tenantId, UUID entityId, int seqNumber, TbEntityUpdatesInfo entityUpdatesInfo, TbCallback callback) { private void onSubEventCallback(TenantId tenantId, UUID entityId, int seqNumber, TbEntityUpdatesInfo entityUpdatesInfo, TbCallback callback) {
log.debug("[{}][{}][{}] Processing sub event callback: {}.", tenantId, entityId, seqNumber, entityUpdatesInfo); log.debug("[{}][{}][{}] Processing sub event callback: {}.", tenantId, entityId, seqNumber, entityUpdatesInfo);
entityUpdates.put(entityId, entityUpdatesInfo); entityUpdates.put(entityId, entityUpdatesInfo);
Set<TbSubscription<?>> pendingSubs = null; Set<TbSubscription<?>> pendingSubs = null;

8
application/src/main/java/org/thingsboard/server/service/subscription/TbAlarmsSubscription.java

@ -36,8 +36,12 @@ public class TbAlarmsSubscription extends TbSubscription<AlarmSubscriptionUpdate
} }
@Override @Override
public boolean canEqual(final Object other) { public boolean equals(Object o) {
return other instanceof TbAlarmsSubscription; return super.equals(o);
} }
@Override
public int hashCode() {
return super.hashCode();
}
} }

8
application/src/main/java/org/thingsboard/server/service/subscription/TbAttributeSubscription.java

@ -43,8 +43,12 @@ public class TbAttributeSubscription extends TbSubscription<TelemetrySubscriptio
} }
@Override @Override
protected boolean canEqual(final Object other) { public boolean equals(Object o) {
return other instanceof TbAttributeSubscription; return super.equals(o);
} }
@Override
public int hashCode() {
return super.hashCode();
}
} }

28
application/src/main/java/org/thingsboard/server/service/subscription/TbEntityLocalSubsInfo.java

@ -84,7 +84,6 @@ public class TbEntityLocalSubsInfo {
if (!newState.attrAllKeys) { if (!newState.attrAllKeys) {
if (attrSub.isAllKeys()) { if (attrSub.isAllKeys()) {
newState.attrAllKeys = true; newState.attrAllKeys = true;
newState.attrKeys = null;
stateChanged = true; stateChanged = true;
} else { } else {
if (newState.attrKeys == null) { if (newState.attrKeys == null) {
@ -101,7 +100,6 @@ public class TbEntityLocalSubsInfo {
if (!newState.tsAllKeys) { if (!newState.tsAllKeys) {
if (tsSub.isAllKeys()) { if (tsSub.isAllKeys()) {
newState.tsAllKeys = true; newState.tsAllKeys = true;
newState.tsKeys = null;
stateChanged = true; stateChanged = true;
} else { } else {
if (newState.tsKeys == null) { if (newState.tsKeys == null) {
@ -135,30 +133,8 @@ public class TbEntityLocalSubsInfo {
return toEvent(ComponentLifecycleEvent.DELETED); return toEvent(ComponentLifecycleEvent.DELETED);
} }
TbSubscriptionsInfo oldState = state.copy(); TbSubscriptionsInfo oldState = state.copy();
TbSubscriptionsInfo newState = new TbSubscriptionsInfo();
//copy unchanged state only
TbSubscriptionsInfo newState = state.copy();
switch (sub.getType()) {
case NOTIFICATIONS:
case NOTIFICATIONS_COUNT:
newState.notifications = false;
break;
case ALARMS:
newState.alarms = false;
break;
case ATTRIBUTES:
newState.attrAllKeys = false;
newState.attrKeys = null;
break;
case TIMESERIES:
newState.tsAllKeys = false;
newState.tsKeys = null;
}
for (TbSubscription<?> subscription : subs) { for (TbSubscription<?> subscription : subs) {
if (subscription.getType() != sub.getType()) {
continue; // skip unchanged types
}
switch (subscription.getType()) { switch (subscription.getType()) {
case NOTIFICATIONS: case NOTIFICATIONS:
case NOTIFICATIONS_COUNT: case NOTIFICATIONS_COUNT:
@ -175,7 +151,6 @@ public class TbEntityLocalSubsInfo {
var attrSub = (TbAttributeSubscription) subscription; var attrSub = (TbAttributeSubscription) subscription;
if (!newState.attrAllKeys && attrSub.isAllKeys()) { if (!newState.attrAllKeys && attrSub.isAllKeys()) {
newState.attrAllKeys = true; newState.attrAllKeys = true;
newState.attrKeys = null;
continue; continue;
} }
if (newState.attrKeys == null) { if (newState.attrKeys == null) {
@ -188,7 +163,6 @@ public class TbEntityLocalSubsInfo {
var tsSub = (TbTimeSeriesSubscription) subscription; var tsSub = (TbTimeSeriesSubscription) subscription;
if (!newState.tsAllKeys && tsSub.isAllKeys()) { if (!newState.tsAllKeys && tsSub.isAllKeys()) {
newState.tsAllKeys = true; newState.tsAllKeys = true;
newState.tsKeys = null;
continue; continue;
} }
if (newState.tsKeys == null) { if (newState.tsKeys == null) {

23
application/src/main/java/org/thingsboard/server/service/subscription/TbSubscription.java

@ -15,25 +15,40 @@
*/ */
package org.thingsboard.server.service.subscription; package org.thingsboard.server.service.subscription;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.id.EntityId; 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.function.BiConsumer; import java.util.function.BiConsumer;
@Data @Data
@EqualsAndHashCode(cacheStrategy = EqualsAndHashCode.CacheStrategy.LAZY, doNotUseGetters = true) @AllArgsConstructor
public abstract class TbSubscription<T> { public abstract class TbSubscription<T> {
@EqualsAndHashCode.Exclude
private final String serviceId; private final String serviceId;
private final String sessionId; private final String sessionId;
private final int subscriptionId; private final int subscriptionId;
private final TenantId tenantId; private final TenantId tenantId;
private final EntityId entityId; private final EntityId entityId;
private final TbSubscriptionType type; private final TbSubscriptionType type;
@EqualsAndHashCode.Exclude
private final BiConsumer<TbSubscription<T>, T> updateProcessor; private final BiConsumer<TbSubscription<T>, T> updateProcessor;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TbSubscription that = (TbSubscription) o;
return subscriptionId == that.subscriptionId &&
sessionId.equals(that.sessionId) &&
tenantId.equals(that.tenantId) &&
entityId.equals(that.entityId) &&
type == that.type;
}
@Override
public int hashCode() {
return Objects.hash(sessionId, subscriptionId, tenantId, entityId, type);
}
} }

5
application/src/main/java/org/thingsboard/server/service/subscription/TbSubscriptionUtils.java

@ -109,9 +109,8 @@ public class TbSubscriptionUtils {
.type(event); .type(event);
if (!ComponentLifecycleEvent.DELETED.equals(event)) { if (!ComponentLifecycleEvent.DELETED.equals(event)) {
builder.info(new TbSubscriptionsInfo(proto.getNotifications(), proto.getAlarms(), builder.info(new TbSubscriptionsInfo(proto.getNotifications(), proto.getAlarms(),
proto.getTsAllKeys(), proto.getAttrAllKeys(), proto.getTsAllKeys(), proto.getTsKeysCount() > 0 ? new HashSet<>(proto.getTsKeysList()) : null,
proto.getTsKeysCount() > 0 ? new HashSet<>(proto.getTsKeysList()) : null, proto.getAttrAllKeys(), proto.getAttrKeysCount() > 0 ? new HashSet<>(proto.getAttrKeysList()) : null,
proto.getAttrKeysCount() > 0 ? new HashSet<>(proto.getAttrKeysList()) : null,
proto.getSeqNumber())); proto.getSeqNumber()));
} }
return builder.build(); return builder.build();

7
application/src/main/java/org/thingsboard/server/service/subscription/TbSubscriptionsInfo.java

@ -27,17 +27,16 @@ import java.util.Set;
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@EqualsAndHashCode @EqualsAndHashCode(exclude = {"seqNumber"})
@ToString @ToString
public class TbSubscriptionsInfo { public class TbSubscriptionsInfo {
protected boolean notifications; protected boolean notifications;
protected boolean alarms; protected boolean alarms;
protected boolean tsAllKeys; protected boolean tsAllKeys;
protected boolean attrAllKeys; // primitives first for equals performance
protected Set<String> tsKeys; protected Set<String> tsKeys;
protected boolean attrAllKeys;
protected Set<String> attrKeys; protected Set<String> attrKeys;
@EqualsAndHashCode.Exclude
protected int seqNumber; protected int seqNumber;
public boolean isEmpty() { public boolean isEmpty() {
@ -49,7 +48,7 @@ public class TbSubscriptionsInfo {
} }
protected TbSubscriptionsInfo copy(int seqNumber) { protected TbSubscriptionsInfo copy(int seqNumber) {
return new TbSubscriptionsInfo(notifications, alarms, tsAllKeys, attrAllKeys, tsKeys, attrKeys, seqNumber); return new TbSubscriptionsInfo(notifications, alarms, tsAllKeys, tsKeys, attrAllKeys, attrKeys, seqNumber);
} }
} }

8
application/src/main/java/org/thingsboard/server/service/subscription/TbTimeSeriesSubscription.java

@ -53,8 +53,12 @@ public class TbTimeSeriesSubscription extends TbSubscription<TelemetrySubscripti
} }
@Override @Override
protected boolean canEqual(final Object other) { public boolean equals(Object o) {
return other instanceof TbTimeSeriesSubscription; return super.equals(o);
} }
@Override
public int hashCode() {
return super.hashCode();
}
} }

5
application/src/main/java/org/thingsboard/server/service/ws/notification/sub/AbstractNotificationSubscription.java

@ -35,9 +35,4 @@ public abstract class AbstractNotificationSubscription<T> extends TbSubscription
super(serviceId, sessionId, subscriptionId, tenantId, entityId, type, updateProcessor); super(serviceId, sessionId, subscriptionId, tenantId, entityId, type, updateProcessor);
} }
@Override
protected boolean canEqual(final Object other) {
return other instanceof AbstractNotificationSubscription;
}
} }

5
application/src/main/java/org/thingsboard/server/service/ws/notification/sub/NotificationsCountSubscription.java

@ -34,11 +34,6 @@ public class NotificationsCountSubscription extends AbstractNotificationSubscrip
super(serviceId, sessionId, subscriptionId, tenantId, entityId, TbSubscriptionType.NOTIFICATIONS_COUNT, updateProcessor); super(serviceId, sessionId, subscriptionId, tenantId, entityId, TbSubscriptionType.NOTIFICATIONS_COUNT, updateProcessor);
} }
@Override
protected boolean canEqual(final Object other) {
return other instanceof NotificationsCountSubscription;
}
public UnreadNotificationsCountUpdate createUpdate() { public UnreadNotificationsCountUpdate createUpdate() {
return UnreadNotificationsCountUpdate.builder() return UnreadNotificationsCountUpdate.builder()
.cmdId(getSubscriptionId()) .cmdId(getSubscriptionId())

5
application/src/main/java/org/thingsboard/server/service/ws/notification/sub/NotificationsSubscription.java

@ -47,11 +47,6 @@ public class NotificationsSubscription extends AbstractNotificationSubscription<
this.limit = limit; this.limit = limit;
} }
@Override
protected boolean canEqual(final Object other) {
return other instanceof NotificationsSubscription;
}
public UnreadNotificationsUpdate createFullUpdate() { public UnreadNotificationsUpdate createFullUpdate() {
return UnreadNotificationsUpdate.builder() return UnreadNotificationsUpdate.builder()
.cmdId(getSubscriptionId()) .cmdId(getSubscriptionId())

Loading…
Cancel
Save