Class InMemoryNotificationBroker

  • All Implemented Interfaces:
    NotificationBroker

    public final class InMemoryNotificationBroker
    extends Object
    implements NotificationBroker
    A notification broker that uses an in-memory shared queue for incoming notifications and a single thread for reading from it. Routing of notifications to subscriptions is done on the reading thread.

    The queue is a fixed size and therefore notifications may be lost if the queue becomes full.

    Since:
    14.0.0
    • Constructor Detail

      • InMemoryNotificationBroker

        @Inject
        public InMemoryNotificationBroker​(AMExecutorServiceFactory executorServiceFactory,
                                          org.forgerock.util.time.TimeService timeService,
                                          @Named("queueSize")
                                          int queueSize,
                                          @Named("consumers")
                                          int consumers)
        Constructs a new InMemoryNotificationBroker.
        Parameters:
        executorServiceFactory - an executor service factory for scheduling reader threads
        timeService - a time service for adding timestamps to messages
        queueSize - the number of notifications to buffer in memory
    • Method Detail

      • publish

        public boolean publish​(Topic topic,
                               org.forgerock.json.JsonValue notification)
        Description copied from interface: NotificationBroker
        Publish passes the notification onto subscribers of the topic. If there are no subscribers to the same topic, the notification is discarded.

        Publishing notifications may fail and this is signalled by returning false.

        Specified by:
        publish in interface NotificationBroker
        Parameters:
        topic - topic
        notification - notification
        Returns:
        attempts to give some indication whether the topic was successfully published. False gives a guarantee that publication definitely failed.
      • subscribe

        public Subscription subscribe​(Consumer consumer)
        Description copied from interface: NotificationBroker
        Creates a new subscription that is initially not bound to any topics.

        The given consumer will be called for each notification that is published to any of the bound topics.

        Specified by:
        subscribe in interface NotificationBroker
        Parameters:
        consumer - a consumer that will be called once per published notification
        Returns:
        a new subscriber
      • shutdown

        public void shutdown()
        Description copied from interface: NotificationBroker
        Initiates an orderly shutdown in which previously published notifications are delivered, but no new notifications will be accepted. Invocation has no additional effect if already shut down.
        Specified by:
        shutdown in interface NotificationBroker