Search in sources :

Example 11 with ExecutionService

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

the class RunScriptOperation method run.

@Override
public void run() {
    final ILogger logger = getNodeEngine().getLogger(getClass());
    final ExecutionService executionService = getNodeEngine().getExecutionService();
    Future<Object> future = executionService.submit(ExecutionService.MC_EXECUTOR, () -> {
        ManagementCenterConfig managementCenterConfig = getNodeEngine().getConfig().getManagementCenterConfig();
        if (!managementCenterConfig.isScriptingEnabled()) {
            throw new AccessControlException("Using ScriptEngine is not allowed on this Hazelcast member.");
        }
        ScriptEngineManager scriptEngineManager = ScriptEngineManagerContext.getScriptEngineManager();
        ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(engine);
        if (scriptEngine == null) {
            throw new IllegalArgumentException("Could not find ScriptEngine named '" + engine + "'." + " Please add the corresponding ScriptEngine to the classpath of this Hazelcast member");
        }
        scriptEngine.put("hazelcast", getNodeEngine().getHazelcastInstance());
        try {
            return scriptEngine.eval(script);
        } catch (ScriptException e) {
            // ScriptException's cause is not serializable - we don't need the cause
            HazelcastException hazelcastException = new HazelcastException(e.getMessage());
            hazelcastException.setStackTrace(e.getStackTrace());
            throw hazelcastException;
        }
    });
    executionService.asCompletableFuture(future).whenCompleteAsync(withTryCatch(logger, (result, error) -> sendResponse(error != null ? peel(error) : result)), CALLER_RUNS);
}
Also used : AbstractLocalOperation(com.hazelcast.spi.impl.operationservice.AbstractLocalOperation) CALLER_RUNS(com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS) HazelcastException(com.hazelcast.core.HazelcastException) ManagementCenterService(com.hazelcast.internal.management.ManagementCenterService) ManagementCenterConfig(com.hazelcast.config.ManagementCenterConfig) ExceptionUtil.peel(com.hazelcast.internal.util.ExceptionUtil.peel) ScriptEngineManager(javax.script.ScriptEngineManager) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) Future(java.util.concurrent.Future) ILogger(com.hazelcast.logging.ILogger) ScriptEngine(javax.script.ScriptEngine) AccessControlException(java.security.AccessControlException) ExceptionUtil.withTryCatch(com.hazelcast.internal.util.ExceptionUtil.withTryCatch) ScriptEngineManagerContext(com.hazelcast.internal.management.ScriptEngineManagerContext) ScriptException(javax.script.ScriptException) ScriptException(javax.script.ScriptException) HazelcastException(com.hazelcast.core.HazelcastException) ScriptEngineManager(javax.script.ScriptEngineManager) AccessControlException(java.security.AccessControlException) ILogger(com.hazelcast.logging.ILogger) ManagementCenterConfig(com.hazelcast.config.ManagementCenterConfig) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) ScriptEngine(javax.script.ScriptEngine)

Example 12 with ExecutionService

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

the class ChangeClusterStateOperation method run.

@Override
public void run() {
    ILogger logger = getNodeEngine().getLogger(getClass());
    ExecutionService executionService = getNodeEngine().getExecutionService();
    Future<Void> future = executionService.submit(ExecutionService.ASYNC_EXECUTOR, () -> {
        getNodeEngine().getClusterService().changeClusterState(newState);
        return null;
    });
    executionService.asCompletableFuture(future).whenCompleteAsync(withTryCatch(logger, (empty, error) -> sendResponse(error != null ? peel(error) : null)), CALLER_RUNS);
}
Also used : CALLER_RUNS(com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS) ManagementCenterService(com.hazelcast.internal.management.ManagementCenterService) ExceptionUtil.peel(com.hazelcast.internal.util.ExceptionUtil.peel) IOException(java.io.IOException) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) Future(java.util.concurrent.Future) ManagementDataSerializerHook(com.hazelcast.internal.management.ManagementDataSerializerHook) ILogger(com.hazelcast.logging.ILogger) AllowedDuringPassiveState(com.hazelcast.spi.impl.AllowedDuringPassiveState) ClusterState(com.hazelcast.cluster.ClusterState) ExceptionUtil.withTryCatch(com.hazelcast.internal.util.ExceptionUtil.withTryCatch) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) ILogger(com.hazelcast.logging.ILogger) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService)

Example 13 with ExecutionService

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

the class ManagementCenterService method registerExecutor.

private void registerExecutor() {
    final ExecutionService executionService = instance.node.nodeEngine.getExecutionService();
    int threadCount = instance.node.getProperties().getInteger(ClusterProperty.MC_EXECUTOR_THREAD_COUNT);
    logger.finest("Creating new executor for Management Center service tasks with threadCount=" + threadCount);
    executionService.register(ExecutionService.MC_EXECUTOR, threadCount, threadCount * EXECUTOR_QUEUE_CAPACITY_PER_THREAD, ExecutorType.CACHED);
}
Also used : ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService)

Example 14 with ExecutionService

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

the class ChangeClusterVersionOperation 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().getClusterService().changeClusterVersion(version);
        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) Version(com.hazelcast.version.Version) ILogger(com.hazelcast.logging.ILogger) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService)

Example 15 with ExecutionService

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

the class PostJoinProxyOperation method run.

@Override
public void run() throws Exception {
    if (proxies == null || proxies.size() <= 0) {
        return;
    }
    NodeEngine nodeEngine = getNodeEngine();
    ProxyServiceImpl proxyService = getService();
    ExecutionService executionService = nodeEngine.getExecutionService();
    for (final ProxyInfo proxy : proxies) {
        final ProxyRegistry registry = proxyService.getOrCreateRegistry(proxy.getServiceName());
        try {
            executionService.execute(ExecutionService.SYSTEM_EXECUTOR, new CreateProxyTask(registry, proxy));
        } catch (Throwable t) {
            logProxyCreationFailure(proxy, t);
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) ProxyInfo(com.hazelcast.spi.impl.proxyservice.impl.ProxyInfo) ProxyRegistry(com.hazelcast.spi.impl.proxyservice.impl.ProxyRegistry) ProxyServiceImpl(com.hazelcast.spi.impl.proxyservice.impl.ProxyServiceImpl) 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