Created
April 13, 2016 16:27
-
-
Save mpilone/b6c70fbdd53d3aa4292f93affa013372 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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