Search in sources :

Example 1 with InvocationBuilder

use of com.hazelcast.spi.impl.operationservice.InvocationBuilder in project hazelcast by hazelcast.

the class PNCounterProxy method invokeInternal.

/**
 * Invokes the {@code operation} recursively on viable replica addresses
 * until successful or the list of viable replicas is exhausted.
 * Replicas with addresses contained in the {@code excludedAddresses} are
 * skipped. If there are no viable replicas, this method will throw the
 * {@code lastException} if not {@code null} or a
 * {@link NoDataMemberInClusterException} if the {@code lastException} is
 * {@code null}.
 *
 * @param operation         the operation to invoke on a CRDT replica
 * @param excludedAddresses the addresses to exclude when choosing a replica
 *                          address, must not be {@code null}
 * @param lastException     the exception thrown from the last invocation of
 *                          the {@code operation} on a replica, may be {@code null}
 * @return the result of the operation invocation on a replica
 * @throws NoDataMemberInClusterException if there are no replicas and the
 *                                        {@code lastException} is {@code null}
 */
private long invokeInternal(Operation operation, List<Address> excludedAddresses, HazelcastException lastException) {
    final Address target = getCRDTOperationTarget(excludedAddresses);
    if (target == null) {
        throw lastException != null ? lastException : new NoDataMemberInClusterException("Cannot invoke operations on a CRDT because the cluster does not contain any data members");
    }
    try {
        final InvocationBuilder builder = getNodeEngine().getOperationService().createInvocationBuilder(SERVICE_NAME, operation, target);
        if (operationTryCount > 0) {
            builder.setTryCount(operationTryCount);
        }
        final InvocationFuture<CRDTTimestampedLong> future = builder.invoke();
        final CRDTTimestampedLong result = future.joinInternal();
        updateObservedReplicaTimestamps(result.getVectorClock());
        return result.getValue();
    } catch (HazelcastException e) {
        logger.fine("Exception occurred while invoking operation on target " + target + ", choosing different target", e);
        if (excludedAddresses == EMPTY_ADDRESS_LIST) {
            excludedAddresses = new ArrayList<Address>();
        }
        excludedAddresses.add(target);
        return invokeInternal(operation, excludedAddresses, e);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Address(com.hazelcast.cluster.Address) ArrayList(java.util.ArrayList) InvocationBuilder(com.hazelcast.spi.impl.operationservice.InvocationBuilder) NoDataMemberInClusterException(com.hazelcast.partition.NoDataMemberInClusterException) CRDTTimestampedLong(com.hazelcast.internal.crdt.pncounter.operations.CRDTTimestampedLong)

Example 2 with InvocationBuilder

use of com.hazelcast.spi.impl.operationservice.InvocationBuilder in project hazelcast by hazelcast.

the class MapPublisherCreateWithValueMessageTask method createPublishersAndGetSnapshotOf.

private List<Future> createPublishersAndGetSnapshotOf(Collection<MemberImpl> members) {
    List<Future> futures = new ArrayList<Future>(members.size());
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    for (MemberImpl member : members) {
        Predicate predicate = serializationService.toObject(parameters.predicate);
        AccumulatorInfo accumulatorInfo = AccumulatorInfo.toAccumulatorInfo(parameters.mapName, parameters.cacheName, predicate, parameters.batchSize, parameters.bufferSize, parameters.delaySeconds, true, parameters.populate, parameters.coalesce);
        PublisherCreateOperation operation = new PublisherCreateOperation(accumulatorInfo);
        operation.setCallerUuid(endpoint.getUuid());
        Address address = member.getAddress();
        InvocationBuilder invocationBuilder = operationService.createInvocationBuilder(SERVICE_NAME, operation, address);
        Future future = invocationBuilder.invoke();
        futures.add(future);
    }
    return futures;
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) AccumulatorInfo(com.hazelcast.map.impl.querycache.accumulator.AccumulatorInfo) InvocationBuilder(com.hazelcast.spi.impl.operationservice.InvocationBuilder) PublisherCreateOperation(com.hazelcast.map.impl.querycache.subscriber.operation.PublisherCreateOperation) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) Predicate(com.hazelcast.query.Predicate)

Example 3 with InvocationBuilder

use of com.hazelcast.spi.impl.operationservice.InvocationBuilder in project hazelcast by hazelcast.

the class AbstractMultiTargetMessageTask method processInternal.

@Override
protected CompletableFuture<Object> processInternal() {
    Supplier<Operation> operationSupplier = createOperationSupplier();
    Collection<Member> targets = getTargets();
    CompletableFuture<Object> finalResult = new CompletableFuture<>();
    if (targets.isEmpty()) {
        finalResult.complete(EMPTY_MAP);
        return finalResult;
    }
    final OperationServiceImpl operationService = nodeEngine.getOperationService();
    MultiTargetCallback callback = new MultiTargetCallback(targets, finalResult);
    for (Member target : targets) {
        Operation op = operationSupplier.get();
        op.setCallerUuid(endpoint.getUuid());
        InvocationBuilder builder = operationService.createInvocationBuilder(getServiceName(), op, target.getAddress()).setResultDeserialized(false);
        InvocationFuture<Object> invocationFuture = builder.invoke();
        invocationFuture.whenCompleteAsync(new SingleTargetCallback(target, callback), CALLER_RUNS);
    }
    return finalResult;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Operation(com.hazelcast.spi.impl.operationservice.Operation) InvocationBuilder(com.hazelcast.spi.impl.operationservice.InvocationBuilder) Member(com.hazelcast.cluster.Member) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 4 with InvocationBuilder

use of com.hazelcast.spi.impl.operationservice.InvocationBuilder in project hazelcast by hazelcast.

the class XAClearRemoteTransactionMessageTask method call.

@Override
protected Object call() throws Exception {
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    InternalPartitionService partitionService = nodeEngine.getPartitionService();
    Data xidData = serializationService.toData(parameters);
    Operation op = new ClearRemoteTransactionOperation(xidData);
    op.setCallerUuid(endpoint.getUuid());
    int partitionId = partitionService.getPartitionId(xidData);
    InvocationBuilder builder = operationService.createInvocationBuilder(getServiceName(), op, partitionId);
    builder.setTryCount(TRY_COUNT).setResultDeserialized(false);
    builder.invoke();
    return XATransactionClearRemoteCodec.encodeResponse();
}
Also used : ClearRemoteTransactionOperation(com.hazelcast.transaction.impl.xa.operations.ClearRemoteTransactionOperation) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Data(com.hazelcast.internal.serialization.Data) ClearRemoteTransactionOperation(com.hazelcast.transaction.impl.xa.operations.ClearRemoteTransactionOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) InvocationBuilder(com.hazelcast.spi.impl.operationservice.InvocationBuilder) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 5 with InvocationBuilder

use of com.hazelcast.spi.impl.operationservice.InvocationBuilder in project hazelcast by hazelcast.

the class StaleReadDuringMigrationTest method invokeOperation.

private InternalCompletableFuture<Boolean> invokeOperation(final Config config) {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    final HazelcastInstance instance = factory.newHazelcastInstance(config);
    warmUpPartitions(instance);
    final int partitionId = 0;
    final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) getPartitionService(instance);
    final InternalPartitionImpl partition = (InternalPartitionImpl) partitionService.getPartition(partitionId);
    partition.setMigrating();
    final OperationServiceImpl operationService = getOperationService(instance);
    final InvocationBuilder invocationBuilder = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new DummyOperation(), partitionId);
    return invocationBuilder.invoke();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) InvocationBuilder(com.hazelcast.spi.impl.operationservice.InvocationBuilder) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Aggregations

InvocationBuilder (com.hazelcast.spi.impl.operationservice.InvocationBuilder)11 Operation (com.hazelcast.spi.impl.operationservice.Operation)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)5 Address (com.hazelcast.cluster.Address)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Future (java.util.concurrent.Future)4 Test (org.junit.Test)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)2 FetchPartitionStateOperation (com.hazelcast.internal.partition.operation.FetchPartitionStateOperation)2 MigrationOperation (com.hazelcast.internal.partition.operation.MigrationOperation)2 MigrationRequestOperation (com.hazelcast.internal.partition.operation.MigrationRequestOperation)2 Data (com.hazelcast.internal.serialization.Data)2 AccumulatorInfo (com.hazelcast.map.impl.querycache.accumulator.AccumulatorInfo)2 PublisherCreateOperation (com.hazelcast.map.impl.querycache.subscriber.operation.PublisherCreateOperation)2 Predicate (com.hazelcast.query.Predicate)2 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)2 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)2