Class PeriodicallyRenewedAmLink

java.lang.Object
org.forgerock.openig.tools.notifications.ws.link.PeriodicallyRenewedAmLink
All Implemented Interfaces:
AmLink, AmLinkListener

public class PeriodicallyRenewedAmLink extends Object implements 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:

  1. [un-]subscriptions are put on hold (ie: bound to a Promise).
  2. This AmLink waits for every ongoing [un-]subscriptions to complete
  3. A new AmLink is started from the current list of managedTopics
  4. Once the new link is ready, waiting [un-]subscriptions are released
  5. 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:

  1. A disconnection happens on any link: consider this as a real disconnection, so transmit the disconnection, then close every open AmLink.
  2. New link fails to start: consider this as a disconnection: see #1.
  • Method Details

    • start

      public Promise<Void,Exception> start()
      Description copied from interface: AmLink
      Start the AmLink. The AmLink is considered ready for use only when the resulting promise has successfully completed. In case of a failed promise, the instance is considered as already closed.

      Note that notifications are guaranteed to be received AT LEAST once. Duplicate notification may occur.

      Specified by:
      start in interface AmLink
      Returns:
      A promise of this AmLink's start completion.
    • close

      public Promise<Void,Exception> close()
      Description copied from interface: AmLink
      Close the AmLink and its associated resources. The instance can't be reused afterward.
      Specified by:
      close in interface AmLink
      Returns:
      A promise indicating the AmLink has been closed
    • 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 interface AmLinkListener
    • 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 interface AmLinkListener
      Parameters:
      notification - the received notification
    • subscribe

      public Promise<Void,Exception> subscribe(String topic)
      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.
      Specified by:
      subscribe in interface AmLink
      Parameters:
      topic - The AM topic to subscribe to.
      Returns:
      A promise of a successful subscription to the AM topic.
    • unsubscribe

      public Promise<Void,Exception> unsubscribe(String topic)
      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 interface AmLink
      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 of PeriodicallyRenewedAmLink.
      Parameters:
      renewalDelay - The delay between AmLink renewals
      amLinkSupplier - The AmLink supplier to use to get new AmLinks
      executorService - The ExecutorService to use to schedule renewals
      Returns:
      a supplier of PeriodicallyRenewedAmLink.