Search in sources :

Example 1 with TargetDisconnectedException

use of com.hazelcast.spi.exception.TargetDisconnectedException in project hazelcast by hazelcast.

the class ClientInvocation method notifyException.

public void notifyException(Throwable exception) {
    if (!lifecycleService.isRunning()) {
        clientInvocationFuture.complete(new HazelcastClientNotActiveException(exception.getMessage(), exception));
        return;
    }
    if ((isBindToSingleConnection() && exception instanceof IOException) || System.currentTimeMillis() > retryTimeoutPointInMillis) {
        clientInvocationFuture.complete(exception);
        return;
    }
    if (isRetrySafeException(exception) || invocationService.isRedoOperation() || (exception instanceof TargetDisconnectedException && clientMessage.isRetryable())) {
        try {
            ClientExecutionServiceImpl executionServiceImpl = (ClientExecutionServiceImpl) this.executionService;
            executionServiceImpl.schedule(this, RETRY_WAIT_TIME_IN_SECONDS, TimeUnit.SECONDS);
        } catch (RejectedExecutionException e) {
            if (logger.isFinestEnabled()) {
                logger.finest("Retry could not be scheduled ", e);
            }
            clientInvocationFuture.complete(exception);
        }
        return;
    }
    clientInvocationFuture.complete(exception);
}
Also used : HazelcastClientNotActiveException(com.hazelcast.client.HazelcastClientNotActiveException) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 2 with TargetDisconnectedException

use of com.hazelcast.spi.exception.TargetDisconnectedException in project hazelcast by hazelcast.

the class ClientClusterStateTest method testClusterShutdownDuringMapPutAll.

@Test
public void testClusterShutdownDuringMapPutAll() {
    warmUpPartitions(instances);
    waitAllForSafeState(instances);
    HazelcastInstance client = factory.newHazelcastClient();
    final IMap<Object, Object> map = client.getMap(randomMapName());
    final HashMap values = new HashMap<Double, Double>();
    for (int i = 0; i < 1000; i++) {
        double value = Math.random();
        values.put(value, value);
    }
    final int numThreads = 10;
    final CountDownLatch threadsFinished = new CountDownLatch(numThreads);
    final CountDownLatch threadsStarted = new CountDownLatch(numThreads);
    ExecutorService executor = Executors.newCachedThreadPool();
    for (int i = 0; i < numThreads; i++) {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                ILogger logger = Logger.getLogger(getClass());
                threadsStarted.countDown();
                logger.info("putAll thread started");
                while (true) {
                    try {
                        map.putAll(values);
                        Thread.sleep(100);
                    } catch (IllegalStateException e) {
                        logger.warning("Expected exception for Map putAll during cluster shutdown:", e);
                        break;
                    } catch (TargetDisconnectedException e) {
                        logger.warning("Expected exception for Map putAll during cluster shutdown:", e);
                        break;
                    } catch (InterruptedException e) {
                    // do nothing
                    }
                }
                threadsFinished.countDown();
                logger.info("putAll thread finishing. Current finished thread count is:" + (numThreads - threadsFinished.getCount()));
            }
        });
    }
    try {
        assertTrue("All threads could not be started", threadsStarted.await(1, TimeUnit.MINUTES));
    } catch (InterruptedException e) {
        fail("All threads could not be started due to InterruptedException. Could not start " + threadsStarted.getCount() + " threads out of " + numThreads);
    }
    instance.getCluster().shutdown();
    executor.shutdown();
    try {
        assertTrue("All threads could not be finished", threadsFinished.await(2, TimeUnit.MINUTES));
    } catch (InterruptedException e) {
        fail("All threads could not be finished due to InterruptedException. Could not finish " + threadsFinished.getCount() + " threads out of " + numThreads);
    } finally {
        executor.shutdownNow();
    }
}
Also used : HashMap(java.util.HashMap) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorService(java.util.concurrent.ExecutorService) ILogger(com.hazelcast.logging.ILogger) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

TargetDisconnectedException (com.hazelcast.spi.exception.TargetDisconnectedException)2 HazelcastClientNotActiveException (com.hazelcast.client.HazelcastClientNotActiveException)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 ILogger (com.hazelcast.logging.ILogger)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Test (org.junit.Test)1