私はこのドキュメントに従っています: http://gemfire.docs.pivotal.io/docs-gemfire/latest/developing/distributed_regions/locking_in_global_regions.html を使用して、グローバルスコープでリージョンを作成し、分散ロックを使用します。
キャッシュ.xml:
<client-cache>
<pool>…definition…</pool>
…
<!--region-attributes For Lock region-->
<region-attributes id="GZ_GLOBAL_REGION_LOCK_ATTRIBUTES" scope="global" pool-name="Zero"/>
…
</client-cache>
gemfire.properties および cache.xml から作成された GemFireCache の後のコード:
private Region<String, Object> getOrCreateLockRegion(GemFireCache gemfireCache) {
Region<String, Object> region = gemfireCache.getRegion(lockRegionName);
if (region == null) {
if(!isUsingClientCache) {
region = createRegionFactory((Cache)gemfireCache, String.class, Object.class, lockRegionAttributesID).create(lockRegionName);
} else {
region = createClientRegionFactory((ClientCache) gemfireCache, String.class, Object.class, lockRegionAttributesID).create(lockRegionName);
}
}
return region;
}
protected <K, V> RegionFactory<K, V> createRegionFactory(Cache gemfireCache, Class<K> keyClass, Class<V> valueClass, String regionAttributeRefID) {
return gemfireCache
.<K, V>createRegionFactory(regionAttributeRefID)
.setKeyConstraint(keyClass)
.setValueConstraint(valueClass);
}
protected <K, V> ClientRegionFactory<K, V> createClientRegionFactory(ClientCache gemfireCache, Class<K> keyClass, Class<V> valueClass, String regionAttributeRefID) {
return gemfireCache
.<K, V>createClientRegionFactory(regionAttributeRefID)
.setKeyConstraint(keyClass)
.setValueConstraint(valueClass);
}
これで のリージョンが得られるScope.Global
ので、region.getDistributedLock(“entrykey”); を呼び出すことができると思います。次に、インスタンス間で調整するためのロックを設定します。
しかし、私が電話したときgetDistributedLock
、私はIllegalStateException: only supported for GLOBAL scope, not LOCAL
そして、ClientRegionFactoryImpl のコンストラクターは、リージョン属性で構成されているものに関係なく、スコープをローカルに強制することがわかりました。それを上書きする API がありません。この行: https://github.com/apache/incubator-geode/blob/develop/geode-core/src/main/java/org/apache/geode/cache/client/internal/ClientRegionFactoryImpl.java#L85
問題は、クライアント サーバー DS 構成を使用している場合、クライアントから分散ロックを使用することになっているのでしょうか? そうでない場合、必要に応じてクライアントを相互にロックして同期させるにはどうすればよいですか?