Search in sources :

Example 16 with ExecutionService

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);
}
Also used : HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) ExecutionService(com.hazelcast.spi.ExecutionService)

Example 17 with ExecutionService

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();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) IExecutorService(com.hazelcast.core.IExecutorService) ExecutionService(com.hazelcast.spi.ExecutionService) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with ExecutionService

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();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) IExecutorService(com.hazelcast.core.IExecutorService) ExecutionService(com.hazelcast.spi.ExecutionService) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with ExecutionService

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);
        }
    });
}
Also used : CompletableFutureTask(com.hazelcast.util.executor.CompletableFutureTask) PrefixedDistributedObject(com.hazelcast.core.PrefixedDistributedObject) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) ExecutionService(com.hazelcast.spi.ExecutionService) ExecutionCallback(com.hazelcast.core.ExecutionCallback)

Example 20 with ExecutionService

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);
}
Also used : ExecutionService(com.hazelcast.spi.ExecutionService)

Aggregations

ExecutionService (com.hazelcast.spi.ExecutionService)22 NodeEngine (com.hazelcast.spi.NodeEngine)5 IExecutorService (com.hazelcast.core.IExecutorService)4 HazelcastProperties (com.hazelcast.spi.properties.HazelcastProperties)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ExecutorService (java.util.concurrent.ExecutorService)4 Test (org.junit.Test)4 ILogger (com.hazelcast.logging.ILogger)3 ClientEndpoint (com.hazelcast.client.ClientEndpoint)2 OperationService (com.hazelcast.spi.OperationService)2 ManagedExecutorService (com.hazelcast.util.executor.ManagedExecutorService)2 Executor (java.util.concurrent.Executor)2 MapConfig (com.hazelcast.config.MapConfig)1 ExecutionCallback (com.hazelcast.core.ExecutionCallback)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 LifecycleService (com.hazelcast.core.LifecycleService)1 PrefixedDistributedObject (com.hazelcast.core.PrefixedDistributedObject)1 ClusterService (com.hazelcast.internal.cluster.ClusterService)1