Class InMemoryNotificationBroker
- java.lang.Object
-
- org.forgerock.openam.notifications.brokers.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 Summary
Constructors Constructor Description InMemoryNotificationBroker(AMExecutorServiceFactory executorServiceFactory, org.forgerock.util.time.TimeService timeService, int queueSize, int consumers)Constructs a new InMemoryNotificationBroker.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanpublish(Topic topic, org.forgerock.json.JsonValue notification)Publish passes the notification onto subscribers of the topic.voidshutdown()Initiates an orderly shutdown in which previously published notifications are delivered, but no new notifications will be accepted.Subscriptionsubscribe(Consumer consumer)Creates a new subscription that is initially not bound to any topics.
-
-
-
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 threadstimeService- a time service for adding timestamps to messagesqueueSize- 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:NotificationBrokerPublish 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:
publishin interfaceNotificationBroker- Parameters:
topic- topicnotification- 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:NotificationBrokerCreates 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:
subscribein interfaceNotificationBroker- Parameters:
consumer- a consumer that will be called once per published notification- Returns:
- a new subscriber
-
shutdown
public void shutdown()
Description copied from interface:NotificationBrokerInitiates 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:
shutdownin interfaceNotificationBroker
-
-