Enable Leader Election¶
This guide will show you how to enable leader election for your application.
0. Enable leader election in manifest¶
1. Using leader election in your application¶
// Implementation of getJSONFromUrl is left as an exercise for the reader
class Leader {
public static boolean isLeader() {
String electorPath = System.getenv("ELECTOR_PATH");
JSONObject leaderJson = getJSONFromUrl(electorPath);
String leader = leaderJson.getString("name");
String hostname = InetAddress.getLocalHost().getHostname();
return hostname.equals(leader);
}
}