private void parseSubscriptionCommands(NotificationClientSync nfSync, ByteBuffer buf, boolean add) { int count = getIntFromUnsignedShort(buf); if (nfSync.getSubscriptionCommands() == null) { nfSync.setSubscriptionCommands(new ArrayList<>()); } SubscriptionCommandType subscriptionType = add ? SubscriptionCommandType.ADD : SubscriptionCommandType.REMOVE; List<SubscriptionCommand> commands = new ArrayList<>(); for (int i = 0; i < count; i++) { long topicId = buf.getLong(); commands.add(new SubscriptionCommand(topicId, subscriptionType)); } nfSync.getSubscriptionCommands().addAll(commands); }
/** * Calculate different between requests. * * @param oldRequest old request * @param newRequest new request * @return difference */ private NotificationClientSync diff(NotificationClientSync oldRequest, NotificationClientSync newRequest) { if (oldRequest == null) { return newRequest; } else { if ((newRequest.getAcceptedUnicastNotifications() != null && newRequest.getAcceptedUnicastNotifications().size() > 0) || (newRequest.getSubscriptionCommands() != null && newRequest.getSubscriptionCommands().size() > 0) || (newRequest.getTopicListHash() != oldRequest.getTopicListHash())) { return newRequest; } else { return null; } } }
/** * Calculate notification delta. * * @param appToken application token * @param context context * @param syncRequest the sync request * @return the gets the notification response */ private GetNotificationResponse calculateNotificationDelta(String appToken, NotificationClientSync syncRequest, SyncContext context) { GetNotificationRequest request = new GetNotificationRequest( syncRequest.getTopicListHash(), context.getEndpointProfile(), syncRequest.getSubscriptionCommands(), syncRequest.getAcceptedUnicastNotifications(), syncRequest.getTopicStates()); return notificationDeltaService.getNotificationDelta(request); }