Search in sources :

Example 1 with TaskOperation

use of com.hazelcast.durableexecutor.impl.operations.TaskOperation in project hazelcast by hazelcast.

the class DurableExecutorSubmitToPartitionMessageTask 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 TaskOperation(parameters.name, callableData);
}
Also used : SecurityContext(com.hazelcast.security.SecurityContext) Data(com.hazelcast.internal.serialization.Data) TaskOperation(com.hazelcast.durableexecutor.impl.operations.TaskOperation) Subject(javax.security.auth.Subject) Callable(java.util.concurrent.Callable)

Example 2 with TaskOperation

use of com.hazelcast.durableexecutor.impl.operations.TaskOperation in project hazelcast by hazelcast.

the class DurableExecutorServiceProxy method submitToPartition.

private <T> DurableExecutorServiceFuture<T> submitToPartition(@Nonnull Callable<T> task, int partitionId, T defaultValue) {
    checkNotNull(task, "task can't be null");
    SerializationService serializationService = getNodeEngine().getSerializationService();
    Data taskData = serializationService.toData(task);
    TaskOperation operation = new TaskOperation(name, taskData);
    operation.setPartitionId(partitionId);
    InternalCompletableFuture<Integer> future = invokeOnPartition(operation);
    int sequence;
    try {
        sequence = future.join();
    } catch (CompletionException t) {
        InternalCompletableFuture<T> completedFuture = completedExceptionally(t.getCause());
        return new DurableExecutorServiceDelegateFuture<T>(completedFuture, serializationService, null, -1);
    } catch (CancellationException e) {
        return new DurableExecutorServiceDelegateFuture<>(future, serializationService, null, -1);
    }
    Operation op = new RetrieveResultOperation(name, sequence).setPartitionId(partitionId);
    InternalCompletableFuture<T> internalCompletableFuture = invokeOnPartition(op);
    long taskId = Bits.combineToLong(partitionId, sequence);
    return new DurableExecutorServiceDelegateFuture<>(internalCompletableFuture, serializationService, defaultValue, taskId);
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) TaskOperation(com.hazelcast.durableexecutor.impl.operations.TaskOperation) ShutdownOperation(com.hazelcast.durableexecutor.impl.operations.ShutdownOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) TaskOperation(com.hazelcast.durableexecutor.impl.operations.TaskOperation) DisposeResultOperation(com.hazelcast.durableexecutor.impl.operations.DisposeResultOperation) RetrieveAndDisposeResultOperation(com.hazelcast.durableexecutor.impl.operations.RetrieveAndDisposeResultOperation) RetrieveResultOperation(com.hazelcast.durableexecutor.impl.operations.RetrieveResultOperation) CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) RetrieveResultOperation(com.hazelcast.durableexecutor.impl.operations.RetrieveResultOperation)

Aggregations

TaskOperation (com.hazelcast.durableexecutor.impl.operations.TaskOperation)2 Data (com.hazelcast.internal.serialization.Data)2 DisposeResultOperation (com.hazelcast.durableexecutor.impl.operations.DisposeResultOperation)1 RetrieveAndDisposeResultOperation (com.hazelcast.durableexecutor.impl.operations.RetrieveAndDisposeResultOperation)1 RetrieveResultOperation (com.hazelcast.durableexecutor.impl.operations.RetrieveResultOperation)1 ShutdownOperation (com.hazelcast.durableexecutor.impl.operations.ShutdownOperation)1 SerializationService (com.hazelcast.internal.serialization.SerializationService)1 SecurityContext (com.hazelcast.security.SecurityContext)1 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)1 Operation (com.hazelcast.spi.impl.operationservice.Operation)1 Callable (java.util.concurrent.Callable)1 CancellationException (java.util.concurrent.CancellationException)1 CompletionException (java.util.concurrent.CompletionException)1 Subject (javax.security.auth.Subject)1