Skip to main content
Version: v1

ReplayController Class

Replay controller object It controls where we start (snapshot, local file, no snapshots) As well as dispatch of ops

Signature

export declare abstract class ReplayController extends ReadDocumentStorageServiceBase

Extends: ReadDocumentStorageServiceBase

Methods

Method Return Type Description
fetchTo(currentOp) number | undefined Returns last op number to fetch from current op Note: this API is called while replay() is in progress - next batch of ops is downloaded in parallel
getStartingOpSequence() Promise<number> Returns sequence number to start processing ops Should be zero if not using snapshot, and snapshot seq# otherwise
initStorage(documentService) Promise<boolean> Initialize reply controller
isDoneFetch(currentOp, lastTimeStamp) boolean Returns true if no more ops should be processed (or downloaded for future processing). It's called at end of each batch with latest op timestamp. Also it's called when there are no more ops available (lastTimeStamp === undefined). If false is returned and there are no more ops, request for more ops is made every 2 seconds. Note: this API is called while replay() is in progress - next batch of ops is downloaded in parallel
replay(emitter, fetchedOps) Promise<void> Replay batch of ops NOTE: new batch of ops is fetched (fetchTo() & isDoneFetch() APIs are called) while this call is in flights

Method Details

fetchTo

Returns last op number to fetch from current op Note: this API is called while replay() is in progress - next batch of ops is downloaded in parallel

Signature

abstract fetchTo(currentOp: number): number | undefined;

Parameters

Parameter Type Description
currentOp number current op

Returns

Return type: number | undefined

getStartingOpSequence

Returns sequence number to start processing ops Should be zero if not using snapshot, and snapshot seq# otherwise

Signature

abstract getStartingOpSequence(): Promise<number>;

Returns

Return type: Promise<number>

initStorage

Initialize reply controller

Signature

abstract initStorage(documentService: IDocumentService): Promise<boolean>;

Parameters

Parameter Type Description
documentService IDocumentService the real document service

Returns

  • Boolean, indicating if controller should be used. If false is returned, caller should fallback to original storage.

Return type: Promise<boolean>

isDoneFetch

Returns true if no more ops should be processed (or downloaded for future processing). It's called at end of each batch with latest op timestamp. Also it's called when there are no more ops available (lastTimeStamp === undefined). If false is returned and there are no more ops, request for more ops is made every 2 seconds. Note: this API is called while replay() is in progress - next batch of ops is downloaded in parallel

Signature

abstract isDoneFetch(currentOp: number, lastTimeStamp?: number): boolean;

Parameters

Parameter Modifiers Type Description
currentOp number current op
lastTimeStamp optional number timestamp of last op (if more ops are available). Undefined otherwise.

Returns

Return type: boolean

replay

Replay batch of ops NOTE: new batch of ops is fetched (fetchTo() & isDoneFetch() APIs are called) while this call is in flights

Signature

abstract replay(emitter: (op: api.ISequencedDocumentMessage[]) => void, fetchedOps: api.ISequencedDocumentMessage[]): Promise<void>;

Parameters

Parameter Type Description
emitter (op: api.ISequencedDocumentMessage[]) => void callback to emit ops
fetchedOps api.ISequencedDocumentMessage[] ops to process

Returns

Return type: Promise<void>