IConcertClientDataStore

Interacts with a key/value store shared by one or more clients connected to a Concert session.

Windows
MacOS
Linux

References

Module

ConcertSyncClient

Header

/Engine/Plugins/Developer/Concert/ConcertSync/ConcertSyncClient/Source/ConcertSyncClient/Public/IConcertClientDataStore.h

Include

#include "IConcertClientDataStore.h"

Syntax

class IConcertClientDataStore

Remarks

Interacts with a key/value store shared by one or more clients connected to a Concert session. The store is like a TMap<FName, Blob>. The implementation requires the 'Blob' to be defined as a USTRUCT() structure, which provides the serialization mechanism. The system automatically wraps primitive types like integers, floating, bool and strings into USTRUCT() for you. If you need to store container types like TArray<>, TMap<> or TSet<> or custom types, you will need to put them into a USTRUCT() struct similare to the example below showing how to use custom types.

The store is type safe, in the sense that a client cannot transmute the type of a stored value into another type. For example if the value "foo" is an integer, it cannot be transformed into a double later one.

The store is used to share variables with other clients. For example, it can be used for to manage a distributed counter like "cameraId" to uniquely number cameras created concurrently by multiple users while editing a level.

The store API returns TFuture to implement asynchronous or blocking operations. While is far more easier to use the blocking operations model, i.e. waiting on future to gets its result (TFuture::Get()) in the caller thread, it is recommended to use the asynchronous API and use continuations. Since the store implies network operation, expect latency and avoid waiting the response in a thread like the game thread.

To implement a sequence of operations using the store asynchronously inside a single thread (game thread), it is recommended to implement it as a finite state machine 'ticked' at each loop.

Example: Initialize a shared value. The code snippet below shows how multiple clients can concurrently create or sync a shared integer value to be ready to compare exchange it later to generate a new unique id.

voidMyClass::InitCameraIdAsync(){FNameKey(TEXT("CameraId"));//Thesharedvariablename.int64Value=0;//Theinitialvalueifnotexistingyet.//Trytofetchthespecifiedkeyvalue(abasictype),ifthekeydoesn'texist,additwiththespecifiedvalue.GetDataStore().FetchOrAdd(Key,Value).Next([this,Key,Value](constTConcertDataStoreResult<int64>&Result){//Ifthekeywasaddedorfetched.if(Result){CameraId=Result.GetValue();bCameraIdAcquired=true;}else{//Thekeyalreadyexisted,butthevaluewasnotaint64.check(Response.GetCode()==EConcertDataStoreResultCode::TypeMismatch);}});

Example: Use custom types. The code snippet below shows how a user can use a custom type with the data store. For simplicity, the example block until the result is available and assumes the all operations succeeded.

USTRUCT()structFPoint2D{int32x;int32y;};USTRUCT()structFShape{TArray<FPoint2D>Points;};voidExample(){FNameKey(TEXT("Point"));FPoint2DPosition{0,0}GetDataStore().FetchOrAdd(Key,Position).Get();UE_LOG(MyLogCat,Display,TEXT("%d"),Session->GetDataStore().FetchAs<FPoint2D>(Key).Get().GetValue().x);//Prints0GetDataStore().CompareExchange(Key,Position,Point2D{10,20}).Get();UE_LOG(MyLogCat,Display,TEXT("%d"),Session->GetDataStore().FetchAs<FPoint2D>(Key).Get().GetValue().x);//Prints10//Storeashape.FShapeShape;Shape.Points.Add(FPoint2D(0,0));Shape.Points.Add(FPoint2D(10,10));Shape.Points.Add(FPoint2D(0,10));GetDataStore().FetchOrAdd(FName(TEXT("Triangle"),Shape).Get();}

Destructors

Name Description

Public function Virtual

~IConcertClientDataStore()

Destructor.

Functions

Name Description

Public function

TFuture< TCo...

 

CompareExchange

(
    const FName& Key,
    const T& Expected,
    const T& Desired
)

Exchanges the stored value to Desired if a stored value corresponding to Key exists, has the same type and its value is equal to Expected, otherwise, the operation fails.

Public function Const

TFuture< TCo...

 

FetchAs

(
    const FName& Key
)

Looks up the specified key, if found and types match, fetches the corresponding value.

Public function

TFuture< TCo...

 

FetchOrAdd

(
    const FName& Key,
    const T& InitialValue
)

Searches the store for the specified key, if not found, adds a new key/value pair, otherwise, if the stored value type matches the initial value type, fetches the stored value.

Protected function

TFuture< FCo...

 

InternalCompareExchange

(
    const FName& Key,
    const UScriptStruct* Type,
    const FName& TypeName,
    const void* Expected,
    const void* Desired
)

Compares and exchanges a key value from the store.

Protected function Const

TFuture< FCo...

 

InternalFetchAs

(
    const FName& Key,
    const UScriptStruct* Type,
    const FName& TypeName
)

Fetches a key value from the store.

Protected function

TFuture< FCo...

 

InternalFetchOrAdd

(
    const FName& Key,
    const UScriptStruct* Type,
    const FName& TypeName,
    const void* Payload
)

Fetches or adds a key/value in the store.

Protected function

void

 

InternalRegisterChangeNotificationHandler

(
    const FName& Key,
    const FName& TypeName,
    const FChangeNotificationHandler& ...,
    EConcertDataStoreChangeNotification...
)

Registers a delegate invoked when the specified key is added or modified.

Protected function

void

 

InternalUnregisterChangeNotificationHandler

(
    const FName& Key
)

Unregisters the delegate corresponding to the specified key (if any) to stop receiving the key change notifications.

Public function

void

 

RegisterChangeNotificationHandler

(
    const FName& InKey,
    const TFunction< void&...,
    EConcertDataStoreChangeNotification...
)

Registers(or replaces) a handler invoked every time another client successfully adds or updates the specified key.

Public function

void

 

UnregisterChangeNotificationHander

(
    const FName& Key
)

Unregisters the function callback corresponding to the specified key (if any) to stop receiving the key change notifications.

Typedefs

Name

Description

FChangeNotificationHandler

The function called back when the data store is updated by another client.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss