Search in sources :

Example 11 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class ClientSchemaService method put.

@Override
public void put(Schema schema) {
    long schemaId = schema.getSchemaId();
    Schema existingSchema = schemas.get(schemaId);
    if (existingSchema != null) {
        return;
    }
    ClientMessage clientMessage = ClientSendSchemaCodec.encodeRequest(schema);
    ClientInvocation invocation = new ClientInvocation(client, clientMessage, SERVICE_NAME);
    invocation.invoke().joinInternal();
    putIfAbsent(schema);
}
Also used : Schema(com.hazelcast.internal.serialization.impl.compact.Schema) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 12 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class ClientScheduledExecutorProxy method getAllScheduledFutures.

@Nonnull
@Override
public <V> Map<Member, List<IScheduledFuture<V>>> getAllScheduledFutures() {
    ClientMessage request = ScheduledExecutorGetAllScheduledFuturesCodec.encodeRequest(getName());
    ClientInvocationFuture future = new ClientInvocation(getClient(), request, getName()).invoke();
    ClientMessage response;
    try {
        response = future.get();
    } catch (Exception e) {
        throw rethrow(e);
    }
    Collection<ScheduledTaskHandler> urnsPerMember = ScheduledExecutorGetAllScheduledFuturesCodec.decodeResponse(response);
    Map<Member, List<IScheduledFuture<V>>> tasksMap = new HashMap<>();
    for (ScheduledTaskHandler scheduledTaskHandler : urnsPerMember) {
        UUID memberUuid = scheduledTaskHandler.getUuid();
        Member member = getContext().getClusterService().getMember(memberUuid);
        tasksMap.compute(member, (BiFunctionEx<Member, List<IScheduledFuture<V>>, List<IScheduledFuture<V>>>) (m, iScheduledFutures) -> {
            if (iScheduledFutures == null) {
                iScheduledFutures = new LinkedList<>();
            }
            iScheduledFutures.add(new ClientScheduledFutureProxy(scheduledTaskHandler, getContext()));
            return iScheduledFutures;
        });
    }
    return tasksMap;
}
Also used : ScheduledExecutorShutdownCodec(com.hazelcast.client.impl.protocol.codec.ScheduledExecutorShutdownCodec) AutoDisposableTask(com.hazelcast.scheduledexecutor.AutoDisposableTask) FutureUtil(com.hazelcast.internal.util.FutureUtil) Member(com.hazelcast.cluster.Member) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ExceptionUtil.rethrow(com.hazelcast.internal.util.ExceptionUtil.rethrow) Level(java.util.logging.Level) BiFunctionEx(com.hazelcast.function.BiFunctionEx) Future(java.util.concurrent.Future) ExceptionUtil.sneakyThrow(com.hazelcast.internal.util.ExceptionUtil.sneakyThrow) PartitionAware(com.hazelcast.partition.PartitionAware) ILogger(com.hazelcast.logging.ILogger) ClientContext(com.hazelcast.client.impl.spi.ClientContext) Map(java.util.Map) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) UuidUtil(com.hazelcast.internal.util.UuidUtil) ClientMessageDecoder(com.hazelcast.client.impl.clientside.ClientMessageDecoder) LinkedList(java.util.LinkedList) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) Nonnull(javax.annotation.Nonnull) ScheduledExecutorGetAllScheduledFuturesCodec(com.hazelcast.client.impl.protocol.codec.ScheduledExecutorGetAllScheduledFuturesCodec) Logger(com.hazelcast.logging.Logger) AbstractTaskDecorator(com.hazelcast.scheduledexecutor.impl.AbstractTaskDecorator) Collection(java.util.Collection) FutureUtil.waitWithDeadline(com.hazelcast.internal.util.FutureUtil.waitWithDeadline) Data(com.hazelcast.internal.serialization.Data) TaskDefinition(com.hazelcast.scheduledexecutor.impl.TaskDefinition) UUID(java.util.UUID) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) ScheduledTaskHandlerImpl(com.hazelcast.scheduledexecutor.impl.ScheduledTaskHandlerImpl) ScheduledExecutorSubmitToPartitionCodec(com.hazelcast.client.impl.protocol.codec.ScheduledExecutorSubmitToPartitionCodec) TimeUnit(java.util.concurrent.TimeUnit) NamedTask(com.hazelcast.scheduledexecutor.NamedTask) List(java.util.List) SplitBrainProtectionException(com.hazelcast.splitbrainprotection.SplitBrainProtectionException) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ScheduledRunnableAdapter(com.hazelcast.scheduledexecutor.impl.ScheduledRunnableAdapter) ScheduledExecutorSubmitToMemberCodec(com.hazelcast.client.impl.protocol.codec.ScheduledExecutorSubmitToMemberCodec) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture) Collections(java.util.Collections) IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HashMap(java.util.HashMap) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) SplitBrainProtectionException(com.hazelcast.splitbrainprotection.SplitBrainProtectionException) LinkedList(java.util.LinkedList) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) LinkedList(java.util.LinkedList) List(java.util.List) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member) Nonnull(javax.annotation.Nonnull)

Example 13 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class IExecutorDelegatingFuture method invokeCancelRequest.

private boolean invokeCancelRequest(boolean mayInterruptIfRunning) throws InterruptedException, ExecutionException {
    waitForRequestToBeSend();
    HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) context.getHazelcastInstance();
    if (partitionId > -1) {
        ClientMessage request = ExecutorServiceCancelOnPartitionCodec.encodeRequest(uuid, mayInterruptIfRunning);
        ClientInvocation clientInvocation = new ClientInvocation(client, request, objectName, partitionId);
        ClientInvocationFuture f = clientInvocation.invoke();
        return ExecutorServiceCancelOnPartitionCodec.decodeResponse(f.get());
    } else {
        ClientMessage request = ExecutorServiceCancelOnMemberCodec.encodeRequest(uuid, member.getUuid(), mayInterruptIfRunning);
        ClientInvocation clientInvocation = new ClientInvocation(client, request, objectName, member.getUuid());
        ClientInvocationFuture f = clientInvocation.invoke();
        return ExecutorServiceCancelOnMemberCodec.decodeResponse(f.get());
    }
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 14 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class ClientRingbufferProxy method addAllAsync.

@Override
public InternalCompletableFuture<Long> addAllAsync(@Nonnull Collection<? extends E> collection, @Nonnull OverflowPolicy overflowPolicy) {
    checkNotNull(collection, "collection can't be null");
    checkNotNull(overflowPolicy, "overflowPolicy can't be null");
    checkFalse(collection.isEmpty(), "collection can't be empty");
    checkTrue(collection.size() <= MAX_BATCH_SIZE, "collection can't be larger than " + MAX_BATCH_SIZE);
    Collection<Data> dataCollection = objectToDataCollection(collection, getSerializationService());
    ClientMessage request = RingbufferAddAllCodec.encodeRequest(name, dataCollection, overflowPolicy.getId());
    try {
        ClientInvocationFuture future = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
        return new ClientDelegatingFuture<>(future, getSerializationService(), RingbufferAddAllCodec::decodeResponse);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) Data(com.hazelcast.internal.serialization.Data) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) RingbufferAddAllCodec(com.hazelcast.client.impl.protocol.codec.RingbufferAddAllCodec) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 15 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class ClientRingbufferProxy method readManyAsync.

@Override
public InternalCompletableFuture<ReadResultSet<E>> readManyAsync(long startSequence, int minCount, int maxCount, IFunction<E, Boolean> filter) {
    checkSequence(startSequence);
    checkNotNegative(minCount, "minCount can't be smaller than 0");
    checkTrue(maxCount >= minCount, "maxCount should be equal or larger than minCount");
    try {
        capacity();
    } catch (Throwable e) {
        return completedExceptionally(e);
    }
    checkTrue(maxCount <= capacity, "the maxCount should be smaller than or equal to the capacity");
    checkTrue(maxCount <= MAX_BATCH_SIZE, "maxCount can't be larger than " + MAX_BATCH_SIZE);
    ClientMessage request = RingbufferReadManyCodec.encodeRequest(name, startSequence, minCount, maxCount, toData(filter));
    try {
        ClientInvocationFuture invocationFuture = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
        return new ClientDelegatingFuture<>(invocationFuture, getSerializationService(), readManyAsyncResponseDecoder);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Aggregations

ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)129 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)97 ClientDelegatingFuture (com.hazelcast.client.impl.ClientDelegatingFuture)54 ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)51 Test (org.junit.Test)23 Data (com.hazelcast.internal.serialization.Data)22 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 QuickTest (com.hazelcast.test.annotation.QuickTest)19 UUID (java.util.UUID)18 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)16 Future (java.util.concurrent.Future)13 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)9 ArrayList (java.util.ArrayList)9 Nonnull (javax.annotation.Nonnull)9 ExecutionException (java.util.concurrent.ExecutionException)8 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)7 Collection (java.util.Collection)6 List (java.util.List)6 Map (java.util.Map)6 TimeUnit (java.util.concurrent.TimeUnit)6