Skip to main content

SharedObject Class

Helper for implementing ISharedObject with simplified, synchronous summarization and garbage collection.

This API is provided for existing users, but is not recommended for new users.

To use, import via @fluidframework/shared-object-base/legacy.

For more information about our API support guarantees, see here.

Signature

export declare abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents> extends SharedObjectCore<TEvent>

Extends: SharedObjectCore<TEvent>

Type Parameters

Parameter Constraint Default Description
TEvent ISharedObjectEvents ISharedObjectEvents

Remarks

DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead. \

Constructors

Constructor Alerts Description
(constructor)(id, runtime, attributes, telemetryContextPrefix) Beta Constructs a new instance of the SharedObject class

Properties

Property Alerts Modifiers Type Description
serializer Beta readonly IFluidSerializer

Methods

Method Alerts Return Type Description
getAttachSummary(fullTree, trackState, telemetryContext) Beta ISummaryTreeWithStats Generates summary of the channel synchronously. It is called when an attach message for a local channel is generated. In other words, when the channel is being attached to make it visible to other clients.
getGCData(fullGC) Beta IGarbageCollectionData Returns the GC data for this channel. It contains a list of GC nodes that contains references to other GC nodes.
processGCDataCore(serializer) Beta void Calls the serializer over all data in this object that reference other GC nodes. Derived classes must override this to provide custom list of references to other GC nodes.
summarize(fullTree, trackState, telemetryContext, incrementalSummaryContext) Beta Promise<ISummaryTreeWithStats> Generates summary of the channel asynchronously. This should not be called where the channel can be modified while summarization is in progress.
summarizeCore(serializer, telemetryContext, incrementalSummaryContext, fullTree) Beta ISummaryTreeWithStats Gets a form of the object that can be serialized.

Constructor Details

(constructor)

Constructs a new instance of the SharedObject class

This API is provided for existing users, but is not recommended for new users.

For more information about our API support guarantees, see here.

Signature
constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes, 
telemetryContextPrefix: string);

Parameters

Parameter Type Description
id string
runtime IFluidDataStoreRuntime
attributes IChannelAttributes
telemetryContextPrefix string

Property Details

serializer

This API is provided for existing users, but is not recommended for new users.

For more information about our API support guarantees, see here.

Signature
protected get serializer(): IFluidSerializer;

Type: IFluidSerializer

Method Details

getAttachSummary

Generates summary of the channel synchronously. It is called when an attach message for a local channel is generated. In other words, when the channel is being attached to make it visible to other clients.

This API is provided for existing users, but is not recommended for new users.

For more information about our API support guarantees, see here.

Signature
getAttachSummary(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
Remarks

Note: Since the Attach Summary is generated for local channels when making them visible to remote clients, they don't have any previous summaries to compare against. For this reason, the attach summary cannot contain summary handles (paths to sub-trees or blobs). It can, however, contain @fluidframework/protocol-definitions#ISummaryAttachment (handles to blobs uploaded async via the blob manager).

Parameters

Parameter Modifiers Type Description
fullTree optional boolean

A flag indicating whether the attempt should generate a full summary tree without any handles for unchanged subtrees.

Default: false

trackState optional boolean

An optimization for tracking state of objects across summaries. If the state of an object did not change since last successful summary, an @fluidframework/protocol-definitions#ISummaryHandle can be used instead of re-summarizing it. If this is false, the expectation is that you should never send an ISummaryHandle, since you are not expected to track state.

Note: The goal is to remove the trackState and automatically decided whether the handles will be used or not: https://github.com/microsoft/FluidFramework/issues/10455

Default: false

telemetryContext optional ITelemetryContext See ITelemetryContext.

Returns

A summary capturing the current state of the channel.

Return type: ISummaryTreeWithStats

getGCData

Returns the GC data for this channel. It contains a list of GC nodes that contains references to other GC nodes.

This API is provided for existing users, but is not recommended for new users.

For more information about our API support guarantees, see here.

Signature
getGCData(fullGC?: boolean): IGarbageCollectionData;

Parameters

Parameter Modifiers Type Description
fullGC optional boolean true to bypass optimizations and force full generation of GC data.

Returns

Return type: IGarbageCollectionData

processGCDataCore

Calls the serializer over all data in this object that reference other GC nodes. Derived classes must override this to provide custom list of references to other GC nodes.

This API is provided for existing users, but is not recommended for new users.

For more information about our API support guarantees, see here.

Signature
protected processGCDataCore(serializer: IFluidSerializer): void;
Remarks

Serialization itself doesn't matter (the result is ignored). We're tapping into the serialization infrastructure as a way to visit all the content in this content that may reference other objects via handle.

Parameters

Parameter Type Description
serializer IFluidSerializer The "serializer" (more like handle visitor) to use. Implementations should ensure that serialize is called on all handles, as the way to visit them.

summarize

Generates summary of the channel asynchronously. This should not be called where the channel can be modified while summarization is in progress.

This API is provided for existing users, but is not recommended for new users.

For more information about our API support guarantees, see here.

Signature
summarize(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext, incrementalSummaryContext?: IExperimentalIncrementalSummaryContext): Promise<ISummaryTreeWithStats>;

Parameters

Parameter Modifiers Type Description
fullTree optional boolean

flag indicating whether the attempt should generate a full summary tree without any handles for unchanged subtrees. It should only be set to true when generating a summary from the entire container.

Default: false

trackState optional boolean

An optimization for tracking state of objects across summaries. If the state of an object did not change since last successful summary, an @fluidframework/protocol-definitions#ISummaryHandle can be used instead of re-summarizing it. If this is false, the expectation is that you should never send an ISummaryHandle, since you are not expected to track state.

Default: false

Note: The goal is to remove the trackState and automatically decided whether the handles will be used or not: https://github.com/microsoft/FluidFramework/issues/10455

telemetryContext optional ITelemetryContext See ITelemetryContext.
incrementalSummaryContext optional IExperimentalIncrementalSummaryContext

Returns

A summary capturing the current state of the channel.

Return type: Promise<ISummaryTreeWithStats>

summarizeCore

Gets a form of the object that can be serialized.

This API is provided for existing users, but is not recommended for new users.

For more information about our API support guarantees, see here.

Signature
protected abstract summarizeCore(serializer: IFluidSerializer, telemetryContext?: ITelemetryContext, incrementalSummaryContext?: IExperimentalIncrementalSummaryContext, fullTree?: boolean): ISummaryTreeWithStats;

Parameters

Parameter Modifiers Type Description
serializer IFluidSerializer
telemetryContext optional ITelemetryContext
incrementalSummaryContext optional IExperimentalIncrementalSummaryContext
fullTree optional boolean

Returns

A tree representing the snapshot of the shared object.

Return type: ISummaryTreeWithStats