Dmitry Trofimov
Dmitry Trofimov

Reputation: 513

Gemfire client/server architecture and region lock

I am using client-server Gemfire architecture, several servers share a replicated region with "global" scope.

I have a client, where a client region is defined as follows:

<gfe:client-region id="regionId" name="regionName" shortcut="CACHING_PROXY" />

This client region serves as a proxy for the global region on the servers.

Now, I would like to lock the region from my client while performing some operations so that no other client is able to modify it while the first client is preforming some critical task.

Lock regionLock = clientRegion.getRegionDistributedLock();

Unfortunately I get an exception:

java.lang.IllegalStateException: Only supported for GLOBAL scope, not LOCAL

So, is there any way to lock a region from the client side?

Upvotes: 0

Views: 593

Answers (1)

Dan Smith
Dan Smith

Reputation: 491

Locking a region from the client side isn't supported.

If you want to do multiple operations under a lock, the best thing to do is use a gemfire function and perform those operations on the server side. You can write a gemfire function that obtains the lock, performs your logic, and releases the lock before returning.

You might also consider using transactions instead of a global lock. You can initiate a transaction on the client side.

Upvotes: 2

Related Questions