Class ReplayMerge

java.lang.Object
io.aeron.archive.client.ReplayMerge
All Implemented Interfaces:
AutoCloseable

public final class ReplayMerge extends Object implements AutoCloseable
Replay a recorded stream from a starting position and merge with live stream for a full history of a stream.

Once constructed either of poll(FragmentHandler, int) or doWork(), interleaved with consumption of the image(), should be called in a duty cycle loop until isMerged() is true. After which the ReplayMerge can be closed and continued usage can be made of the Image or its parent Subscription. If an exception occurs or progress stops, the merge will fail and hasFailed() will be true.

If the endpoint on the replay destination uses a port of 0, then the OS will assign a port from the ephemeral range and this will be added to the replay channel for instructing the archive.

NOTE: Merging is only supported with UDP streams.

NOTE: ReplayMerge is not threadsafe and should not be used with a shared AeronArchive client.

  • Field Details

    • LIVE_ADD_MAX_WINDOW

      public static final int LIVE_ADD_MAX_WINDOW
      The maximum window at which a live destination should be added when trying to merge.
      See Also:
  • Constructor Details

    • ReplayMerge

      public ReplayMerge(Subscription subscription, AeronArchive archive, String replayChannel, String replayDestination, String liveDestination, long recordingId, long startPosition, EpochClock epochClock, long mergeProgressTimeoutMs)
      Create a ReplayMerge to manage the merging of a replayed stream and switching over to live stream as appropriate.
      Parameters:
      subscription - to use for the replay and live stream. Must be a multi-destination subscription.
      archive - to use for the replay.
      replayChannel - to as a template for what the archive will use.
      replayDestination - to send the replay to and the destination added by the Subscription.
      liveDestination - for the live stream and the destination added by the Subscription.
      recordingId - for the replay.
      startPosition - for the replay.
      epochClock - to use for progress checks.
      mergeProgressTimeoutMs - to use for progress checks.
    • ReplayMerge

      public ReplayMerge(Subscription subscription, AeronArchive archive, String replayChannel, String replayDestination, String liveDestination, long recordingId, long startPosition)
      Create a ReplayMerge to manage the merging of a replayed stream and switching over to live stream as appropriate.
      Parameters:
      subscription - to use for the replay and live stream. Must be a multi-destination subscription.
      archive - to use for the replay.
      replayChannel - to use as a template for what the archive will use.
      replayDestination - to send the replay to and the destination added by the Subscription.
      liveDestination - for the live stream and the destination added by the Subscription.
      recordingId - for the replay.
      startPosition - for the replay.
  • Method Details

    • close

      public void close()
      Close and stop any active replay. Will remove the replay destination from the subscription. This operation Will NOT remove the live destination if it has been added, so it can be used for live consumption.
      Specified by:
      close in interface AutoCloseable
    • subscription

      public Subscription subscription()
      Get the Subscription used to consume the replayed and merged stream.
      Returns:
      the Subscription used to consume the replayed and merged stream.
    • doWork

      public int doWork()
      Perform the work of replaying and merging. Should only be used if polling the underlying Image directly, call poll(FragmentHandler, int) on this class.
      Returns:
      indication of work done processing the merge.
    • poll

      public int poll(FragmentHandler fragmentHandler, int fragmentLimit)
      Poll the Image used for replay and merging and live stream. The doWork() method will be called before the poll so that processing of the merge can be done.
      Parameters:
      fragmentHandler - to call for fragments.
      fragmentLimit - for poll call.
      Returns:
      number of fragments processed.
    • isMerged

      public boolean isMerged()
      Is the live stream merged and the replay stopped?
      Returns:
      true if live stream is merged and the replay stopped or false if not.
    • hasFailed

      public boolean hasFailed()
      Has the replay merge failed due to an error?
      Returns:
      true if replay merge has failed due to an error.
    • image

      public Image image()
      The Image which is a merge of the replay and live stream.
      Returns:
      the Image which is a merge of the replay and live stream.
    • isLiveAdded

      public boolean isLiveAdded()
      Is the live destination added to the subscription()?
      Returns:
      true if live destination added or false if not.
    • toString

      public String toString()
      Overrides:
      toString in class Object