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);
}
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);
}
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();
}
}
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();
}
}
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();
}
}
Aggregations