Skip to content

Instantly share code, notes, and snippets.

@mpilone
Created April 13, 2016 16:27
Show Gist options
  • Save mpilone/b6c70fbdd53d3aa4292f93affa013372 to your computer and use it in GitHub Desktop.
Save mpilone/b6c70fbdd53d3aa4292f93affa013372 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");
Lock gatekeeperLock = hazelcast.getLock(KEY_PREFIX + ".lock");
if (gatekeeperLock.tryLock(LOCK_WAIT_PERIOD, TimeUnit.SECONDS)) {
try {
// Logic:
// - Lookup the definition
// - Check the group and acquirer pattern
// - Check for an available permit
// - Issue the permit
}
finally {
if (gatekeeperLock != null) {
gatekeeperLock.unlock();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment