@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof NotificationEvent)) return false; if (!super.equals(o)) return false; NotificationEvent that = (NotificationEvent) o; return Objects.equals(notification, that.notification); }
@Override public int hashCode() { return Objects.hash(super.hashCode(), notification); }
public void publish(Event event) { event.getApplicableFilters() .stream() .flatMap(filter -> registry.getSubscribers(filter).stream()) .forEach(subscriber -> { Response response = Response.newBuilder() .withBody(event) .withCorrelationId(subscriber.getCorrelationId()) .withLast(false) .buildSuccess(); dispatcher.send(subscriber.getReplyTo(), response); }); }
requestResponseMatcher.addSubscription(subscriptionId, response.getCorrelationId()); } else if (!returnUpdated && resAction.equals(Action.COMMAND_EVENT)) { callback.accept(response.getBody().cast(CommandEvent.class).getCommand(), subscriptionId); } else if (returnUpdated && resAction.equals(Action.COMMANDS_UPDATE_EVENT)) { callback.accept(response.getBody().cast(CommandsUpdateEvent.class).getDeviceCommand(), subscriptionId); } else { logger.warn("Unknown action received from backend {}", resAction);
@Override public Response handle(Request request) { final DeviceCommand command = request.getBody().cast(CommandUpdateRequest.class).getDeviceCommand(); hazelcastService.store(command); eventBus.publish(new CommandUpdateEvent(command)); return Response.newBuilder().buildSuccess(); } }
@Override public Response handle(Request request) { final DeviceCommand command = request.getBody().cast(CommandsUpdateRequest.class).getDeviceCommand(); hazelcastService.store(command); eventBus.publish(new CommandsUpdateEvent(command)); return Response.newBuilder().buildSuccess(); } }
@Override public Response handle(Request request) { DeviceNotification notification = ((NotificationInsertRequest) request.getBody()).getDeviceNotification(); NotificationEvent notificationEvent = new NotificationEvent(notification); eventBus.publish(notificationEvent); hazelcastService.store(notification); NotificationInsertResponse payload = new NotificationInsertResponse(notification); return Response.newBuilder() .withBody(payload) .buildSuccess(); } }
@Override public Response handle(Request request) { DeviceCommand deviceCommand = request.getBody().cast(CommandInsertRequest.class).getDeviceCommand(); CommandEvent commandEvent = new CommandEvent(deviceCommand); eventBus.publish(commandEvent); hazelcastService.store(deviceCommand); CommandInsertResponse payload = new CommandInsertResponse(deviceCommand); return Response.newBuilder() .withBody(payload) .buildSuccess(); } }
} else if (resAction.equals(Action.NOTIFICATION_EVENT)) { NotificationEvent event = response.getBody().cast(NotificationEvent.class); callback.accept(event.getNotification(), subscriptionId); } else { logger.warn("Unknown action received from backend {}", resAction);
public CompletableFuture<Pair<Long, DeviceCommand>> sendSubscribeToUpdateRequest(final long commandId, final DeviceVO device, BiConsumer<DeviceCommand, Long> callback) { CompletableFuture<Pair<Long, DeviceCommand>> future = new CompletableFuture<>(); final Long subscriptionId = idGenerator.generate(); Consumer<Response> responseConsumer = response -> { Action resAction = response.getBody().getAction(); if (resAction.equals(Action.COMMAND_UPDATE_SUBSCRIBE_RESPONSE)) { future.complete(Pair.of(response.getBody().cast(CommandUpdateSubscribeResponse.class).getSubscriptionId(), response.getBody().cast(CommandUpdateSubscribeResponse.class).getDeviceCommand())); } else if (resAction.equals(COMMAND_UPDATE_EVENT)) { callback.accept(response.getBody().cast(CommandUpdateEvent.class).getDeviceCommand(), subscriptionId); } else { logger.warn("Unknown action received from backend {}", resAction); } }; Filter filter = new Filter(device.getNetworkId(), device.getDeviceTypeId(), Long.toString(commandId), COMMAND_UPDATE_EVENT.name(), null); rpcClient.call(Request.newBuilder() .withBody(new CommandUpdateSubscribeRequest(commandId, device.getDeviceId(), subscriptionId, filter)) .build(), responseConsumer); return future; }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof CommandEvent)) return false; if (!super.equals(o)) return false; CommandEvent that = (CommandEvent) o; return Objects.equals(command, that.command); }
@Override public int hashCode() { return Objects.hash(super.hashCode(), command); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof CommandsUpdateEvent)) return false; if (!super.equals(o)) return false; CommandsUpdateEvent that = (CommandsUpdateEvent) o; return Objects.equals(command, that.command); }
@Override public int hashCode() { return Objects.hash(super.hashCode(), command); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof CommandUpdateEvent)) return false; if (!super.equals(o)) return false; CommandUpdateEvent that = (CommandUpdateEvent) o; return Objects.equals(command, that.command); }
@Override public int hashCode() { return Objects.hash(super.hashCode(), command); }