Search in sources :

Example 66 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class ExecutorServiceProxy method submitToMember.

private <T> Future<T> submitToMember(@Nonnull Data taskData, @Nonnull Member member) {
    NodeEngine nodeEngine = getNodeEngine();
    UUID uuid = newUnsecureUUID();
    Address target = member.getAddress();
    MemberCallableTaskOperation op = new MemberCallableTaskOperation(name, uuid, taskData);
    InternalCompletableFuture future = nodeEngine.getOperationService().invokeOnTarget(DistributedExecutorService.SERVICE_NAME, op, target);
    return new CancellableDelegatingFuture<>(future, nodeEngine, uuid, target);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Address(com.hazelcast.cluster.Address) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation)

Example 67 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture 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)

Example 68 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class InvalidationMetaDataFetcher method init.

// returns true if handler is initialized properly, otherwise false
public final boolean init(RepairingHandler handler) {
    MetadataHolder resultHolder = new MetadataHolder();
    List<String> dataStructureNames = Collections.singletonList(handler.getName());
    Map<Member, InternalCompletableFuture> futureByMember = fetchMembersMetadataFor(dataStructureNames);
    for (Map.Entry<Member, InternalCompletableFuture> entry : futureByMember.entrySet()) {
        Member member = entry.getKey();
        InternalCompletableFuture future = entry.getValue();
        try {
            extractMemberMetadata(member, future, resultHolder);
        } catch (Exception e) {
            handleExceptionWhileProcessingMetadata(member, e);
            return false;
        }
        initUuid(resultHolder.partitionUuidList, handler);
        initSequence(resultHolder.namePartitionSequenceList, handler);
    }
    return true;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Member(com.hazelcast.cluster.Member) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ExecutionException(java.util.concurrent.ExecutionException)

Example 69 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class ChainingFutureTest method testNonTopologyRelatedExceptionArePropagated.

@Test(expected = OperationTimeoutException.class)
public void testNonTopologyRelatedExceptionArePropagated() {
    InternalCompletableFuture<Object> future1 = newFuture();
    InternalCompletableFuture<Object> future2 = newFuture();
    InternalCompletableFuture<Object> future3 = newFuture();
    CountingIterator<InternalCompletableFuture<Object>> iterator = toIterator(future1, future2, future3);
    ChainingFuture.ExceptionHandler handler = repairingIterator;
    ChainingFuture<Object> future = new ChainingFuture<>(iterator, handler);
    assertEquals(1, iterator.getHasNextCounter());
    assertEquals(1, iterator.getNextCounter());
    assertFalse(future.isDone());
    future1.completeExceptionally(new OperationTimeoutException());
    assertTrue(future.isDone());
    future.joinInternal();
}
Also used : OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 70 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class ChainingFutureTest method testIteratingExceptionArePropagated.

@Test(expected = HazelcastException.class)
public void testIteratingExceptionArePropagated() {
    InternalCompletableFuture<Object> future1 = newFuture();
    InternalCompletableFuture<Object> future2 = newFuture();
    InternalCompletableFuture<Object> future3 = newFuture();
    CountingIterator<InternalCompletableFuture<Object>> iterator = toIterator(future1, future2, future3);
    ChainingFuture.ExceptionHandler handler = repairingIterator;
    ChainingFuture<Object> future = new ChainingFuture<>(iterator, handler);
    assertEquals(1, iterator.getHasNextCounter());
    assertEquals(1, iterator.getNextCounter());
    assertFalse(future.isDone());
    iterator.exceptionToThrow = new HazelcastException("iterating exception");
    future1.complete("foo");
    assertTrue(future.isDone());
    future.joinInternal();
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)90 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)47 QuickTest (com.hazelcast.test.annotation.QuickTest)47 Test (org.junit.Test)47 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)19 HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 Accessors.getOperationService (com.hazelcast.test.Accessors.getOperationService)15 Data (com.hazelcast.internal.serialization.Data)10 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 UUID (java.util.UUID)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Member (com.hazelcast.cluster.Member)7 ApplyRaftRunnable (com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable)7 Future (java.util.concurrent.Future)7 Address (com.hazelcast.cluster.Address)6 List (java.util.List)6 BiConsumer (java.util.function.BiConsumer)6 Nonnull (javax.annotation.Nonnull)6