Search in sources :

Example 16 with ExecutionService

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

the class CacheServiceTest method setup.

@Before
public void setup() {
    // setup mocks
    ExecutionService executionService = mock(ExecutionService.class);
    ManagedExecutorService executorService = mock(ManagedExecutorService.class);
    when(executionService.getExecutor(anyString())).thenReturn(executorService);
    mockNodeEngine = Mockito.mock(NodeEngine.class);
    when(mockNodeEngine.getLogger(any(Class.class))).thenReturn(Logger.getLogger(CacheServiceTest.class));
    when(mockNodeEngine.getExecutionService()).thenReturn(executionService);
    latch = new CountDownLatch(1);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) ManagedExecutorService(com.hazelcast.internal.util.executor.ManagedExecutorService) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) CountDownLatch(java.util.concurrent.CountDownLatch) Before(org.junit.Before)

Example 17 with ExecutionService

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

the class CacheProxySupport method createAndSubmitLoadAllTask.

@SuppressWarnings("unchecked")
protected void createAndSubmitLoadAllTask(Set<Data> keysData, boolean replaceExistingValues, CompletionListener completionListener) {
    try {
        CacheProxyLoadAllTask loadAllTask = new CacheProxyLoadAllTask(getNodeEngine(), operationProvider, keysData, replaceExistingValues, completionListener, getServiceName());
        ExecutionService executionService = getNodeEngine().getExecutionService();
        final CompletableFutureTask<Object> future = (CompletableFutureTask<Object>) executionService.submit("loadAll-" + nameWithPrefix, loadAllTask);
        loadAllTasks.add(future);
        future.whenCompleteAsync((response, t) -> {
            loadAllTasks.remove(future);
            if (t != null) {
                logger.warning("Problem in loadAll task", t);
            }
        });
    } catch (Exception e) {
        if (completionListener != null) {
            completionListener.onException(e);
        }
        throw new CacheException(e);
    }
}
Also used : CompletableFutureTask(com.hazelcast.internal.util.executor.CompletableFutureTask) CacheException(javax.cache.CacheException) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException)

Example 18 with ExecutionService

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

the class ClientEngineImpl method newClientExecutor.

private Executor newClientExecutor() {
    // if user code deployment is enabled, we need more thread per core since operations can do blocking tasks
    // to load classes from other members
    boolean userCodeDeploymentEnabled = nodeEngine.getConfig().getUserCodeDeploymentConfig().isEnabled();
    int threadsPerCore = userCodeDeploymentEnabled ? BLOCKING_THREADS_PER_CORE : THREADS_PER_CORE;
    final ExecutionService executionService = nodeEngine.getExecutionService();
    int coreSize = RuntimeAvailableProcessors.get();
    int threadCount = node.getProperties().getInteger(ClusterProperty.CLIENT_ENGINE_THREAD_COUNT);
    if (threadCount <= 0) {
        threadCount = coreSize * threadsPerCore;
    }
    logger.finest("Creating new client executor with threadCount=" + threadCount);
    // to load classes from other members
    if (userCodeDeploymentEnabled) {
        return executionService.register(ExecutionService.CLIENT_EXECUTOR, threadCount, coreSize * EXECUTOR_QUEUE_CAPACITY_PER_CORE, ExecutorType.CONCRETE);
    }
    String name = ExecutionService.CLIENT_EXECUTOR;
    ClassLoader classLoader = nodeEngine.getConfigClassLoader();
    String hzName = nodeEngine.getHazelcastInstance().getName();
    String internalName = name.substring("hz:".length());
    String threadNamePrefix = createThreadPoolName(hzName, internalName);
    UnblockablePoolExecutorThreadFactory factory = new UnblockablePoolExecutorThreadFactory(threadNamePrefix, classLoader);
    return executionService.register(ExecutionService.CLIENT_EXECUTOR, threadCount, coreSize * EXECUTOR_QUEUE_CAPACITY_PER_CORE, factory);
}
Also used : UnblockablePoolExecutorThreadFactory(com.hazelcast.internal.util.executor.UnblockablePoolExecutorThreadFactory) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService)

Example 19 with ExecutionService

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

the class AbstractBlockingService method init.

@Override
public final void init(NodeEngine nodeEngine, Properties properties) {
    this.raftService = nodeEngine.getService(RaftService.SERVICE_NAME);
    ExecutionService executionService = nodeEngine.getExecutionService();
    executionService.scheduleWithRepetition(new ExpireWaitKeysPeriodicTask(), WAIT_TIMEOUT_TASK_PERIOD_MILLIS, WAIT_TIMEOUT_TASK_PERIOD_MILLIS, MILLISECONDS);
    initImpl();
}
Also used : ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService)

Example 20 with ExecutionService

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

the class MetadataRaftGroupManager method scheduleDiscoverInitialCPMembersTask.

private void scheduleDiscoverInitialCPMembersTask(boolean terminateOnDiscoveryFailure) {
    DiscoverInitialCPMembersTask task = new DiscoverInitialCPMembersTask(terminateOnDiscoveryFailure);
    currentDiscoveryTask = task;
    ExecutionService executionService = nodeEngine.getExecutionService();
    executionService.schedule(CP_SUBSYSTEM_MANAGEMENT_EXECUTOR, task, DISCOVER_INITIAL_CP_MEMBERS_TASK_DELAY_MILLIS, MILLISECONDS);
}
Also used : ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService)

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