Class PeriodicallyRenewedAmLink
java.lang.Object
org.forgerock.openig.tools.notifications.ws.link.PeriodicallyRenewedAmLink
- All Implemented Interfaces:
AmLink
,AmLinkListener
Renew the
AmLink
periodically without causing any disconnection. This is needed to keep a connection with
IDCloud, because it has a timeout on its WebSocket connections.
The periodical connection renewal algorithm:
- [un-]subscriptions are put on hold (ie: bound to a
Promise
). - This
AmLink
waits for every ongoing [un-]subscriptions to complete - A new
AmLink
is started from the current list ofmanagedTopics
- Once the new link is ready, waiting [un-]subscriptions are released
- In the background the old link is shut down.
While transitioning from one connection to the other, AM notifications may be received twice.
The connection renewal happens every renewalDelay
(can't be Duration.ZERO
nor
Duration.UNLIMITED
).
What could go wrong:
- A disconnection happens on any link: consider this as a real disconnection, so transmit the disconnection,
then close every open
AmLink
. - New link fails to start: consider this as a disconnection: see #1.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
A type helper to supply anAmLink.AmLinkSupplier
from a set of topics.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
-
Method Summary
Modifier and TypeMethodDescriptionclose()
Close theAmLink
and its associated resources.void
The handler to call in case of a disconnection.void
onNotification
(Notification notification) The notification handler, will receive all notifications sent by AM.static AmLink.AmLinkSupplier
periodicallyRenewedAmLinkSupplier
(Duration renewalDelay, PeriodicallyRenewedAmLink.AmLinkSupplierFromTopics amLinkSupplier, ScheduledExecutorService executorService) Builds a supplier ofPeriodicallyRenewedAmLink
.start()
Start theAmLink
.Subscribe to an AM topic.unsubscribe
(String topic) Unsubscribe from an AM topic.
-
Method Details
-
start
Description copied from interface:AmLink
-
close
Description copied from interface:AmLink
Close theAmLink
and its associated resources. The instance can't be reused afterward. -
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
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
-
subscribe
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
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:
topic
- The AM topic to un-subscribe from.- Returns:
- A promise of a successful un-subscription to the AM topic.
-
periodicallyRenewedAmLinkSupplier
public static AmLink.AmLinkSupplier periodicallyRenewedAmLinkSupplier(Duration renewalDelay, PeriodicallyRenewedAmLink.AmLinkSupplierFromTopics amLinkSupplier, ScheduledExecutorService executorService) Builds a supplier ofPeriodicallyRenewedAmLink
.- Parameters:
renewalDelay
- The delay between AmLink renewalsamLinkSupplier
- The AmLink supplier to use to get new AmLinksexecutorService
- The ExecutorService to use to schedule renewals- Returns:
- a supplier of
PeriodicallyRenewedAmLink
.
-