Search in sources :

Example 41 with ExecutionService

use of com.hazelcast.spi.impl.executionservice.ExecutionService in project hazelcast by hazelcast.

the class PromoteLiteMemberOperation method run.

@Override
public void run() throws Exception {
    ILogger logger = getNodeEngine().getLogger(getClass());
    ExecutionService executionService = getNodeEngine().getExecutionService();
    Future<Void> future = executionService.submit(ExecutionService.ASYNC_EXECUTOR, () -> {
        getNodeEngine().getHazelcastInstance().getCluster().promoteLocalLiteMember();
        return null;
    });
    executionService.asCompletableFuture(future).whenCompleteAsync(withTryCatch(logger, (empty, error) -> sendResponse(error != null ? peel(error) : null)), CALLER_RUNS);
}
Also used : AbstractLocalOperation(com.hazelcast.spi.impl.operationservice.AbstractLocalOperation) CALLER_RUNS(com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS) ManagementCenterService(com.hazelcast.internal.management.ManagementCenterService) Future(java.util.concurrent.Future) ILogger(com.hazelcast.logging.ILogger) ExceptionUtil.peel(com.hazelcast.internal.util.ExceptionUtil.peel) ExceptionUtil.withTryCatch(com.hazelcast.internal.util.ExceptionUtil.withTryCatch) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) ILogger(com.hazelcast.logging.ILogger) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService)

Example 42 with ExecutionService

use of com.hazelcast.spi.impl.executionservice.ExecutionService in project hazelcast by hazelcast.

the class InternalPartitionServiceImpl method init.

@Override
public void init(NodeEngine nodeEngine, Properties properties) {
    int partitionTableSendInterval = node.getProperties().getSeconds(ClusterProperty.PARTITION_TABLE_SEND_INTERVAL);
    if (partitionTableSendInterval <= 0) {
        partitionTableSendInterval = 1;
    }
    ExecutionService executionService = nodeEngine.getExecutionService();
    executionService.scheduleWithRepetition(new PublishPartitionRuntimeStateTask(node, this), partitionTableSendInterval, partitionTableSendInterval, SECONDS);
    migrationManager.start();
    replicaManager.scheduleReplicaVersionSync(executionService);
}
Also used : ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService)

Example 43 with ExecutionService

use of com.hazelcast.spi.impl.executionservice.ExecutionService in project hazelcast by hazelcast.

the class ExecutorServiceTest method testPostRegisteredExecutionCallbackCompletableFuture.

@Test
public void testPostRegisteredExecutionCallbackCompletableFuture() throws Exception {
    ExecutionService es = getExecutionService(createHazelcastInstance(smallInstanceConfig()));
    CountDownLatch callableLatch = new CountDownLatch(1);
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    try {
        Future<String> future = executorService.submit(new CountDownLatchAwaitingCallable(callableLatch));
        CompletableFuture<String> completableFuture = es.asCompletableFuture(future);
        callableLatch.countDown();
        future.get();
        CountingDownExecutionCallback<String> callback = new CountingDownExecutionCallback<>(1);
        completableFuture.whenCompleteAsync(callback);
        try {
            assertOpenEventually(callback.getLatch());
            assertEquals(CountDownLatchAwaitingCallable.RESULT, callback.getResult());
        } catch (AssertionError error) {
            System.out.println(callback.getLatch().getCount());
            System.out.println(callback.getResult());
            throw error;
        }
    } finally {
        executorService.shutdown();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) IExecutorService(com.hazelcast.core.IExecutorService) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with ExecutionService

use of com.hazelcast.spi.impl.executionservice.ExecutionService in project hazelcast by hazelcast.

the class ExecutorServiceTest method testPreregisteredExecutionCallbackCompletableFuture.

/* ############ andThen(Callback) ############ */
@Test
public void testPreregisteredExecutionCallbackCompletableFuture() {
    ExecutionService es = getExecutionService(createHazelcastInstance(smallInstanceConfig()));
    CountDownLatch callableLatch = new CountDownLatch(1);
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    try {
        Future<String> future = executorService.submit(new CountDownLatchAwaitingCallable(callableLatch));
        CountingDownExecutionCallback<String> callback = new CountingDownExecutionCallback<>(1);
        InternalCompletableFuture<String> completableFuture = es.asCompletableFuture(future);
        completableFuture.whenCompleteAsync(callback);
        callableLatch.countDown();
        assertOpenEventually(callback.getLatch());
        assertEquals(CountDownLatchAwaitingCallable.RESULT, callback.getResult());
    } finally {
        executorService.shutdown();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) IExecutorService(com.hazelcast.core.IExecutorService) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 45 with ExecutionService

use of com.hazelcast.spi.impl.executionservice.ExecutionService in project hazelcast by hazelcast.

the class ExecutorServiceTest method testMultiPostRegisteredExecutionCallbackCompletableFuture.

@Test
public void testMultiPostRegisteredExecutionCallbackCompletableFuture() throws Exception {
    ExecutionService es = getExecutionService(createHazelcastInstance(smallInstanceConfig()));
    CountDownLatch callableLatch = new CountDownLatch(1);
    CountDownLatch callbackLatch = new CountDownLatch(2);
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    try {
        Future<String> future = executorService.submit(new CountDownLatchAwaitingCallable(callableLatch));
        CompletableFuture<String> completableFuture = es.asCompletableFuture(future);
        callableLatch.countDown();
        future.get();
        CountingDownExecutionCallback<String> callback1 = new CountingDownExecutionCallback<>(callbackLatch);
        completableFuture.whenCompleteAsync(callback1);
        CountingDownExecutionCallback<String> callback2 = new CountingDownExecutionCallback<>(callbackLatch);
        completableFuture.whenCompleteAsync(callback2);
        assertOpenEventually(callbackLatch);
        assertEquals(CountDownLatchAwaitingCallable.RESULT, callback1.getResult());
        assertEquals(CountDownLatchAwaitingCallable.RESULT, callback2.getResult());
    } finally {
        executorService.shutdown();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) IExecutorService(com.hazelcast.core.IExecutorService) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ExecutionService (com.hazelcast.spi.impl.executionservice.ExecutionService)46 ILogger (com.hazelcast.logging.ILogger)10 ManagementCenterService (com.hazelcast.internal.management.ManagementCenterService)7 CALLER_RUNS (com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS)7 ExceptionUtil.peel (com.hazelcast.internal.util.ExceptionUtil.peel)7 ExceptionUtil.withTryCatch (com.hazelcast.internal.util.ExceptionUtil.withTryCatch)7 HazelcastProperties (com.hazelcast.spi.properties.HazelcastProperties)7 Future (java.util.concurrent.Future)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 IExecutorService (com.hazelcast.core.IExecutorService)4 AbstractLocalOperation (com.hazelcast.spi.impl.operationservice.AbstractLocalOperation)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 Node (com.hazelcast.instance.impl.Node)3 NodeEngine (com.hazelcast.spi.impl.NodeEngine)3 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 ExecutorService (java.util.concurrent.ExecutorService)3 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)2