Class AeronArchive
- All Implemented Interfaces:
AutoCloseable
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAllows for the async establishment of an archive session.static final classCommon configuration properties for communicating with an Aeron archive.static final classSpecialised configuration options for communicating with an Aeron Archive.static enumDescribes state of the client instance. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringIndicates the client is no longer connected to an archive.static final longRepresents a length that has not been set.static final longRepresents a position that has not been set.static final longRepresents a timestamp that has not been set.static final longWhen replaying a live recording, replay the whole stream and follow the live recording.static final longWhen replaying a live recording, replay up to the current limit then stop the replay and end the stream. -
Method Summary
Modifier and TypeMethodDescriptionaddRecordedExclusivePublication(String channel, int streamId) Add anExclusivePublicationand set it up to be recorded.addRecordedPublication(String channel, int streamId) Add aPublicationand set it up to be recorded.longGet the id of the Archive.TheArchiveProxyfor send asynchronous messages to the connected archive.static AeronArchive.AsyncConnectBegin an attempt at creating a connection which can be completed by callingAeronArchive.AsyncConnect.poll()until it returns the client, before complete it will return null.static AeronArchive.AsyncConnectBegin an attempt at creating a connection which can be completed by callingAeronArchive.AsyncConnect.poll()until it returns the client, before complete it will return null.longattachSegments(long recordingId) Attach segments to the beginning of a recording to restore history that was previously detached.voidCheck if an error has been returned for the control session, or if it is no longer connected, and then throw aArchiveExceptionifAeronArchive.Context.errorHandler(ErrorHandler)is not set.voidclose()Notify the archive that this control session is closed, so it can promptly release resources then close the local resources associated with the client.static AeronArchiveconnect()Connect to an Aeron archive using a defaultAeronArchive.Context.static AeronArchiveConnect to an Aeron archive by providing aAeronArchive.Context.context()Get theAeronArchive.Contextused to connect this archive client.Get theControlResponsePollerfor polling additional events on the control channel.longThe control session id allocated for this connection to the archive.longdeleteDetachedSegments(long recordingId) Delete segments which have been previously detached from a recording.voiddetachSegments(long recordingId, long newStartPosition) Detach segments from the beginning of a recording up to the provided new start position.longextendRecording(long recordingId, String channel, int streamId, io.aeron.archive.codecs.SourceLocation sourceLocation) Extend an existing, non-active recording of a channel and stream pairing.longextendRecording(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.longfindLastMatchingRecording(long minRecordingId, String channelFragment, int streamId, int sessionId) Find the last recording that matches the given criteria.longgetMaxRecordedPosition(long recordingId) Get the max recorded position of a recording.longgetRecordingPosition(long recordingId) Get the position recorded for an active recording.longgetStartPosition(long recordingId) Get the start position for a recording.longgetStopPosition(long recordingId) Get the stop position for a recording.longThe last correlation id used for sending a request to the archive via method on this class.intlistRecording(long recordingId, RecordingDescriptorConsumer consumer) List a recording descriptor for a single recording id.intlistRecordings(long fromRecordingId, int recordCount, RecordingDescriptorConsumer consumer) List all recording descriptors from a recording id with a limit of record count.intlistRecordingsForUri(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.intlistRecordingSubscriptions(int pseudoIndex, int subscriptionCount, String channelFragment, int streamId, boolean applyStreamId, RecordingSubscriptionDescriptorConsumer consumer) List active recording subscriptions in the archive.longmigrateSegments(long srcRecordingId, long dstRecordingId) Migrate segments from a source recording and attach them to the beginning or end of a destination recording.Poll the response stream once for an error.intPoll forRecordingSignals for this session which will be dispatched toAeronArchive.Context.recordingSignalConsumer.longpurgeRecording(long recordingId) Purge a stopped recording, i.e.longpurgeSegments(long recordingId, long newStartPosition) Purge (detach and delete) segments from the beginning of a recording up to the provided new start position.Get theRecordingDescriptorPollerfor polling recording descriptors on the control channel.TheRecordingSubscriptionDescriptorPollerfor polling subscription descriptors on the control channel.Replay a length in bytes of a recording from a position and for convenience create aSubscriptionto receive the replay.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 aSubscriptionto receive the replay.replay(long recordingId, String replayChannel, int replayStreamId, ReplayParams replayParams) Replay a recording based upon the parameters set in ReplayParams.longreplicate(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.longreplicate(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.longreplicate(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.static longsegmentFileBasePosition(long startPosition, long position, int termBufferLength, int segmentFileLength) Position of the recorded stream at the base of a segment file.longstartBoundedReplay(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.longstartRecording(String channel, int streamId, io.aeron.archive.codecs.SourceLocation sourceLocation) Start recording a channel and stream pairing.longstartRecording(String channel, int streamId, io.aeron.archive.codecs.SourceLocation sourceLocation, boolean autoStop) Start recording a channel and stream pairing.longstartReplay(long recordingId, long position, long length, String replayChannel, int replayStreamId) Start a replay for a length in bytes of a recording from a position.longstartReplay(long recordingId, String replayChannel, int replayStreamId, ReplayParams replayParams) Start a replay for a recording based upon the parameters set in ReplayParams.state()Returns the state of this client.voidstopAllReplays(long recordingId) Stop all replay sessions for a given recording id or all replays in general.voidstopRecording(long subscriptionId) Stop recording for a subscriptionId that has been returned fromstartRecording(String, int, SourceLocation)orextendRecording(long, String, int, SourceLocation).voidstopRecording(Publication publication) Stop recording a sessionId specific recording that pertains to the givenPublication.voidstopRecording(String channel, int streamId) Stop recording for a channel and stream pairing.voidstopReplay(long replaySessionId) Stop an existing replay session.voidstopReplication(long replicationId) Stop a replication session by id returned fromreplicate(long, long, int, String, String).longtaggedReplicate(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.longtaggedReplicate(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.longtruncateRecording(long recordingId, long position) Truncate a stopped recording to a given position that is less than the stopped position.booleantryStopRecording(long subscriptionId) Try stop a recording for a subscriptionId that has been returned fromstartRecording(String, int, SourceLocation)orextendRecording(long, String, int, SourceLocation).booleantryStopRecording(String channel, int streamId) Try to stop a recording for a channel and stream pairing.booleantryStopRecordingByIdentity(long recordingId) Try stop an active recording by its recording id.booleantryStopReplication(long replicationId) Attempt to stop a replication session by id returned fromreplicate(long, long, int, String, String).voidupdateChannel(long recordingId, String newChannel) Update the channel for a recording, i.e.
-
Field Details
-
NULL_TIMESTAMP
public static final long NULL_TIMESTAMPRepresents 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_POSITIONRepresents 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_LENGTHRepresents a length that has not been set. If null length is provided then replay the whole recorded stream.- See Also:
-
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_FOLLOWWhen replaying a live recording, replay the whole stream and follow the live recording. This will behave the same way as providingNULL_LENGTH- See Also:
-
REPLAY_ALL_AND_STOP
public static final long REPLAY_ALL_AND_STOPWhen 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
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:
closein interfaceAutoCloseable
-
connect
Connect to an Aeron archive using a defaultAeronArchive.Context. This will create a control session.- Returns:
- the newly created Aeron Archive client.
-
connect
Connect to an Aeron archive by providing aAeronArchive.Context. This will create a control session.Before connecting
AeronArchive.Context.conclude()will be called. If an exception occurs thenAeronArchive.Context.close()will be called.- Parameters:
ctx- for connection configuration.- Returns:
- the newly created Aeron Archive client.
-
asyncConnect
Begin an attempt at creating a connection which can be completed by callingAeronArchive.AsyncConnect.poll()until it returns the client, before complete it will return null.- Returns:
- the
AeronArchive.AsyncConnectthat can be polled for completion.
-
asyncConnect
Begin an attempt at creating a connection which can be completed by callingAeronArchive.AsyncConnect.poll()until it returns the client, before complete it will return null.- Parameters:
ctx- for the archive connection.- Returns:
- the
AeronArchive.AsyncConnectthat can be polled for completion.
-
context
Get theAeronArchive.Contextused to connect this archive client.- Returns:
- the
AeronArchive.Contextused 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
TheArchiveProxyfor send asynchronous messages to the connected archive.- Returns:
- the
ArchiveProxyfor send asynchronous messages to the connected archive.
-
controlResponsePoller
Get theControlResponsePollerfor polling additional events on the control channel.- Returns:
- the
ControlResponsePollerfor polling additional events on the control channel.
-
recordingDescriptorPoller
Get theRecordingDescriptorPollerfor polling recording descriptors on the control channel.- Returns:
- the
RecordingDescriptorPollerfor polling recording descriptors on the control channel.
-
recordingSubscriptionDescriptorPoller
TheRecordingSubscriptionDescriptorPollerfor polling subscription descriptors on the control channel.- Returns:
- the
RecordingSubscriptionDescriptorPollerfor polling subscription descriptors on the control channel.
-
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 returnNOT_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 aArchiveExceptionifAeronArchive.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 forRecordingSignals for this session which will be dispatched toAeronArchive.Context.recordingSignalConsumer.- Returns:
- positive value if signals dispatched otherwise 0.
-
addRecordedPublication
Add aPublicationand set it up to be recorded. If this is not the first, i.e.Publication.isOriginal()is true, then anArchiveExceptionwill be thrown and the recording not initiated.This is a sessionId specific recording.
- Parameters:
channel- for the publication.streamId- for the publication.- Returns:
- the
Publicationready for use.
-
addRecordedExclusivePublication
Add anExclusivePublicationand set it up to be recorded.This is a sessionId specific recording.
- Parameters:
channel- for the publication.streamId- for the publication.- Returns:
- the
ExclusivePublicationready 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 tostopRecording(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 tostopRecording(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 callinglistRecording(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 tostopRecording(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 callinglistRecording(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 tostopRecording(long). However, if is autoStop is true then no need to stop the recording unless you want to abort early.
-
stopRecording
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
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:
trueif 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 fromstartRecording(String, int, SourceLocation)orextendRecording(long, String, int, SourceLocation).- Parameters:
subscriptionId- is theSubscription.registrationId()for the recording in the archive.
-
tryStopRecording
public boolean tryStopRecording(long subscriptionId) Try stop a recording for a subscriptionId that has been returned fromstartRecording(String, int, SourceLocation)orextendRecording(long, String, int, SourceLocation).- Parameters:
subscriptionId- is theSubscription.registrationId()for the recording in the archive.- Returns:
trueif 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:
trueif the recording was stopped or false if the recording is not currently active.
-
stopRecording
Stop recording a sessionId specific recording that pertains to the givenPublication.- 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 isNULL_POSITIONthen 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 callingstopReplay(long). The lower 32-bits can be obtained by casting thelongvalue to anint.- Parameters:
recordingId- to be replayed.position- from which the replay should begin orNULL_POSITIONif from the start.length- of the stream to be replayed orREPLAY_ALL_AND_FOLLOWto follow a live recording. UseREPLAY_ALL_AND_STOPto read up the available limit and stop the replay.Long.MAX_VALUEcan 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 isNULL_POSITIONthen 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 callingstopReplay(long). The lower 32-bits can be obtained by casting thelongvalue to anint.- Parameters:
recordingId- to be replayed.position- from which the replay should begin orNULL_POSITIONif from the start.length- of the stream to be replayed orREPLAY_ALL_AND_FOLLOWto follow a live recording. UseREPLAY_ALL_AND_STOPto read up the available limit and stop the replay.Long.MAX_VALUEcan 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 fromstartReplay(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 orAeron.NULL_VALUEfor 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 aSubscriptionto receive the replay. If the position isNULL_POSITIONthen the stream will be replayed from the start.- Parameters:
recordingId- to be replayed.position- from which the replay should begin orNULL_POSITIONif from the start.length- of the stream to be replayed orREPLAY_ALL_AND_FOLLOWto follow a live recording. UseREPLAY_ALL_AND_STOPto read up the available limit and stop the replay.Long.MAX_VALUEcan 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
Subscriptionfor 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
Subscriptionfor 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
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 returnNULL_POSITION.- Parameters:
recordingId- of the active recording for which the position is required.- Returns:
- the recorded position for the active recording or
NULL_POSITIONif 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_POSITIONif 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_VALUEif 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 asRecordingState.INVALIDand 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 ofstartRecording(String, int, SourceLocation)or aextendRecording(long, String, int, SourceLocation). The returned subscription id can be used for passing tostopRecording(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 isAeron.NULL_VALUEthen 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()orcheckForErrorResponse().- Parameters:
srcRecordingId- recording id which must exist in the source archive.dstRecordingId- recording to extend in the destination, otherwiseAeron.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 isAeron.NULL_VALUEthen 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()orcheckForErrorResponse().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, otherwiseAeron.NULL_VALUE.stopPosition- position to stop the replication.NULL_POSITIONto 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 isAeron.NULL_VALUEthen 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()orcheckForErrorResponse().- Parameters:
srcRecordingId- recording id which must exist in the source archive.dstRecordingId- recording to extend in the destination, otherwiseAeron.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 isAeron.NULL_VALUEthen 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()orcheckForErrorResponse().- Parameters:
srcRecordingId- recording id which must exist in the source archive.dstRecordingId- recording to extend in the destination, otherwiseAeron.NULL_VALUE.stopPosition- position to stop the replication.NULL_POSITIONto 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 theReplicationParams.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()orcheckForErrorResponse().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 fromreplicate(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 fromreplicate(long, long, int, String, String).- Parameters:
replicationId- to stop replication for.- Returns:
trueif 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
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.
-