GS2-Lock SDK for Game Engine API リファレンス

モデル

EzMutex

ミューテックス GS2 の提供するミューテックスは再入可能ロックの一種です。

ロックを取得する際にはトランザクションIDを指定し、同一トランザクションIDを指定した場合にのみ再度ロックを取得できます。 参照カウンタを持つため、解放するときには同回数のアンロック処理が必要です。

必須デフォルト値の制限説明
mutexIdstring~ 1024文字ミューテックスGRN
propertyIdstring~ 1024文字プロパティID
transactionIdstring~ 256文字ロックを取得したトランザクションID

メソッド

get

ミューテックスの状態を取得

Request

必須デフォルト値の制限説明
namespaceNamestring~ 32文字ネームスペース名
propertyIdstring~ 1024文字プロパティID
accessTokenstring~ 128文字ユーザーID

Result

説明
itemEzMutexミューテックス

実装例

    var domain = gs2.Lock.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Mutex(
        propertyId: "property-0001"
    );
    var item = await domain.ModelAsync();
    var domain = gs2.Lock.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Mutex(
        propertyId: "property-0001"
    );
    var future = domain.Model();
    yield return future;
    var item = future.Result;
    const auto Domain = Gs2->Lock->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        GameSession
    )->Mutex(
        "property-0001" // propertyId
    );
    const auto Future = Domain->Model();
    Future->StartSynchronousTask();
    if (Future->GetTask().IsError())
    {
        return false;
    }
値の変更イベントハンドリング
    var domain = gs2.Lock.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Mutex(
        propertyId: "property-0001"
    );
    
    // イベントハンドリングを開始
    var callbackId = domain.Subscribe(
        value => {
            // 値が変化した時に呼び出される
            // value には変更後の値が渡ってくる
        }
    );

    // イベントハンドリングを停止
    domain.Unsubscribe(callbackId);
    var domain = gs2.Lock.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Mutex(
        propertyId: "property-0001"
    );
    var future = domain.Model();
    yield return future;
    var item = future.Result;
    const auto Domain = Gs2->Lock->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        GameSession
    )->Mutex(
        "property-0001" // propertyId
    );
    
    // イベントハンドリングを開始
    const auto CallbackId = Domain->Subscribe(
        [](TSharedPtr<Gs2::Lock::Model::FMutex> value) {
            // 値が変化した時に呼び出される
            // value には変更後の値が渡ってくる
        }
    );

    // イベントハンドリングを停止
    Domain->Unsubscribe(CallbackId);

lock

ロックを取得

ttl で指定した秒数 プロパティID のリソースをロックします。 ロックする際には トランザクションID を指定する必要があります。 異なる トランザクションID による同一 プロパティID に対するロック取得は失敗します。 同一トランザクションからのロック取得リクエストの場合は参照カウントを増やします。

Request

必須デフォルト値の制限説明
namespaceNamestring~ 32文字ネームスペース名
propertyIdstring~ 1024文字プロパティID
accessTokenstring~ 128文字ユーザーID
transactionIdstring~ 256文字ロックを取得したトランザクションID
ttllong~ 9223372036854775805ロックを取得する期間(秒)

Result

説明
itemEzMutexミューテックス

実装例

    var domain = gs2.Lock.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Mutex(
        propertyId: "property-0001"
    );
    var result = await domain.LockAsync(
        transactionId: "transaction-0001",
        ttl: 100000L
    );
    var item = await result.ModelAsync();
    var domain = gs2.Lock.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Mutex(
        propertyId: "property-0001"
    );
    var future = domain.LockFuture(
        transactionId: "transaction-0001",
        ttl: 100000L
    );
    yield return future;
    if (future.Error != null)
    {
        onError.Invoke(future.Error, null);
        yield break;
    }
    var future2 = future.Result.Model();
    yield return future2;
    if (future2.Error != null)
    {
        onError.Invoke(future2.Error, null);
        yield break;
    }
    var result = future2.Result;
    const auto Domain = Gs2->Lock->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        GameSession
    )->Mutex(
        "property-0001" // propertyId
    );
    const auto Future = Domain->Lock(
        "transaction-0001", // transactionId
        100000L // ttl
    );
    Future->StartSynchronousTask();
    if (Future->GetTask().IsError())
    {
        return false;
    }

    // obtain changed values / result values
    const auto Future2 = Future->GetTask().Result()->Model();
    Future2->StartSynchronousTask();
    if (Future2->GetTask().IsError())
    {
        return Future2->GetTask().Error();
    }
    const auto Result = Future2->GetTask().Result();

unlock

ロックを解放

ロックの解放には同一 トランザクションID から解放する必要があります。 ロックの取得時に再入を行った場合は同一回数ロックの解放を行い、参照カウントが0になったタイミングで実際に解放が行われます。

Request

必須デフォルト値の制限説明
namespaceNamestring~ 32文字ネームスペース名
propertyIdstring~ 1024文字プロパティID
accessTokenstring~ 128文字ユーザーID
transactionIdstring~ 256文字ロックを取得したトランザクションID

Result

説明
itemEzMutexミューテックス

実装例

    var domain = gs2.Lock.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Mutex(
        propertyId: "property-0001"
    );
    var result = await domain.UnlockAsync(
        transactionId: "transaction-0001"
    );
    var domain = gs2.Lock.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Mutex(
        propertyId: "property-0001"
    );
    var future = domain.UnlockFuture(
        transactionId: "transaction-0001"
    );
    yield return future;
    if (future.Error != null)
    {
        onError.Invoke(future.Error, null);
        yield break;
    }
    const auto Domain = Gs2->Lock->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        GameSession
    )->Mutex(
        "property-0001" // propertyId
    );
    const auto Future = Domain->Unlock(
        "transaction-0001" // transactionId
    );
    Future->StartSynchronousTask();
    if (Future->GetTask().IsError())
    {
        return false;
    }
    const auto Result = Future->GetTask().Result();