GS2-Lock
GS2-SDK for Game Engine のリファレンス
ゲームエンジン向けSDK
モデル
EzMutex
ミューテックス
GS2 の提供するミューテックスは再入可能ロックの一種です。
ロックを取得する際にはトランザクションIDを指定し、同一トランザクションIDを指定した場合にのみ再度ロックを取得できます。
参照カウンタを持つため、解放するときには同回数のアンロック処理が必要です。
型 | 説明 | |
---|---|---|
mutexId | string | ミューテックスGRN |
propertyId | string | プロパティID |
transactionId | string | ロックを取得したトランザクションID |
メソッド
get
get
ProfilePtr = std::make_shared<gs2::ez::Profile>(
TCHAR_TO_ANSI(*ClientId),
TCHAR_TO_ANSI(*ClientSecret),
gs2::ez::Gs2BasicReopener()
);
ClientPtr = std::make_shared<gs2::ez::Client>(
*ProfilePtr
);
ProfilePtr->initialize(
[this](gs2::ez::Profile::AsyncInitializeResult r)
{
if (r.getError())
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
}
else
{
AccountCreate();
}
}
);
// Up to this line is the initialization process.
ClientPtr->lock.getMutex(
[](gs2::ez::account::AsyncEzGetMutexResult r)
{
if (r.getError())
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "lock.getMutex failed.");
}
else
{
Item = r.getResult()->getItem();
}
},
ProfilePtr->getGs2Session(),
TCHAR_TO_ANSI("namespace1"), // namespaceName
TCHAR_TO_ANSI("property-0001") // propertyId
);
///////////////////////////////////////////////////////////////
// New Experience (Enabled UniTask)
///////////////////////////////////////////////////////////////
using Gs2.Unity.Util;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
#endif
var profile = new Profile(
clientId: "your client id",
clientSecret: "your client secret",
reopener: new Gs2BasicReopener()
);
await profile.InitializeAsync();
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);
// Up to this line is the initialization process.
{
var domain = gs2.Lock.Namespace(
namespaceName: "namespace1"
).Me(
gameSession: gameSession
).Mutex(
propertyId: "property-0001"
);
var item = await domain.ModelAsync();
}
///////////////////////////////////////////////////////////////
// Legacy Experience
///////////////////////////////////////////////////////////////
using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;
var profile = new Profile(
clientId: "your client id",
clientSecret: "your client secret",
reopener: new Gs2BasicReopener()
);
{
AsyncResult<object> asyncResult = null;
var current = profile.Initialize(
r => { asyncResult = r; }
);
yield return current;
if (asyncResult.Error != null)
{
OnError(asyncResult.Error);
yield break;
}
}
var gs2 = new Gs2.Unity.Client(profile);
// Up to this line is the initialization process.
{
AsyncResult<EzGetResult> asyncResult = null;
var current = gs2.Lock.Get(
callback: r => { asyncResult = r; },
session: session,
namespaceName: "namespace1",
propertyId: "property-0001"
);
yield return current;
if (asyncResult.Error != null)
{
OnError(asyncResult.Error);
yield break;
}
var result = asyncResult.Result;
var item = result.Item;
}
ミューテックスの状態を取得
Request
型 | 必須 | デフォルト | 値の制限 | 説明 | |
---|---|---|---|---|---|
namespaceName | string | ✓ | ~ 32文字 | ネームスペース名 | |
propertyId | string | ✓ | ~ 1024文字 | プロパティID | |
accessToken | string | ✓ | ~ 128文字 | ユーザーID |
Result
型 | 説明 | |
---|---|---|
item | EzMutex | ミューテックス |
lock
lock
ProfilePtr = std::make_shared<gs2::ez::Profile>(
TCHAR_TO_ANSI(*ClientId),
TCHAR_TO_ANSI(*ClientSecret),
gs2::ez::Gs2BasicReopener()
);
ClientPtr = std::make_shared<gs2::ez::Client>(
*ProfilePtr
);
ProfilePtr->initialize(
[this](gs2::ez::Profile::AsyncInitializeResult r)
{
if (r.getError())
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
}
else
{
AccountCreate();
}
}
);
// Up to this line is the initialization process.
ClientPtr->lock.lock(
[](gs2::ez::account::AsyncEzLockResult r)
{
if (r.getError())
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "lock.lock failed.");
}
else
{
Item = r.getResult()->getItem();
}
},
ProfilePtr->getGs2Session(),
TCHAR_TO_ANSI("namespace1"), // namespaceName
TCHAR_TO_ANSI("property-0001"), // propertyId
TCHAR_TO_ANSI("transaction-0001"), // transactionId
100000L // ttl
);
///////////////////////////////////////////////////////////////
// New Experience (Enabled UniTask)
///////////////////////////////////////////////////////////////
using Gs2.Unity.Util;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
#endif
var profile = new Profile(
clientId: "your client id",
clientSecret: "your client secret",
reopener: new Gs2BasicReopener()
);
await profile.InitializeAsync();
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);
// Up to this line is the initialization process.
{
var domain = gs2.Lock.Namespace(
namespaceName: "namespace1"
).Me(
gameSession: gameSession
).Mutex(
propertyId: "property-0001"
);
var result = await domain.LockAsync(
transactionId: "transaction-0001",
ttl: 100000L
);
var item = await result.ModelAsync();
}
///////////////////////////////////////////////////////////////
// Legacy Experience
///////////////////////////////////////////////////////////////
using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;
var profile = new Profile(
clientId: "your client id",
clientSecret: "your client secret",
reopener: new Gs2BasicReopener()
);
{
AsyncResult<object> asyncResult = null;
var current = profile.Initialize(
r => { asyncResult = r; }
);
yield return current;
if (asyncResult.Error != null)
{
OnError(asyncResult.Error);
yield break;
}
}
var gs2 = new Gs2.Unity.Client(profile);
// Up to this line is the initialization process.
{
AsyncResult<EzLockResult> asyncResult = null;
var current = gs2.Lock.Lock(
callback: r => { asyncResult = r; },
session: session,
namespaceName: "namespace1",
propertyId: "property-0001",
transactionId: "transaction-0001",
ttl: 100000L
);
yield return current;
if (asyncResult.Error != null)
{
OnError(asyncResult.Error);
yield break;
}
var result = asyncResult.Result;
var item = result.Item;
}
ロックを取得
ttl で指定した秒数 プロパティID
のリソースをロックします。
ロックする際には トランザクションID
を指定する必要があります。
異なる トランザクションID
による同一 プロパティID
に対するロック取得は失敗します。
同一トランザクションからのロック取得リクエストの場合は参照カウントを増やします。
Request
型 | 必須 | デフォルト | 値の制限 | 説明 | |
---|---|---|---|---|---|
namespaceName | string | ✓ | ~ 32文字 | ネームスペース名 | |
propertyId | string | ✓ | ~ 1024文字 | プロパティID | |
accessToken | string | ✓ | ~ 128文字 | ユーザーID | |
transactionId | string | ✓ | ~ 256文字 | ロックを取得したトランザクションID | |
ttl | long | ✓ | ~ 9223372036854775806 | ロックを取得する期間(秒) |
Result
型 | 説明 | |
---|---|---|
item | EzMutex | ミューテックス |
unlock
unlock
ProfilePtr = std::make_shared<gs2::ez::Profile>(
TCHAR_TO_ANSI(*ClientId),
TCHAR_TO_ANSI(*ClientSecret),
gs2::ez::Gs2BasicReopener()
);
ClientPtr = std::make_shared<gs2::ez::Client>(
*ProfilePtr
);
ProfilePtr->initialize(
[this](gs2::ez::Profile::AsyncInitializeResult r)
{
if (r.getError())
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
}
else
{
AccountCreate();
}
}
);
// Up to this line is the initialization process.
ClientPtr->lock.unlock(
[](gs2::ez::account::AsyncEzUnlockResult r)
{
if (r.getError())
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "lock.unlock failed.");
}
else
{
Item = r.getResult()->getItem();
}
},
ProfilePtr->getGs2Session(),
TCHAR_TO_ANSI("namespace1"), // namespaceName
TCHAR_TO_ANSI("property-0001"), // propertyId
TCHAR_TO_ANSI("transaction-0001") // transactionId
);
///////////////////////////////////////////////////////////////
// New Experience (Enabled UniTask)
///////////////////////////////////////////////////////////////
using Gs2.Unity.Util;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
#endif
var profile = new Profile(
clientId: "your client id",
clientSecret: "your client secret",
reopener: new Gs2BasicReopener()
);
await profile.InitializeAsync();
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);
// Up to this line is the initialization process.
{
var domain = gs2.Lock.Namespace(
namespaceName: "namespace1"
).Me(
gameSession: gameSession
).Mutex(
propertyId: "property-0001"
);
var result = await domain.UnlockAsync(
transactionId: "transaction-0001"
);
var item = await result.ModelAsync();
}
///////////////////////////////////////////////////////////////
// Legacy Experience
///////////////////////////////////////////////////////////////
using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;
var profile = new Profile(
clientId: "your client id",
clientSecret: "your client secret",
reopener: new Gs2BasicReopener()
);
{
AsyncResult<object> asyncResult = null;
var current = profile.Initialize(
r => { asyncResult = r; }
);
yield return current;
if (asyncResult.Error != null)
{
OnError(asyncResult.Error);
yield break;
}
}
var gs2 = new Gs2.Unity.Client(profile);
// Up to this line is the initialization process.
{
AsyncResult<EzUnlockResult> asyncResult = null;
var current = gs2.Lock.Unlock(
callback: r => { asyncResult = r; },
session: session,
namespaceName: "namespace1",
propertyId: "property-0001",
transactionId: "transaction-0001"
);
yield return current;
if (asyncResult.Error != null)
{
OnError(asyncResult.Error);
yield break;
}
var result = asyncResult.Result;
var item = result.Item;
}
ロックを解放
ロックの解放には同一 トランザクションID
から解放する必要があります。
ロックの取得時に再入を行った場合は同一回数ロックの解放を行い、参照カウントが0になったタイミングで実際に解放が行われます。
Request
型 | 必須 | デフォルト | 値の制限 | 説明 | |
---|---|---|---|---|---|
namespaceName | string | ✓ | ~ 32文字 | ネームスペース名 | |
propertyId | string | ✓ | ~ 1024文字 | プロパティID | |
accessToken | string | ✓ | ~ 128文字 | ユーザーID | |
transactionId | string | ✓ | ~ 256文字 | ロックを取得したトランザクションID |
Result
型 | 説明 | |
---|---|---|
item | EzMutex | ミューテックス |