Package io.aeron.archive.client
Class ReplayMerge
java.lang.Object
io.aeron.archive.client.ReplayMerge
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum window at which a live destination should be added when trying to merge. -
Constructor Summary
ConstructorsConstructorDescriptionReplayMerge(Subscription subscription, AeronArchive archive, String replayChannel, String replayDestination, String liveDestination, long recordingId, long startPosition) Create aReplayMergeto manage the merging of a replayed stream and switching over to live stream as appropriate.ReplayMerge(Subscription subscription, AeronArchive archive, String replayChannel, String replayDestination, String liveDestination, long recordingId, long startPosition, EpochClock epochClock, long mergeProgressTimeoutMs) Create aReplayMergeto manage the merging of a replayed stream and switching over to live stream as appropriate. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close and stop any active replay.intdoWork()Perform the work of replaying and merging.booleanHas the replay merge failed due to an error?image()TheImagewhich is a merge of the replay and live stream.booleanIs the live destination added to thesubscription()?booleanisMerged()Is the live stream merged and the replay stopped?intpoll(FragmentHandler fragmentHandler, int fragmentLimit) Poll theImageused for replay and merging and live stream.Get theSubscriptionused to consume the replayed and merged stream.toString()
-
Field Details
-
LIVE_ADD_MAX_WINDOW
public static final int LIVE_ADD_MAX_WINDOWThe 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 aReplayMergeto 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 theSubscription.liveDestination- for the live stream and the destination added by theSubscription.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 aReplayMergeto 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 theSubscription.liveDestination- for the live stream and the destination added by theSubscription.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:
closein interfaceAutoCloseable
-
subscription
Get theSubscriptionused to consume the replayed and merged stream.- Returns:
- the
Subscriptionused 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 underlyingImagedirectly, callpoll(FragmentHandler, int)on this class.- Returns:
- indication of work done processing the merge.
-
poll
Poll theImageused for replay and merging and live stream. ThedoWork()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
TheImagewhich is a merge of the replay and live stream.- Returns:
- the
Imagewhich is a merge of the replay and live stream.
-
isLiveAdded
public boolean isLiveAdded()Is the live destination added to thesubscription()?- Returns:
- true if live destination added or false if not.
-
toString
-