Search in sources :

Example 96 with NodeEngine

use of com.hazelcast.spi.NodeEngine in project hazelcast by hazelcast.

the class ExecutorServiceProxy method submitToMember.

@Override
public <T> Future<T> submitToMember(Callable<T> task, Member member) {
    checkNotNull(task, "task can't be null");
    checkNotShutdown();
    NodeEngine nodeEngine = getNodeEngine();
    Data taskData = nodeEngine.toData(task);
    String uuid = newUnsecureUuidString();
    Address target = ((MemberImpl) member).getAddress();
    boolean sync = checkSync();
    MemberCallableTaskOperation op = new MemberCallableTaskOperation(name, uuid, taskData);
    InternalCompletableFuture future = nodeEngine.getOperationService().invokeOnTarget(DistributedExecutorService.SERVICE_NAME, op, target);
    if (sync) {
        Object response;
        try {
            response = future.get();
        } catch (Exception e) {
            response = e;
        }
        return new CompletedFuture<T>(nodeEngine.getSerializationService(), response, getAsyncExecutor());
    }
    return new CancellableDelegatingFuture<T>(future, nodeEngine, uuid, target);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) MemberImpl(com.hazelcast.instance.MemberImpl) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Data(com.hazelcast.nio.serialization.Data) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) UuidUtil.newUnsecureUuidString(com.hazelcast.util.UuidUtil.newUnsecureUuidString) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TimeoutException(java.util.concurrent.TimeoutException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) CompletedFuture(com.hazelcast.util.executor.CompletedFuture)

Example 97 with NodeEngine

use of com.hazelcast.spi.NodeEngine in project hazelcast by hazelcast.

the class ExecutorServiceProxy method submitToMember.

@Override
public <T> void submitToMember(Callable<T> task, Member member, ExecutionCallback<T> callback) {
    checkNotShutdown();
    NodeEngine nodeEngine = getNodeEngine();
    Data taskData = nodeEngine.toData(task);
    String uuid = newUnsecureUuidString();
    MemberCallableTaskOperation op = new MemberCallableTaskOperation(name, uuid, taskData);
    OperationService operationService = nodeEngine.getOperationService();
    Address address = ((MemberImpl) member).getAddress();
    operationService.createInvocationBuilder(DistributedExecutorService.SERVICE_NAME, op, address).setExecutionCallback((ExecutionCallback) callback).invoke();
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) MemberImpl(com.hazelcast.instance.MemberImpl) Data(com.hazelcast.nio.serialization.Data) UuidUtil.newUnsecureUuidString(com.hazelcast.util.UuidUtil.newUnsecureUuidString) OperationService(com.hazelcast.spi.OperationService) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) ExecutionCallback(com.hazelcast.core.ExecutionCallback)

Example 98 with NodeEngine

use of com.hazelcast.spi.NodeEngine in project hazelcast by hazelcast.

the class ExecutorServiceProxy method submit.

@Override
public <T> Future<T> submit(Runnable task, T result) {
    checkNotNull(task, "task can't be null");
    checkNotShutdown();
    NodeEngine nodeEngine = getNodeEngine();
    Callable<T> callable = createRunnableAdapter(task);
    Data callableData = nodeEngine.toData(callable);
    String uuid = newUnsecureUuidString();
    int partitionId = getTaskPartitionId(callable);
    Operation op = new CallableTaskOperation(name, uuid, callableData).setPartitionId(partitionId);
    InternalCompletableFuture future = invokeOnPartition(op);
    boolean sync = checkSync();
    if (sync) {
        try {
            future.get();
        } catch (Exception exception) {
            logger.warning(exception);
        }
        return new CompletedFuture<T>(nodeEngine.getSerializationService(), result, getAsyncExecutor());
    }
    return new CancellableDelegatingFuture<T>(future, result, nodeEngine, uuid, partitionId);
}
Also used : InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Data(com.hazelcast.nio.serialization.Data) UuidUtil.newUnsecureUuidString(com.hazelcast.util.UuidUtil.newUnsecureUuidString) ShutdownOperation(com.hazelcast.executor.impl.operations.ShutdownOperation) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) Operation(com.hazelcast.spi.Operation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TimeoutException(java.util.concurrent.TimeoutException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) NodeEngine(com.hazelcast.spi.NodeEngine) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) CompletedFuture(com.hazelcast.util.executor.CompletedFuture)

Example 99 with NodeEngine

use of com.hazelcast.spi.NodeEngine in project hazelcast by hazelcast.

the class ExecutorServiceProxy method submitToPartitionOwner.

private <T> void submitToPartitionOwner(Callable<T> task, ExecutionCallback<T> callback, int partitionId) {
    checkNotShutdown();
    NodeEngine nodeEngine = getNodeEngine();
    Data taskData = nodeEngine.toData(task);
    CallableTaskOperation op = new CallableTaskOperation(name, null, taskData);
    OperationService operationService = nodeEngine.getOperationService();
    operationService.createInvocationBuilder(DistributedExecutorService.SERVICE_NAME, op, partitionId).setExecutionCallback((ExecutionCallback) callback).invoke();
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Data(com.hazelcast.nio.serialization.Data) OperationService(com.hazelcast.spi.OperationService) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) ExecutionCallback(com.hazelcast.core.ExecutionCallback) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation)

Example 100 with NodeEngine

use of com.hazelcast.spi.NodeEngine in project hazelcast by hazelcast.

the class ExecutorServiceProxy method shutdown.

@Override
public void shutdown() {
    NodeEngine nodeEngine = getNodeEngine();
    Collection<Member> members = nodeEngine.getClusterService().getMembers();
    OperationService operationService = nodeEngine.getOperationService();
    Collection<Future> calls = new LinkedList<Future>();
    for (Member member : members) {
        if (member.localMember()) {
            getService().shutdownExecutor(name);
        } else {
            Future f = submitShutdownOperation(operationService, member);
            calls.add(f);
        }
    }
    waitWithDeadline(calls, 1, TimeUnit.SECONDS, WHILE_SHUTDOWN_EXCEPTION_HANDLER);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Future(java.util.concurrent.Future) CompletedFuture(com.hazelcast.util.executor.CompletedFuture) OperationService(com.hazelcast.spi.OperationService) Member(com.hazelcast.core.Member) LinkedList(java.util.LinkedList)

Aggregations

NodeEngine (com.hazelcast.spi.NodeEngine)163 Data (com.hazelcast.nio.serialization.Data)50 OperationService (com.hazelcast.spi.OperationService)30 Address (com.hazelcast.nio.Address)25 ILogger (com.hazelcast.logging.ILogger)20 Operation (com.hazelcast.spi.Operation)14 IPartitionService (com.hazelcast.spi.partition.IPartitionService)14 Member (com.hazelcast.core.Member)12 Future (java.util.concurrent.Future)12 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)11 Test (org.junit.Test)10 InitializingObject (com.hazelcast.spi.InitializingObject)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)8 AbstractDistributedObject (com.hazelcast.spi.AbstractDistributedObject)8 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)7