use of com.hazelcast.spi.ExecutionService in project hazelcast by hazelcast.
the class ClusterHeartbeatManager method init.
/**
* Initializes the {@link ClusterHeartbeatManager}. It will schedule the :
* <ul>
* <li>heartbeat operation to the {@link #getHeartbeatInterval(HazelcastProperties)} interval</li>
* <li>master confirmation to the {@link GroupProperty#MASTER_CONFIRMATION_INTERVAL_SECONDS} interval</li>
* <li>member list publication to the {@link GroupProperty#MEMBER_LIST_PUBLISH_INTERVAL_SECONDS} interval</li>
* </ul>
*/
void init() {
ExecutionService executionService = nodeEngine.getExecutionService();
HazelcastProperties hazelcastProperties = node.getProperties();
executionService.scheduleWithRepetition(EXECUTOR_NAME, new Runnable() {
public void run() {
heartbeat();
}
}, heartbeatIntervalMillis, heartbeatIntervalMillis, TimeUnit.MILLISECONDS);
long masterConfirmationInterval = hazelcastProperties.getSeconds(GroupProperty.MASTER_CONFIRMATION_INTERVAL_SECONDS);
masterConfirmationInterval = (masterConfirmationInterval > 0 ? masterConfirmationInterval : 1);
executionService.scheduleWithRepetition(EXECUTOR_NAME, new Runnable() {
public void run() {
sendMasterConfirmation();
}
}, masterConfirmationInterval, masterConfirmationInterval, TimeUnit.SECONDS);
long memberListPublishInterval = hazelcastProperties.getSeconds(GroupProperty.MEMBER_LIST_PUBLISH_INTERVAL_SECONDS);
memberListPublishInterval = (memberListPublishInterval > 0 ? memberListPublishInterval : 1);
executionService.scheduleWithRepetition(EXECUTOR_NAME, new Runnable() {
public void run() {
sendMemberListToOthers();
}
}, memberListPublishInterval, memberListPublishInterval, TimeUnit.SECONDS);
}
use of com.hazelcast.spi.ExecutionService in project hazelcast by hazelcast.
the class ExecutorServiceTest method testPostRegisteredExecutionCallbackCompletableFuture.
@Test
public void testPostRegisteredExecutionCallbackCompletableFuture() throws Exception {
ExecutionService es = getExecutionService(createHazelcastInstance());
CountDownLatch callableLatch = new CountDownLatch(1);
ExecutorService executorService = Executors.newSingleThreadExecutor();
try {
Future<String> future = executorService.submit(new CountDownLatchAwaitingCallable(callableLatch));
ICompletableFuture<String> completableFuture = es.asCompletableFuture(future);
callableLatch.countDown();
future.get();
CountingDownExecutionCallback<String> callback = new CountingDownExecutionCallback<String>(1);
completableFuture.andThen(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.ExecutionService in project hazelcast by hazelcast.
the class ExecutorServiceTest method testPreregisteredExecutionCallbackCompletableFuture.
/* ############ andThen(Callback) ############ */
@Test
public void testPreregisteredExecutionCallbackCompletableFuture() {
ExecutionService es = getExecutionService(createHazelcastInstance());
CountDownLatch callableLatch = new CountDownLatch(1);
ExecutorService executorService = Executors.newSingleThreadExecutor();
try {
Future<String> future = executorService.submit(new CountDownLatchAwaitingCallable(callableLatch));
CountingDownExecutionCallback<String> callback = new CountingDownExecutionCallback<String>(1);
ICompletableFuture<String> completableFuture = es.asCompletableFuture(future);
completableFuture.andThen(callback);
callableLatch.countDown();
assertOpenEventually(callback.getLatch());
assertEquals(CountDownLatchAwaitingCallable.RESULT, callback.getResult());
} finally {
executorService.shutdown();
}
}
use of com.hazelcast.spi.ExecutionService in project hazelcast by hazelcast.
the class AbstractCacheProxyBase method submitLoadAllTask.
@SuppressWarnings("unchecked")
void submitLoadAllTask(LoadAllTask loadAllTask) {
ExecutionService executionService = nodeEngine.getExecutionService();
final CompletableFutureTask<Object> future = (CompletableFutureTask<Object>) executionService.submit("loadAll-" + nameWithPrefix, loadAllTask);
loadAllTasks.add(future);
future.andThen(new ExecutionCallback() {
@Override
public void onResponse(Object response) {
loadAllTasks.remove(future);
}
@Override
public void onFailure(Throwable t) {
loadAllTasks.remove(future);
getNodeEngine().getLogger(getClass()).warning("Problem in loadAll task", t);
}
});
}
use of com.hazelcast.spi.ExecutionService in project hazelcast by hazelcast.
the class InternalPartitionServiceImpl method init.
@Override
public void init(NodeEngine nodeEngine, Properties properties) {
int partitionTableSendInterval = node.getProperties().getSeconds(GroupProperty.PARTITION_TABLE_SEND_INTERVAL);
if (partitionTableSendInterval <= 0) {
partitionTableSendInterval = 1;
}
ExecutionService executionService = nodeEngine.getExecutionService();
executionService.scheduleWithRepetition(new PublishPartitionRuntimeStateTask(node, this), partitionTableSendInterval, partitionTableSendInterval, TimeUnit.SECONDS);
migrationManager.start();
replicaManager.scheduleReplicaVersionSync(executionService);
}
Aggregations