Class MessageBus


  • public final class MessageBus
    extends java.lang.Object
    A bus for posting messages to subscribers. Message content is defined by the Topic a subscriber subscribes to.
    • Constructor Summary

      Constructors 
      Constructor Description
      MessageBus()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <M> void publish​(Topic<M> topic, M message)
      Publishes message into topic.
      <M> @NotNull Disposable subscribe​(@NotNull Topic<M> topic, @NotNull java.util.function.Consumer<M> listener)
      Subscribes listener to messages in the topic.
      <M> @NotNull Disposable subscribeOnce​(@NotNull Topic<M> topic, @NotNull java.util.function.Consumer<M> listener)
      Subscribes listener to a single message in the topic.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MessageBus

        public MessageBus()
    • Method Detail

      • subscribe

        @NotNull
        public <M> @NotNull Disposable subscribe​(@NotNull
                                                 @NotNull Topic<M> topic,
                                                 @NotNull
                                                 @NotNull java.util.function.Consumer<M> listener)
        Subscribes listener to messages in the topic.
      • subscribeOnce

        @NotNull
        public <M> @NotNull Disposable subscribeOnce​(@NotNull
                                                     @NotNull Topic<M> topic,
                                                     @NotNull
                                                     @NotNull java.util.function.Consumer<M> listener)
        Subscribes listener to a single message in the topic. The subscription is cancelled after first received message.
      • publish

        public <M> void publish​(Topic<M> topic,
                                M message)
        Publishes message into topic.
        Type Parameters:
        M - type of the message.
        Parameters:
        topic - topic to publish message to
        message - message to publish