@Override public CompletableFuture<?> subscribe(String subscriberId, Map<String, Set<String>> aggregatesAndEvents, SubscriberOptions subscriberOptions, Function<DispatchedEvent<Event>, CompletableFuture<?>> handler) { if (activityLogger.isDebugEnabled()) activityLogger.debug("Subscribing {} {}", subscriberId, aggregatesAndEvents); CompletableFuture<?> outcome = aggregateEvents.subscribe(subscriberId, aggregatesAndEvents, subscriberOptions, se -> serializedEventDeserializer.toDispatchedEvent(se).map(handler::apply).orElse(CompletableFuture.completedFuture(null))); if (activityLogger.isDebugEnabled()) return CompletableFutureUtil.tap(outcome, (result, throwable) -> { if (throwable == null) activityLogger.debug("Subscribed {} {}", subscriberId, aggregatesAndEvents); else activityLogger.error(String.format("Subscribe failed: %s %s", subscriberId, aggregatesAndEvents), throwable); }); else return outcome; }
@Override public CompletableFuture<?> subscribe(String subscriberId, Map<String, Set<String>> aggregatesAndEvents, SubscriberOptions subscriberOptions, Function<DispatchedEvent<Event>, CompletableFuture<?>> handler) { if (activityLogger.isDebugEnabled()) activityLogger.debug("Subscribing {} {}", subscriberId, aggregatesAndEvents); CompletableFuture<?> outcome = aggregateEvents.subscribe(subscriberId, aggregatesAndEvents, subscriberOptions, se -> serializedEventDeserializer.toDispatchedEvent(se).map(handler::apply).orElse(CompletableFuture.completedFuture(null))); if (activityLogger.isDebugEnabled()) return CompletableFutureUtil.tap(outcome, (result, throwable) -> { if (throwable == null) activityLogger.debug("Subscribed {} {}", subscriberId, aggregatesAndEvents); else activityLogger.error(String.format("Subscribe failed: %s %s", subscriberId, aggregatesAndEvents), throwable); }); else return outcome; }
@Override public void subscribe(String subscriberId, Map<String, Set<String>> aggregatesAndEvents, SubscriberOptions subscriberOptions, Function<SerializedEvent, CompletableFuture<?>> handler) { try { target.subscribe(subscriberId, aggregatesAndEvents, subscriberOptions, handler).get(timeoutOptions.getTimeout(), timeoutOptions.getTimeUnit()); } catch (Throwable e) { Throwable unwrapped = CompletableFutureUtil.unwrap(e); if (unwrapped instanceof RuntimeException) throw (RuntimeException)unwrapped; else throw new RuntimeException(unwrapped); } }
@Override public void subscribe(String subscriberId, Map<String, Set<String>> aggregatesAndEvents, SubscriberOptions subscriberOptions, Function<SerializedEvent, CompletableFuture<?>> handler) { try { target.subscribe(subscriberId, aggregatesAndEvents, subscriberOptions, handler).get(timeoutOptions.getTimeout(), timeoutOptions.getTimeUnit()); } catch (Throwable e) { Throwable unwrapped = CompletableFutureUtil.unwrap(e); if (unwrapped instanceof RuntimeException) throw (RuntimeException)unwrapped; else throw new RuntimeException(unwrapped); } }