Search in sources :

Example 1 with CallableTaskOperation

use of com.hazelcast.executor.impl.operations.CallableTaskOperation in project hazelcast by hazelcast.

the class ExecutorServiceProxy method submitToPartitionOwner.

private <T> Future<T> submitToPartitionOwner(Callable<T> task, int partitionId, boolean preventSync) {
    checkNotNull(task, "task can't be null");
    checkNotShutdown();
    NodeEngine nodeEngine = getNodeEngine();
    Data taskData = nodeEngine.toData(task);
    String uuid = newUnsecureUuidString();
    boolean sync = !preventSync && checkSync();
    Operation op = new CallableTaskOperation(name, uuid, taskData).setPartitionId(partitionId);
    InternalCompletableFuture future = invokeOnPartition(op);
    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, partitionId);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Data(com.hazelcast.nio.serialization.Data) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) 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) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) CompletedFuture(com.hazelcast.util.executor.CompletedFuture)

Example 2 with CallableTaskOperation

use of com.hazelcast.executor.impl.operations.CallableTaskOperation in project hazelcast by hazelcast.

the class ExecutorServiceSubmitToPartitionMessageTask method prepareOperation.

@Override
protected Operation prepareOperation() {
    SecurityContext securityContext = clientEngine.getSecurityContext();
    Data callableData = parameters.callable;
    if (securityContext != null) {
        Subject subject = endpoint.getSubject();
        Object taskObject = serializationService.toObject(parameters.callable);
        Callable callable;
        if (taskObject instanceof Runnable) {
            callable = securityContext.createSecureCallable(subject, (Runnable) taskObject);
        } else {
            callable = securityContext.createSecureCallable(subject, (Callable<? extends Object>) taskObject);
        }
        callableData = serializationService.toData(callable);
    }
    return new CallableTaskOperation(parameters.name, parameters.uuid, callableData);
}
Also used : SecurityContext(com.hazelcast.security.SecurityContext) Data(com.hazelcast.internal.serialization.Data) Subject(javax.security.auth.Subject) Callable(java.util.concurrent.Callable) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation)

Example 3 with CallableTaskOperation

use of com.hazelcast.executor.impl.operations.CallableTaskOperation in project hazelcast by hazelcast.

the class ExecutorServiceProxy method submit.

@Nonnull
@Override
public <T> Future<T> submit(@Nonnull Runnable task, T result) {
    checkNotNull(task, "task must not be null");
    checkNotShutdown();
    NodeEngine nodeEngine = getNodeEngine();
    Callable<T> callable = createRunnableAdapter(task);
    Data callableData = nodeEngine.toData(callable);
    UUID uuid = newUnsecureUUID();
    int partitionId = getTaskPartitionId(callable);
    Operation op = new CallableTaskOperation(name, uuid, callableData).setPartitionId(partitionId);
    InvocationFuture future = invokeOnPartition(op);
    return new CancellableDelegatingFuture<>(future, result, nodeEngine, uuid, partitionId);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Data(com.hazelcast.internal.serialization.Data) ShutdownOperation(com.hazelcast.executor.impl.operations.ShutdownOperation) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) InvocationFuture(com.hazelcast.spi.impl.operationservice.impl.InvocationFuture) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) Nonnull(javax.annotation.Nonnull)

Example 4 with CallableTaskOperation

use of com.hazelcast.executor.impl.operations.CallableTaskOperation in project hazelcast by hazelcast.

the class ExecutorServiceProxy method submitToPartitionOwner.

@Nonnull
private <T> Future<T> submitToPartitionOwner(@Nonnull Callable<T> task, int partitionId) {
    checkNotNull(task, "task must not be null");
    checkNotShutdown();
    NodeEngine nodeEngine = getNodeEngine();
    Data taskData = nodeEngine.toData(task);
    UUID uuid = newUnsecureUUID();
    Operation op = new CallableTaskOperation(name, uuid, taskData).setPartitionId(partitionId);
    InternalCompletableFuture future = invokeOnPartition(op);
    return new CancellableDelegatingFuture<>(future, nodeEngine, uuid, partitionId);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Data(com.hazelcast.internal.serialization.Data) ShutdownOperation(com.hazelcast.executor.impl.operations.ShutdownOperation) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) Nonnull(javax.annotation.Nonnull)

Example 5 with CallableTaskOperation

use of com.hazelcast.executor.impl.operations.CallableTaskOperation in project hazelcast by hazelcast.

the class ExecutorServiceProxy method submitToPartitionOwner.

private <T> void submitToPartitionOwner(@Nonnull Callable<T> task, @Nullable ExecutionCallback<T> callback, int partitionId) {
    checkNotShutdown();
    checkNotNull(task, "task must not be null");
    NodeEngine nodeEngine = getNodeEngine();
    Data taskData = nodeEngine.toData(task);
    CallableTaskOperation op = new CallableTaskOperation(name, null, taskData);
    OperationService operationService = nodeEngine.getOperationService();
    InvocationFuture<T> future = operationService.createInvocationBuilder(DistributedExecutorService.SERVICE_NAME, op, partitionId).invoke();
    if (callback != null) {
        future.whenCompleteAsync(new ExecutionCallbackAdapter<>(callback)).whenCompleteAsync((v, t) -> {
            if (t instanceof RejectedExecutionException) {
                callback.onFailure(t);
            }
        });
    }
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Data(com.hazelcast.internal.serialization.Data) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation)

Aggregations

CallableTaskOperation (com.hazelcast.executor.impl.operations.CallableTaskOperation)5 MemberCallableTaskOperation (com.hazelcast.executor.impl.operations.MemberCallableTaskOperation)4 Data (com.hazelcast.internal.serialization.Data)4 ShutdownOperation (com.hazelcast.executor.impl.operations.ShutdownOperation)3 NodeEngine (com.hazelcast.spi.impl.NodeEngine)3 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)2 Operation (com.hazelcast.spi.impl.operationservice.Operation)2 UUID (java.util.UUID)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 Nonnull (javax.annotation.Nonnull)2 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 Data (com.hazelcast.nio.serialization.Data)1 SecurityContext (com.hazelcast.security.SecurityContext)1 AbstractDistributedObject (com.hazelcast.spi.AbstractDistributedObject)1 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)1 NodeEngine (com.hazelcast.spi.NodeEngine)1 Operation (com.hazelcast.spi.Operation)1 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)1 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)1 InvocationFuture (com.hazelcast.spi.impl.operationservice.impl.InvocationFuture)1