Last active
April 10, 2016 05:55
-
-
Save suresk/19f16576ed7cecec6576db261f4659cc to your computer and use it in GitHub Desktop.
Elasticsearch get distributed lock
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
private boolean getLock(String aliasName) | |
{ | |
synchronized (aliasName) | |
{ | |
IndexRequestBuilder indexRequest = elasticClient.prepareIndex(LOCK_DIRECTORY, LOCK_TYPE, aliasName).setSource("{}").setOpType(OpType.CREATE); | |
boolean successful = false; | |
try | |
{ | |
IndexResponse response = indexRequest.get(); | |
successful = response.isCreated(); | |
} | |
catch(Exception e) | |
{ | |
// This means we couldn't get the lock. | |
e.printStackTrace(); | |
} | |
return successful; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment