@Test void handle() { assertThat(SUT.packetConsumer, nullValue()); SUT.handle(o -> o.notify()); assertThat(SUT.commands, hasSize(0)); assertThat(SUT.packetConsumer, notNullValue()); assertThrows(ConversationContext.PlcWiringException.class, () -> SUT.handle(o -> o.notify())); }
@Override public DefaultContextHandler handle(Consumer<T> packetConsumer) { if (this.packetConsumer != null) { throw new ConversationContext.PlcWiringException("can't handle multiple consumers"); } this.packetConsumer = packetConsumer; final HandlerRegistration registration = new HandlerRegistration(commands, expectClazz, packetConsumer, onTimeoutConsumer, errorConsumer, Instant.now().plus(timeout)); finisher.accept(registration); context.sendToWire(request); return new DefaultContextHandler(() -> registration.hasHandled(), () -> registration.cancel()); }
DefaultSendRequestContext implements ConversationContext.SendRequestContext<T> { @Override public DefaultContextHandler handle(Consumer<T> packetConsumer) { if (this.packetConsumer != null) { throw new ConversationContext.PlcWiringException("can't handle multiple consumers"); } this.packetConsumer = packetConsumer; final HandlerRegistration registration = new HandlerRegistration(commands, expectClazz, packetConsumer, onTimeoutConsumer, errorConsumer, Instant.now().plus(timeout)); finisher.accept(registration); context.sendToWire(request); return new DefaultContextHandler(() -> registration.hasHandled(), () -> registration.cancel()); } }
DefaultSendRequestContext implements ConversationContext.SendRequestContext<T> { @Override public DefaultContextHandler handle(Consumer<T> packetConsumer) { if (this.packetConsumer != null) { throw new ConversationContext.PlcWiringException("can't handle multiple consumers"); } this.packetConsumer = packetConsumer; final HandlerRegistration registration = new HandlerRegistration(commands, expectClazz, packetConsumer, onTimeoutConsumer, errorConsumer, Instant.now().plus(timeout)); finisher.accept(registration); context.sendToWire(request); return new DefaultContextHandler(() -> registration.hasHandled(), () -> registration.cancel()); } DefaultSendRequestContext(Consumer<HandlerRegistration> finisher, T request, ConversationContext<T> context); protected  DefaultSendRequestContext(Deque<Either<Function<?, ?>, Predicate<?>>> commands, Duration timeout, Consumer<HandlerRegistration> finisher, Object request, ConversationContext<?> context, Class<?> expectClazz, Consumer<?> packetConsumer, Consumer<TimeoutException> onTimeoutConsumer, BiConsumer<?, ? extends Throwable> errorConsumer); }
DefaultSendRequestContext implements ConversationContext.SendRequestContext<T> { @Override public DefaultContextHandler handle(Consumer<T> packetConsumer) { if (this.packetConsumer != null) { throw new ConversationContext.PlcWiringException("can't handle multiple consumers"); } this.packetConsumer = packetConsumer; final HandlerRegistration registration = new HandlerRegistration(commands, expectClazz, packetConsumer, onTimeoutConsumer, errorConsumer, Instant.now().plus(timeout)); finisher.accept(registration); context.sendToWire(request); return new DefaultContextHandler(() -> registration.hasHandled(), () -> registration.cancel()); } DefaultSendRequestContext(Consumer<HandlerRegistration> finisher, T request, ConversationContext<T> context); protected  DefaultSendRequestContext(Deque<Either<Function<?, ?>, Predicate<?>>> commands, Duration timeout, Consumer<HandlerRegistration> finisher, Object request, ConversationContext<?> context, Class<?> expectClazz, Consumer<?> packetConsumer, Consumer<TimeoutException> onTimeoutConsumer, BiConsumer<?, ? extends Throwable> errorConsumer); @Override ConversationContext.SendRequestContext<T> expectResponse(Class<T> clazz, Duration timeout); @Override ConversationContext.SendRequestContext<T> check(Predicate<T> checker); @Override DefaultContextHandler handle(Consumer<T> packetConsumer); @Override ConversationContext.SendRequestContext<T> onTimeout(Consumer<TimeoutException> onTimeoutConsumer); @Override ConversationContext.SendRequestContext<T> onError(BiConsumer<T, E> errorConsumer); @Override ConversationContext.SendRequestContext<R> unwrap(Function<T, R> unwrapper); @Override ConversationContext.SendRequestContext<R> only(Class<R> clazz); }
DefaultSendRequestContext implements ConversationContext.SendRequestContext<T> { @Override public DefaultContextHandler handle(Consumer<T> packetConsumer) { if (this.packetConsumer != null) { throw new ConversationContext.PlcWiringException("can't handle multiple consumers"); } this.packetConsumer = packetConsumer; final HandlerRegistration registration = new HandlerRegistration(commands, expectClazz, packetConsumer, onTimeoutConsumer, errorConsumer, Instant.now().plus(timeout)); finisher.accept(registration); context.sendToWire(request); return new DefaultContextHandler(() -> registration.hasHandled(), () -> registration.cancel()); } DefaultSendRequestContext(Consumer<HandlerRegistration> finisher, T request, ConversationContext<T> context); protected  DefaultSendRequestContext(Deque<Either<Function<?, ?>, Predicate<?>>> commands, Duration timeout, Consumer<HandlerRegistration> finisher, Object request, ConversationContext<?> context, Class<?> expectClazz, Consumer<?> packetConsumer, Consumer<TimeoutException> onTimeoutConsumer, BiConsumer<?, ? extends Throwable> errorConsumer); @Override ConversationContext.SendRequestContext<T> expectResponse(Class<T> clazz, Duration timeout); @Override ConversationContext.SendRequestContext<T> check(Predicate<T> checker); @Override DefaultContextHandler handle(Consumer<T> packetConsumer); @Override ConversationContext.SendRequestContext<T> onTimeout(Consumer<TimeoutException> onTimeoutConsumer); @Override ConversationContext.SendRequestContext<T> onError(BiConsumer<T, E> errorConsumer); @Override ConversationContext.SendRequestContext<R> unwrap(Function<T, R> unwrapper); @Override ConversationContext.SendRequestContext<R> only(Class<R> clazz);  }