Class SimpleMessageBus

  • All Implemented Interfaces:
    MessageBus

    @ThreadSafe
    public class SimpleMessageBus
    extends java.lang.Object
    implements MessageBus
    A partial implementation of MessageBus.
    Author:
    Fabrizio Giudici
    • Constructor Detail

      • SimpleMessageBus

        public SimpleMessageBus()
        Creates a new instance with a SimpleAsyncMessageDelivery strategy for delivery. It will use its own thread pool.
      • SimpleMessageBus

        public SimpleMessageBus​(@Nonnull
                                java.util.concurrent.Executor executor)
        Creates a new instance given an executor and a SimpleAsyncMessageDelivery strategy for delivery.
        Parameters:
        executor - the Executor
      • SimpleMessageBus

        public SimpleMessageBus​(@Nonnull
                                java.util.concurrent.Executor executor,
                                @Nonnull
                                MessageDelivery messageDelivery)
        Creates a new instance given an executor and a strategy for delivery.
        Parameters:
        executor - the Executor
        messageDelivery - the strategy for delivery
    • Method Detail

      • publish

        public <Topic> void publish​(@Nonnull
                                    Topic message)
        Publishes the given event. The topic is the class of the event.
        Specified by:
        publish in interface MessageBus
        Type Parameters:
        Topic - the static type of the topic
        Parameters:
        message - the event
      • publish

        public <Topic> void publish​(@Nonnull
                                    java.lang.Class<Topic> topic,
                                    @Nonnull
                                    Topic message)
        Publishes the given message and topic. Passing an explicit topic can be useful when dealing with a hierarchy of events (so, perhaps a subclass is passed but the topic is the root of the hierarchy).
        Specified by:
        publish in interface MessageBus
        Type Parameters:
        Topic - the static type of the topic
        Parameters:
        topic - the topic
        message - the message
      • subscribe

        public <Topic> void subscribe​(@Nonnull
                                      java.lang.Class<Topic> topic,
                                      @Nonnull
                                      MessageBus.Listener<Topic> listener)
        Subscribes a MessageBus.Listener to a topic.
        Specified by:
        subscribe in interface MessageBus
        Type Parameters:
        Topic - the static type of the topic
        Parameters:
        topic - the topic
        listener - the listener
      • dispatchMessage

        protected <TOPIC> void dispatchMessage​(@Nonnull
                                               java.lang.Class<TOPIC> topic,
                                               @Nonnull
                                               TOPIC message)
        Dispatches a message.
        Type Parameters:
        TOPIC - the static type of the topic
        Parameters:
        topic - the dynamic type of the topic
        message - the message