PendingStateManager Class

Packages > @fluidframework/container-runtime > PendingStateManager

PendingStateManager is responsible for maintaining the messages that have not been sent or have not yet been acknowledged by the server. It also maintains the batch information for both automatically and manually flushed batches along with the messages. When the Container reconnects, it replays the pending states, which includes setting the FlushMode, manual flushing of messages and triggering resubmission of unacked ops.

It verifies that all the ops are acked, are received in the right order and batch information is correct.

Signature:

export declare class PendingStateManager 

Constructors

List of constructors for this class
Constructor Modifiers Description
(constructor)(containerRuntime, applyStashedOp, initialState) Constructs a new instance of the PendingStateManager class

Methods

List of methods on this class
Method Modifiers Description
applyStashedOpsAt(seqNum) Applies stashed ops at their reference sequence number so they are ready to be ACKed or resubmitted
getLocalState()
hasPendingMessages() Called to check if there are any pending messages in the pending state queue.
onFlush() Called when flush() is called on the ContainerRuntime to manually flush messages.
onFlushModeUpdated(flushMode) Called when the FlushMode is updated. Adds the FlushMode to the pending state queue.
onSubmitMessage(type, clientSequenceNumber, referenceSequenceNumber, content, localOpMetadata, opMetadata) Called when a message is submitted locally. Adds the message and the associated details to the pending state queue.
processMessage(message, local) Processes a local message once it's ack'd by the server to verify that there was no data corruption and that the batch information was preserved for batch messages. Also process remote messages that might have been sent from a previous container.
replayPendingStates() Called when the Container's connection state changes. If the Container gets connected, it replays all the pending states in its queue. This includes setting the FlushMode and triggering resubmission of unacked ops.

Constructors

PendingStateManager.(constructor)

Constructs a new instance of the PendingStateManager class

Signature:

constructor(containerRuntime: ContainerRuntime, applyStashedOp: (type: any, content: any) => Promise<unknown>, initialState: IPendingLocalState | undefined);

Parameters

List of parameters
Parameter Type Description
containerRuntime ContainerRuntime
applyStashedOp (type: any, content: any) => Promise
initialState IPendingLocalState | undefined

Methods

applyStashedOpsAt

Applies stashed ops at their reference sequence number so they are ready to be ACKed or resubmitted

Signature:

applyStashedOpsAt(seqNum: number): Promise<void>;

Parameters

List of parameters
Parameter Type Description
seqNum number

Returns:

Promise<void>

getLocalState

Signature:

getLocalState(): IPendingLocalState | undefined;

Returns:

IPendingLocalState | undefined

hasPendingMessages

Called to check if there are any pending messages in the pending state queue.

Signature:

hasPendingMessages(): boolean;

Returns:

boolean

A boolean indicating whether there are messages or not.

onFlush

Called when flush() is called on the ContainerRuntime to manually flush messages.

Signature:

onFlush(): void;

Returns:

void

onFlushModeUpdated

Called when the FlushMode is updated. Adds the FlushMode to the pending state queue.

Signature:

onFlushModeUpdated(flushMode: FlushMode): void;

Parameters

List of parameters
Parameter Type Description
flushMode FlushMode The flushMode that was updated.

Returns:

void

onSubmitMessage

Called when a message is submitted locally. Adds the message and the associated details to the pending state queue.

Signature:

onSubmitMessage(type: ContainerMessageType, clientSequenceNumber: number, referenceSequenceNumber: number, content: any, localOpMetadata: unknown, opMetadata: Record<string, unknown> | undefined): void;

Parameters

List of parameters
Parameter Type Description
type ContainerMessageType The container message type.
clientSequenceNumber number The clientSequenceNumber associated with the message.
referenceSequenceNumber number
content any The message content.
localOpMetadata unknown The local metadata associated with the message.
opMetadata Record | undefined

Returns:

void

processMessage

Processes a local message once it’s ack’d by the server to verify that there was no data corruption and that the batch information was preserved for batch messages. Also process remote messages that might have been sent from a previous container.

Signature:

processMessage(message: ISequencedDocumentMessage, local: boolean): {
        localAck: boolean;
        localOpMetadata: unknown;
    };

Parameters

List of parameters
Parameter Type Description
message ISequencedDocumentMessage The messsage that got ack'd and needs to be processed.
local boolean

Returns:

{ localAck: boolean; localOpMetadata: unknown; }

replayPendingStates

Called when the Container’s connection state changes. If the Container gets connected, it replays all the pending states in its queue. This includes setting the FlushMode and triggering resubmission of unacked ops.

Signature:

replayPendingStates(): void;

Returns:

void