Search in sources :

Example 1 with CALLER_RUNS

use of com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS in project hazelcast by hazelcast.

the class HotRestartTriggerBackupMessageTask method call.

@Override
protected Object call() throws Exception {
    ILogger logger = nodeEngine.getLogger(getClass());
    ExecutionService executionService = nodeEngine.getExecutionService();
    Future<Void> future = executionService.submit(ExecutionService.ASYNC_EXECUTOR, () -> {
        node.getNodeExtension().getHotRestartService().backup();
        return null;
    });
    executionService.asCompletableFuture(future).whenCompleteAsync(withTryCatch(logger, (empty, error) -> sendResponse(error != null ? peel(error) : null)), CALLER_RUNS);
    return null;
}
Also used : CALLER_RUNS(com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS) ManagementCenterService(com.hazelcast.internal.management.ManagementCenterService) ManagementPermission(com.hazelcast.security.permission.ManagementPermission) Connection(com.hazelcast.internal.nio.Connection) ExceptionUtil.peel(com.hazelcast.internal.util.ExceptionUtil.peel) MCTriggerHotRestartBackupCodec(com.hazelcast.client.impl.protocol.codec.MCTriggerHotRestartBackupCodec) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) Node(com.hazelcast.instance.impl.Node) Future(java.util.concurrent.Future) AbstractCallableMessageTask(com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask) ILogger(com.hazelcast.logging.ILogger) Permission(java.security.Permission) ExceptionUtil.withTryCatch(com.hazelcast.internal.util.ExceptionUtil.withTryCatch) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ILogger(com.hazelcast.logging.ILogger) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService)

Example 2 with CALLER_RUNS

use of com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS in project hazelcast by hazelcast.

the class RunConsoleCommandOperation method run.

@Override
public void run() throws Exception {
    final ManagementCenterService mcs = ((NodeEngineImpl) getNodeEngine()).getManagementCenterService();
    if (mcs == null) {
        sendResponse(new HazelcastException("ManagementCenterService is not initialized yet"));
        return;
    }
    final ILogger logger = getNodeEngine().getLogger(getClass());
    final ExecutionService executionService = getNodeEngine().getExecutionService();
    Future<String> future = executionService.submit(ExecutionService.MC_EXECUTOR, () -> {
        ManagementCenterConfig mcConfig = getNodeEngine().getConfig().getManagementCenterConfig();
        if (!mcConfig.isConsoleEnabled()) {
            throw new AccessControlException("Using Console is not allowed on this Hazelcast member.");
        }
        try {
            final String ns = namespace;
            String cmd = command;
            if (!isNullOrEmpty(ns)) {
                // set namespace as a part of the command
                cmd = ns + "__" + cmd;
            }
            return mcs.runConsoleCommand(cmd);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw e;
        }
    });
    executionService.asCompletableFuture(future).whenCompleteAsync(withTryCatch(logger, (output, error) -> sendResponse(error != null ? peel(error) : output)), CALLER_RUNS);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) AbstractLocalOperation(com.hazelcast.spi.impl.operationservice.AbstractLocalOperation) CALLER_RUNS(com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastException(com.hazelcast.core.HazelcastException) ManagementCenterService(com.hazelcast.internal.management.ManagementCenterService) ManagementCenterConfig(com.hazelcast.config.ManagementCenterConfig) ExceptionUtil.peel(com.hazelcast.internal.util.ExceptionUtil.peel) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) Future(java.util.concurrent.Future) ILogger(com.hazelcast.logging.ILogger) StringUtil.isNullOrEmpty(com.hazelcast.internal.util.StringUtil.isNullOrEmpty) AccessControlException(java.security.AccessControlException) ExceptionUtil.withTryCatch(com.hazelcast.internal.util.ExceptionUtil.withTryCatch) HazelcastException(com.hazelcast.core.HazelcastException) ManagementCenterService(com.hazelcast.internal.management.ManagementCenterService) AccessControlException(java.security.AccessControlException) ILogger(com.hazelcast.logging.ILogger) ManagementCenterConfig(com.hazelcast.config.ManagementCenterConfig) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService)

Example 3 with CALLER_RUNS

use of com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS 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 4 with CALLER_RUNS

use of com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS 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 5 with CALLER_RUNS

use of com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS 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)

Aggregations

CALLER_RUNS (com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS)9 ExceptionUtil.peel (com.hazelcast.internal.util.ExceptionUtil.peel)8 ExceptionUtil.withTryCatch (com.hazelcast.internal.util.ExceptionUtil.withTryCatch)8 ILogger (com.hazelcast.logging.ILogger)8 ManagementCenterService (com.hazelcast.internal.management.ManagementCenterService)7 ExecutionService (com.hazelcast.spi.impl.executionservice.ExecutionService)7 Future (java.util.concurrent.Future)7 AbstractLocalOperation (com.hazelcast.spi.impl.operationservice.AbstractLocalOperation)4 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 Node (com.hazelcast.instance.impl.Node)3 Connection (com.hazelcast.internal.nio.Connection)3 Permission (java.security.Permission)3 AbstractCallableMessageTask (com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask)2 ManagementCenterConfig (com.hazelcast.config.ManagementCenterConfig)2 HazelcastException (com.hazelcast.core.HazelcastException)2 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)2 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)2 ManagementPermission (com.hazelcast.security.permission.ManagementPermission)2 IOException (java.io.IOException)2 AccessControlException (java.security.AccessControlException)2