Created
December 10, 2013 17:54
-
-
Save gurbuzali/7895011 to your computer and use it in GitHub Desktop.
2.x client reconnect
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 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