Search in sources :

Example 41 with ClientInvocation

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

the class ClientMapProxy method readFromEventJournal.

@Override
public <T> InternalCompletableFuture<ReadResultSet<T>> readFromEventJournal(long startSequence, int minSize, int maxSize, int partitionId, java.util.function.Predicate<? super EventJournalMapEvent<K, V>> predicate, java.util.function.Function<? super EventJournalMapEvent<K, V>, ? extends T> projection) {
    if (maxSize < minSize) {
        throw new IllegalArgumentException("maxSize " + maxSize + " must be greater or equal to minSize " + minSize);
    }
    final SerializationService ss = getSerializationService();
    final ClientMessage request = MapEventJournalReadCodec.encodeRequest(name, startSequence, minSize, maxSize, ss.toData(predicate), ss.toData(projection));
    final ClientInvocationFuture fut = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
    return new ClientDelegatingFuture<>(fut, ss, message -> {
        MapEventJournalReadCodec.ResponseParameters params = MapEventJournalReadCodec.decodeResponse(message);
        ReadResultSetImpl resultSet = new ReadResultSetImpl<>(params.readCount, params.items, params.itemSeqs, params.nextSeq);
        resultSet.setSerializationService(getSerializationService());
        return resultSet;
    });
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) SerializationService(com.hazelcast.internal.serialization.SerializationService) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) MapEventJournalReadCodec(com.hazelcast.client.impl.protocol.codec.MapEventJournalReadCodec) ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 42 with ClientInvocation

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

the class ClientMultiMapProxy method putAllInternal.

@SuppressWarnings({ "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity", "checkstyle:methodlength" })
private void putAllInternal(@Nonnull Map<Data, Collection<Data>> map, @Nonnull InternalCompletableFuture<Void> future) {
    if (map.isEmpty()) {
        future.complete(null);
        return;
    }
    ClientPartitionService partitionService = getContext().getPartitionService();
    int partitionCount = partitionService.getPartitionCount();
    Map<Integer, Collection<Map.Entry<Data, Collection<Data>>>> entryMap = new HashMap<>(partitionCount);
    for (Map.Entry<Data, Collection<Data>> entry : map.entrySet()) {
        checkNotNull(entry.getKey(), NULL_KEY_IS_NOT_ALLOWED);
        checkNotNull(entry.getValue(), NULL_VALUE_IS_NOT_ALLOWED);
        Data keyData = entry.getKey();
        int partitionId = partitionService.getPartitionId(keyData);
        Collection<Map.Entry<Data, Collection<Data>>> partition = entryMap.get(partitionId);
        if (partition == null) {
            partition = new ArrayList<>();
            entryMap.put(partitionId, partition);
        }
        partition.add(new AbstractMap.SimpleEntry<>(keyData, entry.getValue()));
    }
    assert entryMap.size() > 0;
    AtomicInteger counter = new AtomicInteger(entryMap.size());
    InternalCompletableFuture<Void> resultFuture = future;
    BiConsumer<ClientMessage, Throwable> callback = (response, t) -> {
        if (t != null) {
            resultFuture.completeExceptionally(t);
        }
        if (counter.decrementAndGet() == 0) {
            if (!resultFuture.isDone()) {
                resultFuture.complete(null);
            }
        }
    };
    for (Map.Entry<Integer, Collection<Map.Entry<Data, Collection<Data>>>> entry : entryMap.entrySet()) {
        Integer partitionId = entry.getKey();
        // if there is only one entry, consider how we can use MapPutRequest
        // without having to get back the return value
        ClientMessage request = MultiMapPutAllCodec.encodeRequest(name, entry.getValue());
        new ClientInvocation(getClient(), request, getName(), partitionId).invoke().whenCompleteAsync(callback);
    }
}
Also used : MultiMapPutCodec(com.hazelcast.client.impl.protocol.codec.MultiMapPutCodec) MultiMapContainsValueCodec(com.hazelcast.client.impl.protocol.codec.MultiMapContainsValueCodec) MultiMapAddEntryListenerCodec(com.hazelcast.client.impl.protocol.codec.MultiMapAddEntryListenerCodec) MultiMapForceUnlockCodec(com.hazelcast.client.impl.protocol.codec.MultiMapForceUnlockCodec) Member(com.hazelcast.cluster.Member) ListenerAdapters.createListenerAdapter(com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter) MultiMapSizeCodec(com.hazelcast.client.impl.protocol.codec.MultiMapSizeCodec) Thread.currentThread(java.lang.Thread.currentThread) CollectionUtil(com.hazelcast.internal.util.CollectionUtil) EventHandler(com.hazelcast.client.impl.spi.EventHandler) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) MultiMapClearCodec(com.hazelcast.client.impl.protocol.codec.MultiMapClearCodec) ListenerMessageCodec(com.hazelcast.client.impl.spi.impl.ListenerMessageCodec) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MultiMapContainsEntryCodec(com.hazelcast.client.impl.protocol.codec.MultiMapContainsEntryCodec) Map(java.util.Map) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientLockReferenceIdGenerator(com.hazelcast.client.impl.clientside.ClientLockReferenceIdGenerator) MultiMapIsLockedCodec(com.hazelcast.client.impl.protocol.codec.MultiMapIsLockedCodec) MultiMapPutAllCodec(com.hazelcast.client.impl.protocol.codec.MultiMapPutAllCodec) EntryEvent(com.hazelcast.core.EntryEvent) MultiMapEntrySetCodec(com.hazelcast.client.impl.protocol.codec.MultiMapEntrySetCodec) LocalMultiMapStats(com.hazelcast.multimap.LocalMultiMapStats) ClientPartitionService(com.hazelcast.client.impl.spi.ClientPartitionService) MultiMapLockCodec(com.hazelcast.client.impl.protocol.codec.MultiMapLockCodec) Collection(java.util.Collection) Set(java.util.Set) EntryListener(com.hazelcast.core.EntryListener) UUID(java.util.UUID) MultiMapRemoveEntryCodec(com.hazelcast.client.impl.protocol.codec.MultiMapRemoveEntryCodec) MultiMapDeleteCodec(com.hazelcast.client.impl.protocol.codec.MultiMapDeleteCodec) UnmodifiableLazyList(com.hazelcast.spi.impl.UnmodifiableLazyList) CompletionStage(java.util.concurrent.CompletionStage) Preconditions.checkPositive(com.hazelcast.internal.util.Preconditions.checkPositive) MultiMapAddEntryListenerToKeyCodec(com.hazelcast.client.impl.protocol.codec.MultiMapAddEntryListenerToKeyCodec) MultiMapGetCodec(com.hazelcast.client.impl.protocol.codec.MultiMapGetCodec) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) MultiMapRemoveEntryListenerCodec(com.hazelcast.client.impl.protocol.codec.MultiMapRemoveEntryListenerCodec) MultiMapTryLockCodec(com.hazelcast.client.impl.protocol.codec.MultiMapTryLockCodec) DataAwareEntryEvent(com.hazelcast.map.impl.DataAwareEntryEvent) HashMap(java.util.HashMap) IMapEvent(com.hazelcast.map.IMapEvent) MultiMapUnlockCodec(com.hazelcast.client.impl.protocol.codec.MultiMapUnlockCodec) ArrayList(java.util.ArrayList) MultiMapValuesCodec(com.hazelcast.client.impl.protocol.codec.MultiMapValuesCodec) MultiMap(com.hazelcast.multimap.MultiMap) ClientContext(com.hazelcast.client.impl.spi.ClientContext) BiConsumer(java.util.function.BiConsumer) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) EntryEventType(com.hazelcast.core.EntryEventType) UnmodifiableLazySet(com.hazelcast.spi.impl.UnmodifiableLazySet) MultiMapRemoveCodec(com.hazelcast.client.impl.protocol.codec.MultiMapRemoveCodec) Data(com.hazelcast.internal.serialization.Data) MultiMapContainsKeyCodec(com.hazelcast.client.impl.protocol.codec.MultiMapContainsKeyCodec) MultiMapKeySetCodec(com.hazelcast.client.impl.protocol.codec.MultiMapKeySetCodec) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) ClientProxy(com.hazelcast.client.impl.spi.ClientProxy) TimeUnit(java.util.concurrent.TimeUnit) AbstractMap(java.util.AbstractMap) MultiMapValueCountCodec(com.hazelcast.client.impl.protocol.codec.MultiMapValueCountCodec) MapEvent(com.hazelcast.map.MapEvent) ListenerAdapter(com.hazelcast.map.impl.ListenerAdapter) ThreadUtil(com.hazelcast.internal.util.ThreadUtil) HashMap(java.util.HashMap) Data(com.hazelcast.internal.serialization.Data) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractMap(java.util.AbstractMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collection(java.util.Collection) ClientPartitionService(com.hazelcast.client.impl.spi.ClientPartitionService) Map(java.util.Map) HashMap(java.util.HashMap) MultiMap(com.hazelcast.multimap.MultiMap) AbstractMap(java.util.AbstractMap)

Example 43 with ClientInvocation

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

the class ClientDurableExecutorServiceProxy method submitToPartition.

private <T> DurableExecutorServiceFuture<T> submitToPartition(@Nonnull Callable<T> task, int partitionId, @Nullable T result) {
    checkNotNull(task, "task should not be null");
    ClientMessage request = DurableExecutorSubmitToPartitionCodec.encodeRequest(name, toData(task));
    int sequence;
    try {
        ClientMessage response = invokeOnPartition(request, partitionId);
        sequence = DurableExecutorSubmitToPartitionCodec.decodeResponse(response);
    } catch (Throwable t) {
        return completedExceptionally(t, ConcurrencyUtil.getDefaultAsyncExecutor());
    }
    ClientMessage clientMessage = DurableExecutorRetrieveResultCodec.encodeRequest(name, sequence);
    ClientInvocationFuture future = new ClientInvocation(getClient(), clientMessage, getName(), partitionId).invoke();
    long taskId = Bits.combineToLong(partitionId, sequence);
    return new ClientDurableExecutorServiceDelegatingFuture<>(future, getSerializationService(), DurableExecutorRetrieveResultCodec::decodeResponse, result, taskId);
}
Also used : DurableExecutorRetrieveResultCodec(com.hazelcast.client.impl.protocol.codec.DurableExecutorRetrieveResultCodec) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 44 with ClientInvocation

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

the class ClientDurableExecutorServiceProxy method retrieveAndDisposeResult.

@Override
public <T> Future<T> retrieveAndDisposeResult(long taskId) {
    int partitionId = Bits.extractInt(taskId, false);
    int sequence = Bits.extractInt(taskId, true);
    ClientMessage clientMessage = DurableExecutorRetrieveAndDisposeResultCodec.encodeRequest(name, sequence);
    ClientInvocationFuture future = new ClientInvocation(getClient(), clientMessage, getName(), partitionId).invoke();
    return new ClientDelegatingFuture<>(future, getSerializationService(), DurableExecutorRetrieveResultCodec::decodeResponse);
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) DurableExecutorRetrieveResultCodec(com.hazelcast.client.impl.protocol.codec.DurableExecutorRetrieveResultCodec) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 45 with ClientInvocation

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

the class ClientFlakeIdGeneratorProxy method newIdBatch.

private IdBatch newIdBatch(int batchSize) {
    ClientMessage requestMsg = FlakeIdGeneratorNewIdBatchCodec.encodeRequest(name, batchSize);
    ClientMessage responseMsg = new ClientInvocation(getClient(), requestMsg, getName()).invoke().joinInternal();
    ResponseParameters response = FlakeIdGeneratorNewIdBatchCodec.decodeResponse(responseMsg);
    return new IdBatch(response.base, response.increment, response.batchSize);
}
Also used : IdBatch(com.hazelcast.flakeidgen.impl.IdBatch) ResponseParameters(com.hazelcast.client.impl.protocol.codec.FlakeIdGeneratorNewIdBatchCodec.ResponseParameters) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

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