use of com.hazelcast.client.HazelcastClientOfflineException in project hazelcast by hazelcast.
the class ClientTransactionManagerServiceImpl method connect.
public ClientConnection connect() throws Exception {
ClientInvocationServiceImpl invocationService = (ClientInvocationServiceImpl) client.getInvocationService();
long startTimeMillis = System.currentTimeMillis();
long invocationTimeoutMillis = invocationService.getInvocationTimeoutMillis();
ClientConfig clientConfig = client.getClientConfig();
boolean smartRouting = clientConfig.getNetworkConfig().isSmartRouting();
while (client.getLifecycleService().isRunning()) {
try {
ClientConnection connection = client.getConnectionManager().getRandomConnection();
if (connection == null) {
throw throwException(smartRouting);
}
return connection;
} catch (Exception e) {
if (e instanceof HazelcastClientOfflineException) {
throw e;
}
if (System.currentTimeMillis() - startTimeMillis > invocationTimeoutMillis) {
throw newOperationTimeoutException(e, invocationTimeoutMillis, startTimeMillis);
}
}
Thread.sleep(invocationService.getInvocationRetryPauseMillis());
}
throw new HazelcastClientNotActiveException();
}
use of com.hazelcast.client.HazelcastClientOfflineException in project hazelcast by hazelcast.
the class ConfiguredBehaviourTest method testReconnectModeASYNC_clusterDown_clientGetsOfflineExcption.
@Test
public void testReconnectModeASYNC_clusterDown_clientGetsOfflineExcption() {
HazelcastInstance member1 = hazelcastFactory.newHazelcastInstance();
HazelcastInstance member2 = hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
clientConfig.getConnectionStrategyConfig().setReconnectMode(ASYNC);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
IMap<Object, Object> map = client.getMap(randomMapName());
member1.shutdown();
member2.shutdown();
assertTrue(client.getLifecycleService().isRunning());
for (int i = 0; i < 100; i++) {
try {
map.get(randomString());
fail("map.get should throw HazelcastClientOfflineException");
} catch (HazelcastClientOfflineException ignored) {
}
}
}
use of com.hazelcast.client.HazelcastClientOfflineException in project hazelcast by hazelcast.
the class ConfiguredBehaviourTest method testReconnectModeASYNCTwoMembers.
@Test
public void testReconnectModeASYNCTwoMembers() {
hazelcastFactory.newInstances(getConfig(), 2);
CountDownLatch connectedLatch = new CountDownLatch(1);
ClientConfig clientConfig = new ClientConfig();
clientConfig.addListenerConfig(new ListenerConfig((LifecycleListener) event -> {
if (event.getState().equals(CLIENT_CONNECTED)) {
connectedLatch.countDown();
}
}));
clientConfig.getConnectionStrategyConfig().setReconnectMode(ASYNC);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
assertTrue(client.getLifecycleService().isRunning());
assertOpenEventually(connectedLatch);
IMap<Integer, Integer> map = client.getMap(randomMapName());
map.put(1, 5);
hazelcastFactory.shutdownAllMembers();
HazelcastInstance[] instances = hazelcastFactory.newInstances(getConfig(), 2);
assertTrueEventually(() -> {
Set<Member> actualMembers = client.getCluster().getMembers();
Set<Member> expectedMembers = instances[0].getCluster().getMembers();
assertEquals(expectedMembers, actualMembers);
});
assertTrueEventually(() -> {
try {
map.get(1);
} catch (HazelcastClientOfflineException e) {
fail();
}
});
}
use of com.hazelcast.client.HazelcastClientOfflineException in project hazelcast by hazelcast.
the class ClientTransactionManagerServiceImpl method throwException.
private RuntimeException throwException(boolean smartRouting) {
ClientConfig clientConfig = client.getClientConfig();
ClientConnectionStrategyConfig connectionStrategyConfig = clientConfig.getConnectionStrategyConfig();
ClientConnectionStrategyConfig.ReconnectMode reconnectMode = connectionStrategyConfig.getReconnectMode();
if (reconnectMode.equals(ClientConnectionStrategyConfig.ReconnectMode.ASYNC)) {
throw new HazelcastClientOfflineException();
}
if (smartRouting) {
Set<Member> members = client.getCluster().getMembers();
String msg;
if (members.isEmpty()) {
msg = "No address was return by the LoadBalancer since there are no members in the cluster";
} else {
msg = "No address was return by the LoadBalancer. " + "But the cluster contains the following members:" + members;
}
throw new IllegalStateException(msg);
}
throw new IllegalStateException("No active connection is found");
}
Aggregations