Skip to content

Instantly share code, notes, and snippets.

@gurbuzali
Created December 10, 2013 17:54
Show Gist options
  • Save gurbuzali/7895011 to your computer and use it in GitHub Desktop.
Save gurbuzali/7895011 to your computer and use it in GitHub Desktop.
2.x client reconnect
public class HazelcastClientUtils {
private static HazelcastClient client = null;
public static void init() {
new Thread() {
public void run() {
while (true) {
if (client == null) {
createClient();
continue;
}
if (client.isActive()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
continue;
}
client.getLifecycleService().shutdown();
createClient();
}
}
}.start();
}
private static void createClient() {
final ClientConfig clientConfig = new ClientConfig();
clientConfig.setInitialConnectionAttemptLimit(1);
clientConfig.setReconnectionAttemptLimit(0);
try {
client = HazelcastClient.newHazelcastClient(clientConfig);
} catch (Exception e) {
e.printStackTrace();
}
}
public static IMap getMap(String name) {
return client.getMap(name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment