/** * Construct a message consumer that detects an indication that a device is ready to receive an upstream * message and delegates to the passed callback handlers. * * @param messageConsumer Message consumer that handles generic messages. * @param notificationReadyToDeliverConsumer Consumer<TimeUntilDisconnectNotification> that is called when the message indicates the current readiness * to receive an upstream message. * @return The message consumer that invokes the specific handlers depending on the event type. * @throws NullPointerException if any of the parameters are {@code null}. */ public static Consumer<Message> getConsumer(final Consumer<Message> messageConsumer, final Consumer<TimeUntilDisconnectNotification> notificationReadyToDeliverConsumer) { Objects.requireNonNull(messageConsumer); Objects.requireNonNull(notificationReadyToDeliverConsumer); return new MessageTap( msg -> { if (msg.getBody() == null || MessageHelper.hasDataBody(msg)) { TimeUntilDisconnectNotification.fromMessage(msg).ifPresent( notificationObject -> notificationReadyToDeliverConsumer.accept(notificationObject)); messageConsumer.accept(msg); } }); }
/** * Construct a message consumer that detects an indication that a device is ready to receive an upstream * message and delegates to the passed callback handlers. * * @param messageConsumer Message consumer that handles generic messages. * @param notificationReadyToDeliverConsumer Consumer<TimeUntilDisconnectNotification> that is called when the message indicates the current readiness * to receive an upstream message. * @return The message consumer that invokes the specific handlers depending on the event type. * @throws NullPointerException if any of the parameters are {@code null}. */ public static Consumer<Message> getConsumer(final Consumer<Message> messageConsumer, final Consumer<TimeUntilDisconnectNotification> notificationReadyToDeliverConsumer) { Objects.requireNonNull(messageConsumer); Objects.requireNonNull(notificationReadyToDeliverConsumer); return new MessageTap( msg -> { if (msg.getBody() == null || MessageHelper.hasDataBody(msg, false)) { TimeUntilDisconnectNotification.fromMessage(msg).ifPresent( notificationObject -> notificationReadyToDeliverConsumer.accept(notificationObject)); messageConsumer.accept(msg); } }); }