Created
April 13, 2016 16:37
-
-
Save mpilone/517005f85dc6632de6467f586deb1897 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
public boolean tryAcquire(int timeout) { | |
SemaphorePermit permit = new SemaphorePermit(semaphoreName, groupName, | |
acquirerName, null); | |
// Delegate to the gatekeeper which enforces the permit rules based | |
// on the semaphore definition. The gatekeeper might be a local library | |
// or a call to a remote service. | |
permit = gatekeeperGateway.tryAcquire(permit); | |
Date expirationDate = permit.getExpirationDate(); | |
if (expirationDate == null) { | |
// We didn't get the permit. Either sleep or expire the attempt. | |
// ... | |
} | |
else { | |
// We got the permit. Return true. | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment