Skip to content

Instantly share code, notes, and snippets.

@mpilone
Created April 13, 2016 16:36
Show Gist options
  • Save mpilone/194242200e509be8d1acb0365e3b2078 to your computer and use it in GitHub Desktop.
Save mpilone/194242200e509be8d1acb0365e3b2078 to your computer and use it in GitHub Desktop.
final static String KEY_PREFIX = "gatekeeper";
ConcurrentMap definitionMap = hazelcast.getMap(KEY_PREFIX + ".semaphoreDefinitions");
ConcurrentMap permitMap = hazelcast.getMap(KEY_PREFIX + ".semaphorePermits");
// Logic:
// - Lookup the definition
// - Check the group and acquirer pattern
// - Check for an available permit
// - Issue the permit
if (!permitMap.replace(semaphoreName, origPermits, updatedPermits)) {
throw new OptimisticLockingFailureException("Conflict "
+ "while updating semaphore permits.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment