Class AeronArchive

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

public final class AeronArchive extends Object implements AutoCloseable
Client for interacting with a local or remote Aeron Archive which records and replays message streams from storage.

This client provides a simple interaction model which is mostly synchronous and may not be optimal. The underlying components such as the ArchiveProxy and the ControlResponsePoller or RecordingDescriptorPoller may be used directly if a more asynchronous interaction is required.

Note: This class is threadsafe but the lock can be elided for single threaded access via AeronArchive.Context.lock(Lock) being set to NoOpLock.

  • Field Details

    • NULL_TIMESTAMP

      public static final long NULL_TIMESTAMP
      Represents a timestamp that has not been set. Can be used when the time is not known.
      See Also:
    • NULL_POSITION

      public static final long NULL_POSITION
      Represents a position that has not been set. Can be used when the position is not known.
      See Also:
    • NULL_LENGTH

      public static final long NULL_LENGTH
      Represents a length that has not been set. If null length is provided then replay the whole recorded stream.
      See Also:
    • NOT_CONNECTED_MSG

      public static final String NOT_CONNECTED_MSG
      Indicates the client is no longer connected to an archive.
      See Also:
    • REPLAY_ALL_AND_FOLLOW

      public static final long REPLAY_ALL_AND_FOLLOW
      When replaying a live recording, replay the whole stream and follow the live recording. This will behave the same way as providing NULL_LENGTH
      See Also:
    • REPLAY_ALL_AND_STOP

      public static final long REPLAY_ALL_AND_STOP
      When replaying a live recording, replay up to the current limit then stop the replay and end the stream.
      See Also:
  • Method Details

    • segmentFileBasePosition

      public static long segmentFileBasePosition(long startPosition, long position, int termBufferLength, int segmentFileLength)
      Position of the recorded stream at the base of a segment file. If a recording starts within a term then the base position can be before the recording started.
      Parameters:
      startPosition - of the stream.
      position - of the stream to calculate the segment base position from.
      termBufferLength - of the stream.
      segmentFileLength - which is a multiple of term length.
      Returns:
      the position of the recorded stream at the beginning of a segment file.
    • state

      public AeronArchive.State state()
      Returns the state of this client.
      Returns:
      client state.
    • close

      public void close()
      Notify the archive that this control session is closed, so it can promptly release resources then close the local resources associated with the client.
      Specified by:
      close in interface AutoCloseable
    • connect

      public static AeronArchive connect()
      Connect to an Aeron archive using a default AeronArchive.Context. This will create a control session.
      Returns:
      the newly created Aeron Archive client.
    • connect

      public static AeronArchive connect(AeronArchive.Context ctx)
      Connect to an Aeron archive by providing a AeronArchive.Context. This will create a control session.

      Before connecting AeronArchive.Context.conclude() will be called. If an exception occurs then AeronArchive.Context.close() will be called.

      Parameters:
      ctx - for connection configuration.
      Returns:
      the newly created Aeron Archive client.
    • asyncConnect

      public static AeronArchive.AsyncConnect asyncConnect()
      Begin an attempt at creating a connection which can be completed by calling AeronArchive.AsyncConnect.poll() until it returns the client, before complete it will return null.
      Returns:
      the AeronArchive.AsyncConnect that can be polled for completion.
    • asyncConnect

      public static AeronArchive.AsyncConnect asyncConnect(AeronArchive.Context ctx)
      Begin an attempt at creating a connection which can be completed by calling AeronArchive.AsyncConnect.poll() until it returns the client, before complete it will return null.
      Parameters:
      ctx - for the archive connection.
      Returns:
      the AeronArchive.AsyncConnect that can be polled for completion.
    • context

      public AeronArchive.Context context()
      Get the AeronArchive.Context used to connect this archive client.
      Returns:
      the AeronArchive.Context used to connect this archive client.
    • lastCorrelationId

      public long lastCorrelationId()
      The last correlation id used for sending a request to the archive via method on this class.
      Returns:
      last correlation id used for sending a request to the archive.
    • controlSessionId

      public long controlSessionId()
      The control session id allocated for this connection to the archive.
      Returns:
      control session id allocated for this connection to the archive.
    • archiveProxy

      public ArchiveProxy archiveProxy()
      The ArchiveProxy for send asynchronous messages to the connected archive.
      Returns:
      the ArchiveProxy for send asynchronous messages to the connected archive.
    • controlResponsePoller

      public ControlResponsePoller controlResponsePoller()
      Get the ControlResponsePoller for polling additional events on the control channel.
      Returns:
      the ControlResponsePoller for polling additional events on the control channel.
    • recordingDescriptorPoller

      public RecordingDescriptorPoller recordingDescriptorPoller()
      Get the RecordingDescriptorPoller for polling recording descriptors on the control channel.
      Returns:
      the RecordingDescriptorPoller for polling recording descriptors on the control channel.
    • recordingSubscriptionDescriptorPoller

      public RecordingSubscriptionDescriptorPoller recordingSubscriptionDescriptorPoller()
      The RecordingSubscriptionDescriptorPoller for polling subscription descriptors on the control channel.
      Returns:
      the RecordingSubscriptionDescriptorPoller for polling subscription descriptors on the control channel.
    • pollForErrorResponse

      public String pollForErrorResponse()
      Poll the response stream once for an error. If another message is present then it will be skipped over so only call when not expecting another response. If not connected then return NOT_CONNECTED_MSG.
      Returns:
      the error String otherwise null if no error is found.
    • checkForErrorResponse

      public void checkForErrorResponse()
      Check if an error has been returned for the control session, or if it is no longer connected, and then throw a ArchiveException if AeronArchive.Context.errorHandler(ErrorHandler) is not set.

      To check for an error response without raising an exception then try pollForErrorResponse().

      See Also:
    • pollForRecordingSignals

      public int pollForRecordingSignals()
      Poll for RecordingSignals for this session which will be dispatched to AeronArchive.Context.recordingSignalConsumer.
      Returns:
      positive value if signals dispatched otherwise 0.
    • addRecordedPublication

      public Publication addRecordedPublication(String channel, int streamId)
      Add a Publication and set it up to be recorded. If this is not the first, i.e. Publication.isOriginal() is true, then an ArchiveException will be thrown and the recording not initiated.

      This is a sessionId specific recording.

      Parameters:
      channel - for the publication.
      streamId - for the publication.
      Returns:
      the Publication ready for use.
    • addRecordedExclusivePublication

      public ExclusivePublication addRecordedExclusivePublication(String channel, int streamId)
      Add an ExclusivePublication and set it up to be recorded.

      This is a sessionId specific recording.

      Parameters:
      channel - for the publication.
      streamId - for the publication.
      Returns:
      the ExclusivePublication ready for use.
    • startRecording

      public long startRecording(String channel, int streamId, io.aeron.archive.codecs.SourceLocation sourceLocation)
      Start recording a channel and stream pairing.

      Channels that include sessionId parameters are considered different from channels without sessionIds. If a publication matches both a sessionId specific channel recording and a non-sessionId specific recording, it will be recorded twice.

      Parameters:
      channel - to be recorded.
      streamId - to be recorded.
      sourceLocation - of the publication to be recorded.
      Returns:
      the subscriptionId, i.e. Subscription.registrationId(), of the recording. This can be passed to stopRecording(long).
    • startRecording

      public long startRecording(String channel, int streamId, io.aeron.archive.codecs.SourceLocation sourceLocation, boolean autoStop)
      Start recording a channel and stream pairing.

      Channels that include sessionId parameters are considered different from channels without sessionIds. If a publication matches both a sessionId specific channel recording and a non-sessionId specific recording, it will be recorded twice.

      Parameters:
      channel - to be recorded.
      streamId - to be recorded.
      sourceLocation - of the publication to be recorded.
      autoStop - if the recording should be automatically stopped when complete.
      Returns:
      the subscriptionId, i.e. Subscription.registrationId(), of the recording. This can be passed to stopRecording(long). However, if is autoStop is true then no need to stop the recording unless you want to abort early.
    • extendRecording

      public long extendRecording(long recordingId, String channel, int streamId, io.aeron.archive.codecs.SourceLocation sourceLocation)
      Extend an existing, non-active recording of a channel and stream pairing.

      The channel must be configured for the initial position from which it will be extended. This can be done with ChannelUriStringBuilder.initialPosition(long, int, int). The details required to initialise can be found by calling listRecording(long, RecordingDescriptorConsumer).

      Parameters:
      recordingId - of the existing recording.
      channel - to be recorded.
      streamId - to be recorded.
      sourceLocation - of the publication to be recorded.
      Returns:
      the subscriptionId, i.e. Subscription.registrationId(), of the recording. This can be passed to stopRecording(long).
    • extendRecording

      public long extendRecording(long recordingId, String channel, int streamId, io.aeron.archive.codecs.SourceLocation sourceLocation, boolean autoStop)
      Extend an existing, non-active recording of a channel and stream pairing.

      The channel must be configured for the initial position from which it will be extended. This can be done with ChannelUriStringBuilder.initialPosition(long, int, int). The details required to initialise can be found by calling listRecording(long, RecordingDescriptorConsumer).

      Parameters:
      recordingId - of the existing recording.
      channel - to be recorded.
      streamId - to be recorded.
      sourceLocation - of the publication to be recorded.
      autoStop - if the recording should be automatically stopped when complete.
      Returns:
      the subscriptionId, i.e. Subscription.registrationId(), of the recording. This can be passed to stopRecording(long). However, if is autoStop is true then no need to stop the recording unless you want to abort early.
    • stopRecording

      public void stopRecording(String channel, int streamId)
      Stop recording for a channel and stream pairing.

      Channels that include sessionId parameters are considered different from channels without sessionIds. Stopping a recording on a channel without a sessionId parameter will not stop the recording of any sessionId specific recordings that use the same channel and streamId.

      Parameters:
      channel - to stop recording for.
      streamId - to stop recording for.
    • tryStopRecording

      public boolean tryStopRecording(String channel, int streamId)
      Try to stop a recording for a channel and stream pairing.

      Channels that include sessionId parameters are considered different from channels without sessionIds. Stopping a recording on a channel without a sessionId parameter will not stop the recording of any sessionId specific recordings that use the same channel and streamId.

      Parameters:
      channel - to stop recording for.
      streamId - to stop recording for.
      Returns:
      true if the recording was stopped or false if the subscription is not currently active.
    • stopRecording

      public void stopRecording(long subscriptionId)
      Stop recording for a subscriptionId that has been returned from startRecording(String, int, SourceLocation) or extendRecording(long, String, int, SourceLocation).
      Parameters:
      subscriptionId - is the Subscription.registrationId() for the recording in the archive.
    • tryStopRecording

      public boolean tryStopRecording(long subscriptionId)
      Try stop a recording for a subscriptionId that has been returned from startRecording(String, int, SourceLocation) or extendRecording(long, String, int, SourceLocation).
      Parameters:
      subscriptionId - is the Subscription.registrationId() for the recording in the archive.
      Returns:
      true if the recording was stopped or false if the subscription is not currently active.
    • tryStopRecordingByIdentity

      public boolean tryStopRecordingByIdentity(long recordingId)
      Try stop an active recording by its recording id.
      Parameters:
      recordingId - for which active recording should be stopped.
      Returns:
      true if the recording was stopped or false if the recording is not currently active.
    • stopRecording

      public void stopRecording(Publication publication)
      Stop recording a sessionId specific recording that pertains to the given Publication.
      Parameters:
      publication - to stop recording for.
    • startReplay

      public long startReplay(long recordingId, long position, long length, String replayChannel, int replayStreamId)
      Start a replay for a length in bytes of a recording from a position. If the position is NULL_POSITION then the stream will be replayed from the start.

      The lower 32-bits of the returned value contains the Image.sessionId() of the received replay. All 64-bits are required to uniquely identify the replay when calling stopReplay(long). The lower 32-bits can be obtained by casting the long value to an int.

      Parameters:
      recordingId - to be replayed.
      position - from which the replay should begin or NULL_POSITION if from the start.
      length - of the stream to be replayed or REPLAY_ALL_AND_FOLLOW to follow a live recording. Use REPLAY_ALL_AND_STOP to read up the available limit and stop the replay. Long.MAX_VALUE can also be used to follow a live stream.
      replayChannel - to which the replay should be sent.
      replayStreamId - to which the replay should be sent.
      Returns:
      the id of the replay session which will be the same as the Image.sessionId() of the received replay for correlation with the matching channel and stream id in the lower 32 bits.
    • startBoundedReplay

      public long startBoundedReplay(long recordingId, long position, long length, int limitCounterId, String replayChannel, int replayStreamId)
      Start a replay for a length in bytes of a recording from a position bounded by a position counter. If the position is NULL_POSITION then the stream will be replayed from the start.

      The lower 32-bits of the returned value contains the Image.sessionId() of the received replay. All 64-bits are required to uniquely identify the replay when calling stopReplay(long). The lower 32-bits can be obtained by casting the long value to an int.

      Parameters:
      recordingId - to be replayed.
      position - from which the replay should begin or NULL_POSITION if from the start.
      length - of the stream to be replayed or REPLAY_ALL_AND_FOLLOW to follow a live recording. Use REPLAY_ALL_AND_STOP to read up the available limit and stop the replay. Long.MAX_VALUE can also be used to follow a live stream.
      limitCounterId - to use to bound replay.
      replayChannel - to which the replay should be sent.
      replayStreamId - to which the replay should be sent.
      Returns:
      the id of the replay session which will be the same as the Image.sessionId() of the received replay for correlation with the matching channel and stream id in the lower 32 bits.
    • startReplay

      public long startReplay(long recordingId, String replayChannel, int replayStreamId, ReplayParams replayParams)
      Start a replay for a recording based upon the parameters set in ReplayParams. By default, it will replay all the recording from the start. The ReplayParams is free to be reused when this call completes.
      Parameters:
      recordingId - to be replayed.
      replayChannel - to which the replay should be sent.
      replayStreamId - to which the replay should be sent.
      replayParams - optional parameters for the replay
      Returns:
      the id of the replay session which will be the same as the Image.sessionId() of the received replay for correlation with the matching channel and stream id in the lower 32 bits.
      See Also:
    • stopReplay

      public void stopReplay(long replaySessionId)
      Stop an existing replay session.
      Parameters:
      replaySessionId - to stop replay for which would have been returned from startReplay(long, long, long, String, int).
    • stopAllReplays

      public void stopAllReplays(long recordingId)
      Stop all replay sessions for a given recording id or all replays in general.
      Parameters:
      recordingId - to stop replay for or Aeron.NULL_VALUE for all replays.
    • replay

      public Subscription replay(long recordingId, long position, long length, String replayChannel, int replayStreamId)
      Replay a length in bytes of a recording from a position and for convenience create a Subscription to receive the replay. If the position is NULL_POSITION then the stream will be replayed from the start.
      Parameters:
      recordingId - to be replayed.
      position - from which the replay should begin or NULL_POSITION if from the start.
      length - of the stream to be replayed or REPLAY_ALL_AND_FOLLOW to follow a live recording. Use REPLAY_ALL_AND_STOP to read up the available limit and stop the replay. Long.MAX_VALUE can also be used to follow a live stream.
      replayChannel - to which the replay should be sent.
      replayStreamId - to which the replay should be sent.
      Returns:
      the Subscription for consuming the replay.
    • replay

      public Subscription replay(long recordingId, long position, long length, String replayChannel, int replayStreamId, AvailableImageHandler availableImageHandler, UnavailableImageHandler unavailableImageHandler)
      Replay a length in bytes of a recording from a position and for convenience create a Subscription to receive the replay. If the position is NULL_POSITION then the stream will be replayed from the start.
      Parameters:
      recordingId - to be replayed.
      position - from which the replay should begin or NULL_POSITION if from the start.
      length - of the stream to be replayed or REPLAY_ALL_AND_FOLLOW to follow a live recording. Use REPLAY_ALL_AND_STOP to read up the available limit and stop the replay. Long.MAX_VALUE can also be used to follow a live stream.
      replayChannel - to which the replay should be sent.
      replayStreamId - to which the replay should be sent.
      availableImageHandler - to be called when the replay image becomes available.
      unavailableImageHandler - to be called when the replay image goes unavailable.
      Returns:
      the Subscription for consuming the replay.
    • replay

      public Subscription replay(long recordingId, String replayChannel, int replayStreamId, ReplayParams replayParams)
      Replay a recording based upon the parameters set in ReplayParams. By default, it will replay all the recording from the start. The ReplayParams is free to be reused when this call completes.
      Parameters:
      recordingId - to be replayed.
      replayChannel - to which the replay should be sent.
      replayStreamId - to which the replay should be sent.
      replayParams - optional parameters for the replay
      Returns:
      the Subscription for consuming the replay.
      See Also:
    • listRecordings

      public int listRecordings(long fromRecordingId, int recordCount, RecordingDescriptorConsumer consumer)
      List all recording descriptors from a recording id with a limit of record count.

      If the recording id is greater than the largest known id then nothing is returned.

      Parameters:
      fromRecordingId - at which to begin the listing.
      recordCount - to limit for each query.
      consumer - to which the descriptors are dispatched.
      Returns:
      the number of descriptors found and consumed.
    • listRecordingsForUri

      public int listRecordingsForUri(long fromRecordingId, int recordCount, String channelFragment, int streamId, RecordingDescriptorConsumer consumer)
      List recording descriptors from a recording id with a limit of record count for a given channelFragment and stream id.

      If the recording id is greater than the largest known id then nothing is returned.

      Parameters:
      fromRecordingId - at which to begin the listing.
      recordCount - to limit for each query.
      channelFragment - for a contains match on the original channel stored with the archive descriptor.
      streamId - to match.
      consumer - to which the descriptors are dispatched.
      Returns:
      the number of descriptors found and consumed.
    • listRecording

      public int listRecording(long recordingId, RecordingDescriptorConsumer consumer)
      List a recording descriptor for a single recording id.

      If the recording id is greater than the largest known id then nothing is returned.

      Parameters:
      recordingId - at which to begin the listing.
      consumer - to which the descriptors are dispatched.
      Returns:
      the number of descriptors found and consumed.
    • getStartPosition

      public long getStartPosition(long recordingId)
      Get the start position for a recording.
      Parameters:
      recordingId - of the recording for which the position is required.
      Returns:
      the start position of a recording.
      See Also:
    • getRecordingPosition

      public long getRecordingPosition(long recordingId)
      Get the position recorded for an active recording. If no active recording then return NULL_POSITION.
      Parameters:
      recordingId - of the active recording for which the position is required.
      Returns:
      the recorded position for the active recording or NULL_POSITION if recording not active.
      See Also:
    • getStopPosition

      public long getStopPosition(long recordingId)
      Get the stop position for a recording.
      Parameters:
      recordingId - of the recording for which the position is required.
      Returns:
      the stop position, or NULL_POSITION if still active.
      See Also:
    • getMaxRecordedPosition

      public long getMaxRecordedPosition(long recordingId)
      Get the max recorded position of a recording. For active recordings it will be the recording position, and for inactive recordings it will be the stop position.
      Parameters:
      recordingId - of the recording for which the position is required.
      Returns:
      the max recorded position of the recording.
      Since:
      1.44.0
    • archiveId

      public long archiveId()
      Get the id of the Archive.
      Returns:
      the id of the Archive.
      Since:
      1.44.0
    • findLastMatchingRecording

      public long findLastMatchingRecording(long minRecordingId, String channelFragment, int streamId, int sessionId)
      Find the last recording that matches the given criteria.
      Parameters:
      minRecordingId - to search back to.
      channelFragment - for a contains match on the original channel stored with the archive descriptor.
      streamId - of the recording to match.
      sessionId - of the recording to match.
      Returns:
      the recordingId if found otherwise Aeron.NULL_VALUE if not found.
    • truncateRecording

      public long truncateRecording(long recordingId, long position)
      Truncate a stopped recording to a given position that is less than the stopped position. The provided position must be on a fragment boundary. Truncating a recording to the start position effectively deletes the recording.
      Parameters:
      recordingId - of the stopped recording to be truncated.
      position - to which the recording will be truncated.
      Returns:
      count of deleted segment files.
    • purgeRecording

      public long purgeRecording(long recordingId)
      Purge a stopped recording, i.e. mark recording as RecordingState.INVALID and delete the corresponding segment files. The space in the Catalog will be reclaimed upon compaction.
      Parameters:
      recordingId - of the stopped recording to be purged.
      Returns:
      count of deleted segment files.
    • listRecordingSubscriptions

      public int listRecordingSubscriptions(int pseudoIndex, int subscriptionCount, String channelFragment, int streamId, boolean applyStreamId, RecordingSubscriptionDescriptorConsumer consumer)
      List active recording subscriptions in the archive. These are the result of requesting one of startRecording(String, int, SourceLocation) or a extendRecording(long, String, int, SourceLocation). The returned subscription id can be used for passing to stopRecording(long).
      Parameters:
      pseudoIndex - in the active list at which to begin for paging.
      subscriptionCount - to get in a listing.
      channelFragment - to do a contains match on the stripped channel URI. Empty string is match all.
      streamId - to match on the subscription.
      applyStreamId - true if the stream id should be matched.
      consumer - for the matched subscription descriptors.
      Returns:
      the count of matched subscriptions.
    • replicate

      public long replicate(long srcRecordingId, long dstRecordingId, int srcControlStreamId, String srcControlChannel, String liveDestination)
      Replicate a recording from a source archive to a destination which can be considered a backup for a primary archive. The source recording will be replayed via the provided replay channel and use the original stream id. If the destination recording id is Aeron.NULL_VALUE then a new destination recording is created, otherwise the provided destination recording id will be extended. The details of the source recording descriptor will be replicated.

      For a source recording that is still active the replay can merge with the live stream and then follow it directly and no longer require the replay from the source. This would require a multicast live destination.

      Errors will be reported asynchronously and can be checked for with pollForErrorResponse() or checkForErrorResponse().

      Parameters:
      srcRecordingId - recording id which must exist in the source archive.
      dstRecordingId - recording to extend in the destination, otherwise Aeron.NULL_VALUE.
      srcControlStreamId - remote control stream id for the source archive to instruct the replay on.
      srcControlChannel - remote control channel for the source archive to instruct the replay on.
      liveDestination - destination for the live stream if merge is required. Empty or null for no merge.
      Returns:
      return the replication session id which can be passed later to stopReplication(long).
    • replicate

      public long replicate(long srcRecordingId, long dstRecordingId, long stopPosition, int srcControlStreamId, String srcControlChannel, String liveDestination, String replicationChannel)
      Replicate a recording from a source archive to a destination which can be considered a backup for a primary archive. The source recording will be replayed via the provided replay channel and use the original stream id. If the destination recording id is Aeron.NULL_VALUE then a new destination recording is created, otherwise the provided destination recording id will be extended. The details of the source recording descriptor will be replicated.

      For a source recording that is still active the replay can merge with the live stream and then follow it directly and no longer require the replay from the source. This would require a multicast live destination.

      Errors will be reported asynchronously and can be checked for with pollForErrorResponse() or checkForErrorResponse().

      Stop recording this stream when the position of the destination reaches the specified stop position.

      Parameters:
      srcRecordingId - recording id which must exist in the source archive.
      dstRecordingId - recording to extend in the destination, otherwise Aeron.NULL_VALUE.
      stopPosition - position to stop the replication. NULL_POSITION to stop at end of current recording.
      srcControlStreamId - remote control stream id for the source archive to instruct the replay on.
      srcControlChannel - remote control channel for the source archive to instruct the replay on.
      liveDestination - destination for the live stream if merge is required. Empty or null for no merge.
      replicationChannel - channel over which the replication will occur. Empty or null for default channel.
      Returns:
      return the replication session id which can be passed later to stopReplication(long).
    • taggedReplicate

      public long taggedReplicate(long srcRecordingId, long dstRecordingId, long channelTagId, long subscriptionTagId, int srcControlStreamId, String srcControlChannel, String liveDestination)
      Replicate a recording from a source archive to a destination which can be considered a backup for a primary archive. The source recording will be replayed via the provided replay channel and use the original stream id. If the destination recording id is Aeron.NULL_VALUE then a new destination recording is created, otherwise the provided destination recording id will be extended. The details of the source recording descriptor will be replicated. The subscription used in the archive will be tagged with the provided tags.

      For a source recording that is still active the replay can merge with the live stream and then follow it directly and no longer require the replay from the source. This would require a multicast live destination.

      Errors will be reported asynchronously and can be checked for with pollForErrorResponse() or checkForErrorResponse().

      Parameters:
      srcRecordingId - recording id which must exist in the source archive.
      dstRecordingId - recording to extend in the destination, otherwise Aeron.NULL_VALUE.
      channelTagId - used to tag the replication subscription.
      subscriptionTagId - used to tag the replication subscription.
      srcControlStreamId - remote control stream id for the source archive to instruct the replay on.
      srcControlChannel - remote control channel for the source archive to instruct the replay on.
      liveDestination - destination for the live stream if merge is required. Empty or null for no merge.
      Returns:
      return the replication session id which can be passed later to stopReplication(long).
    • taggedReplicate

      public long taggedReplicate(long srcRecordingId, long dstRecordingId, long stopPosition, long channelTagId, long subscriptionTagId, int srcControlStreamId, String srcControlChannel, String liveDestination, String replicationChannel)
      Replicate a recording from a source archive to a destination which can be considered a backup for a primary archive. The source recording will be replayed via the provided replay channel and use the original stream id. If the destination recording id is Aeron.NULL_VALUE then a new destination recording is created, otherwise the provided destination recording id will be extended. The details of the source recording descriptor will be replicated. The subscription used in the archive will be tagged with the provided tags.

      For a source recording that is still active the replay can merge with the live stream and then follow it directly and no longer require the replay from the source. This would require a multicast live destination.

      Errors will be reported asynchronously and can be checked for with pollForErrorResponse() or checkForErrorResponse().

      Parameters:
      srcRecordingId - recording id which must exist in the source archive.
      dstRecordingId - recording to extend in the destination, otherwise Aeron.NULL_VALUE.
      stopPosition - position to stop the replication. NULL_POSITION to stop at end of current recording.
      channelTagId - used to tag the replication subscription.
      subscriptionTagId - used to tag the replication subscription.
      srcControlStreamId - remote control stream id for the source archive to instruct the replay on.
      srcControlChannel - remote control channel for the source archive to instruct the replay on.
      liveDestination - destination for the live stream if merge is required. Empty or null for no merge.
      replicationChannel - channel over which the replication will occur. Empty or null for default channel.
      Returns:
      return the replication session id which can be passed later to stopReplication(long).
    • replicate

      public long replicate(long srcRecordingId, int srcControlStreamId, String srcControlChannel, ReplicationParams replicationParams)
      Replicate a recording from a source archive to a destination which can be considered a backup for a primary archive. The behaviour of the replication is controlled through the ReplicationParams.

      For a source recording that is still active the replay can merge with the live stream and then follow it directly and no longer require the replay from the source. This would require a multicast live destination.

      Errors will be reported asynchronously and can be checked for with pollForErrorResponse() or checkForErrorResponse().

      The ReplicationParams is free to be reused when this call completes.

      Parameters:
      srcRecordingId - recording id which must exist in the source archive.
      srcControlStreamId - remote control stream id for the source archive to instruct the replay on.
      srcControlChannel - remote control channel for the source archive to instruct the replay on.
      replicationParams - Optional parameters to control the behaviour of the replication.
      Returns:
      return the replication session id which can be passed later to stopReplication(long).
    • stopReplication

      public void stopReplication(long replicationId)
      Stop a replication session by id returned from replicate(long, long, int, String, String).
      Parameters:
      replicationId - to stop replication for.
      See Also:
    • tryStopReplication

      public boolean tryStopReplication(long replicationId)
      Attempt to stop a replication session by id returned from replicate(long, long, int, String, String).
      Parameters:
      replicationId - to stop replication for.
      Returns:
      true if the replication was stopped, false if the replication is not active.
      See Also:
    • detachSegments

      public void detachSegments(long recordingId, long newStartPosition)
      Detach segments from the beginning of a recording up to the provided new start position.

      The new start position must be first byte position of a segment after the existing start position.

      It is not possible to detach segments which are active for recording or being replayed.

      Parameters:
      recordingId - to which the operation applies.
      newStartPosition - for the recording after the segments are detached.
      See Also:
    • deleteDetachedSegments

      public long deleteDetachedSegments(long recordingId)
      Delete segments which have been previously detached from a recording.
      Parameters:
      recordingId - to which the operation applies.
      Returns:
      count of deleted segment files.
      See Also:
    • purgeSegments

      public long purgeSegments(long recordingId, long newStartPosition)
      Purge (detach and delete) segments from the beginning of a recording up to the provided new start position.

      The new start position must be first byte position of a segment after the existing start position.

      It is not possible to detach segments which are active for recording or being replayed.

      Parameters:
      recordingId - to which the operation applies.
      newStartPosition - for the recording after the segments are detached.
      Returns:
      count of deleted segment files.
      See Also:
    • attachSegments

      public long attachSegments(long recordingId)
      Attach segments to the beginning of a recording to restore history that was previously detached.

      Segment files must match the existing recording and join exactly to the start position of the recording they are being attached to.

      Parameters:
      recordingId - to which the operation applies.
      Returns:
      count of attached segment files.
      See Also:
    • migrateSegments

      public long migrateSegments(long srcRecordingId, long dstRecordingId)
      Migrate segments from a source recording and attach them to the beginning or end of a destination recording.

      The source recording must match the destination recording for segment length, term length, mtu length, stream id. The source recording must join to the destination recording on a segment boundary and without gaps, i.e., the stop position and term id of one must match the start position and term id of the other.

      The source recording must be stopped. The destination recording must be stopped if migrating segments to the end of the destination recording.

      The source recording will be effectively truncated back to its start position after the migration.

      Parameters:
      srcRecordingId - source recording from which the segments will be migrated.
      dstRecordingId - destination recording to which the segments will be attached.
      Returns:
      count of attached segment files.
    • updateChannel

      public void updateChannel(long recordingId, String newChannel)
      Update the channel for a recording, i.e. replace original and stripped channel information in the catalog.
      Parameters:
      recordingId - the recording id to update.
      newChannel - to use in the catalogue.