private void notifyOnMessage(MessageListener listener, ServerSession from, ServerChannel to, Mutable mutable, Promise<Boolean> promise) { try { listener.onMessage(from, to, mutable, Promise.from(r -> promise.succeed(r == null ? true : r), failure -> { _logger.info("Exception reported by listener " + listener, failure); promise.succeed(true); })); } catch (Throwable x) { _logger.info("Exception thrown by listener " + listener, x); promise.succeed(true); } }
/** * <p>Callback invoked when a message is being published.</p> * <p>Implementers can notify the promise with false to signal * that the message should not be published.</p> * * @param sender the session that publishes the message * @param channel the channel the message is published to * @param message the message to be published * @param promise the promise to notify whether the message processing should continue */ public default void onMessage(ServerSession sender, ServerChannel channel, ServerMessage.Mutable message, Promise<Boolean> promise) { promise.succeed(onMessage(sender, channel, message)); }