Class TopicMultiplexerAmLink
- java.lang.Object
-
- org.forgerock.openig.tools.notifications.ws.link.TopicMultiplexerAmLink
-
- All Implemented Interfaces:
AmLink
,AmLinkListener
,AmLinkListener.ResilientAmLinkListener
public class TopicMultiplexerAmLink extends Object implements AmLink, AmLinkListener.ResilientAmLinkListener
Multiplex topic registration on top of aAmLink
.As AM does not manage multiple subscriptions to the same topic from a client, this class has to do the subscription multiplexing itself. In other words, it maintains a map of subscribed
TopicMultiplexerAmLink.Topic
s, each of which has a reference counter used to detect when an un-registration action needs to be performed.The first time a topic is subscribed to, this class sends a subscription message to AM and waits for the acknowledgment. Every subsequent subscription to the same topic will reuse the same "connection" without sending a subscription request. Inversely, no un-subscription request is sent to AM until the last reference is removed.
The following issues may occur:
- 2 (un)subscriptions at the same time: a lock prevents this.
- A topic is subscribed, then unsubscribed before the subscription promise fulfillment: Wait for the subscription promise to complete before un-subscribing
- A topic is subscribed, the subscription promise failed. Then the subscription is removed from the topic list
- A topic is un-subscribed, the un-subscription promise failed. The the topic is still considered as subscribed
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.forgerock.openig.tools.notifications.ws.link.AmLink
AmLink.AmLinkSupplier, AmLink.ResilientAmLinkSupplier
-
Nested classes/interfaces inherited from interface org.forgerock.openig.tools.notifications.ws.link.AmLinkListener
AmLinkListener.ResilientAmLinkListener
-
-
Constructor Summary
Constructors Constructor Description TopicMultiplexerAmLink(AmLink.ResilientAmLinkSupplier amLinkSupplier, AmLinkListener.ResilientAmLinkListener amLinkListener)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AmLink.ResilientAmLinkSupplier
asSupplier(AmLink.ResilientAmLinkSupplier amLinkSupplier)
Promise<Void,Exception>
close()
Close theAmLink
and its associated resources.void
onDisconnection()
The handler to call in case of a disconnection.void
onNotification(Notification notification)
The notification handler, will receive all notifications sent by AM.void
onReopen()
The handler to call on connection reopening.Promise<Void,Exception>
start()
Start theAmLink
.Promise<Void,Exception>
subscribe(String topicName)
Subscribe to an AM topic.Promise<Void,Exception>
unsubscribe(String topicName)
Unsubscribe from an AM topic.
-
-
-
Constructor Detail
-
TopicMultiplexerAmLink
public TopicMultiplexerAmLink(AmLink.ResilientAmLinkSupplier amLinkSupplier, AmLinkListener.ResilientAmLinkListener amLinkListener)
-
-
Method Detail
-
onReopen
public void onReopen()
Description copied from interface:AmLinkListener.ResilientAmLinkListener
The handler to call on connection reopening. Can only be called after onDisconnection call, and will be called before any (un)subscribe promise completes.- Specified by:
onReopen
in interfaceAmLinkListener.ResilientAmLinkListener
-
onDisconnection
public void onDisconnection()
Description copied from interface:AmLinkListener
The handler to call in case of a disconnection. When this handler is called, the instance is considered as closed. Can only be called after the start promise successful completion, and before every ongoing (un)subscribe promise failure.- Specified by:
onDisconnection
in interfaceAmLinkListener
-
onNotification
public void onNotification(Notification notification)
Description copied from interface:AmLinkListener
The notification handler, will receive all notifications sent by AM. Duplicate notifications may occur.- Specified by:
onNotification
in interfaceAmLinkListener
- Parameters:
notification
- the received notification
-
close
public Promise<Void,Exception> close()
Description copied from interface:AmLink
Close theAmLink
and its associated resources. The instance can't be reused afterward.
-
subscribe
public Promise<Void,Exception> subscribe(String topicName)
Description copied from interface:AmLink
Subscribe to an AM topic. After successful subscription, the notification consumer (supplied in will begin receiving notifications on this topic.
-
unsubscribe
public Promise<Void,Exception> unsubscribe(String topicName)
Description copied from interface:AmLink
Unsubscribe from an AM topic. After successful unsubscribe request, the notification consumer will stop receiving notifications on this topic.- Specified by:
unsubscribe
in interfaceAmLink
- Parameters:
topicName
- The AM topic to un-subscribe from.- Returns:
- A promise of a successful un-subscription to the AM topic.
-
asSupplier
public static AmLink.ResilientAmLinkSupplier asSupplier(AmLink.ResilientAmLinkSupplier amLinkSupplier)
-
-