Search in sources :

Example 1 with ClientPartitionService

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

the class ClientCacheProxySupport method groupKeysToPartitions.

private List<Data>[] groupKeysToPartitions(Set<? extends K> keys, Set<Data> serializedKeys) {
    List<Data>[] keysByPartition = new List[partitionCount];
    ClientPartitionService partitionService = getContext().getPartitionService();
    for (K key : keys) {
        Data keyData = getSerializationService().toData(key);
        if (serializedKeys != null) {
            serializedKeys.add(keyData);
        }
        int partitionId = partitionService.getPartitionId(keyData);
        List<Data> partition = keysByPartition[partitionId];
        if (partition == null) {
            partition = new ArrayList<>();
            keysByPartition[partitionId] = partition;
        }
        partition.add(keyData);
    }
    return keysByPartition;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Data(com.hazelcast.internal.serialization.Data) ClientPartitionService(com.hazelcast.client.impl.spi.ClientPartitionService)

Example 2 with ClientPartitionService

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

the class ClientCacheProxySupport method onInitialize.

@Override
protected void onInitialize() {
    logger = getContext().getLoggingService().getLogger(getClass());
    statsHandler = new CacheStatsHandler(getSerializationService());
    ClientPartitionService partitionService = getContext().getPartitionService();
    partitionCount = partitionService.getPartitionCount();
}
Also used : ClientPartitionService(com.hazelcast.client.impl.spi.ClientPartitionService)

Example 3 with ClientPartitionService

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

the class ClientMapProxy method putAllInternal.

@SuppressWarnings("checkstyle:npathcomplexity")
private void putAllInternal(@Nonnull Map<? extends K, ? extends V> map, @Nullable InternalCompletableFuture<Void> future, boolean triggerMapLoader) {
    if (map.isEmpty()) {
        if (future != null) {
            future.complete(null);
        }
        return;
    }
    checkNotNull(map, "Null argument map is not allowed");
    ClientPartitionService partitionService = getContext().getPartitionService();
    int partitionCount = partitionService.getPartitionCount();
    Map<Integer, List<Map.Entry<Data, Data>>> entryMap = new HashMap<>(partitionCount);
    for (Entry<? extends K, ? extends V> entry : map.entrySet()) {
        checkNotNull(entry.getKey(), NULL_KEY_IS_NOT_ALLOWED);
        checkNotNull(entry.getValue(), NULL_VALUE_IS_NOT_ALLOWED);
        Data keyData = toData(entry.getKey());
        int partitionId = partitionService.getPartitionId(keyData);
        List<Map.Entry<Data, Data>> partition = entryMap.get(partitionId);
        if (partition == null) {
            partition = new ArrayList<>();
            entryMap.put(partitionId, partition);
        }
        partition.add(new AbstractMap.SimpleEntry<>(keyData, toData(entry.getValue())));
    }
    assert entryMap.size() > 0;
    AtomicInteger counter = new AtomicInteger(entryMap.size());
    InternalCompletableFuture<Void> resultFuture = future != null ? future : new InternalCompletableFuture<>();
    BiConsumer<ClientMessage, Throwable> callback = (response, t) -> {
        if (t != null) {
            resultFuture.completeExceptionally(t);
        }
        if (counter.decrementAndGet() == 0) {
            finalizePutAll(map, entryMap);
            if (!resultFuture.isDone()) {
                resultFuture.complete(null);
            }
        }
    };
    for (Entry<Integer, List<Map.Entry<Data, 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 = MapPutAllCodec.encodeRequest(name, entry.getValue(), triggerMapLoader);
        new ClientInvocation(getClient(), request, getName(), partitionId).invoke().whenCompleteAsync(callback);
    }
    // if executing in sync mode, block for the responses
    if (future == null) {
        try {
            resultFuture.get();
        } catch (Throwable e) {
            throw rethrow(e);
        }
    }
}
Also used : MapGetAllCodec(com.hazelcast.client.impl.protocol.codec.MapGetAllCodec) MapSetTtlCodec(com.hazelcast.client.impl.protocol.codec.MapSetTtlCodec) MapForceUnlockCodec(com.hazelcast.client.impl.protocol.codec.MapForceUnlockCodec) PartitionPredicate(com.hazelcast.query.PartitionPredicate) MapRemoveEntryListenerCodec(com.hazelcast.client.impl.protocol.codec.MapRemoveEntryListenerCodec) MapTryLockCodec(com.hazelcast.client.impl.protocol.codec.MapTryLockCodec) ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) Thread.currentThread(java.lang.Thread.currentThread) ExceptionUtil.rethrow(com.hazelcast.internal.util.ExceptionUtil.rethrow) MapContainsValueCodec(com.hazelcast.client.impl.protocol.codec.MapContainsValueCodec) MapEntrySetCodec(com.hazelcast.client.impl.protocol.codec.MapEntrySetCodec) SerializationUtil(com.hazelcast.internal.serialization.impl.SerializationUtil) ListenerMessageCodec(com.hazelcast.client.impl.spi.impl.ListenerMessageCodec) Future(java.util.concurrent.Future) MapAddEntryListenerWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapAddEntryListenerWithPredicateCodec) MapLockCodec(com.hazelcast.client.impl.protocol.codec.MapLockCodec) MapPutTransientWithMaxIdleCodec(com.hazelcast.client.impl.protocol.codec.MapPutTransientWithMaxIdleCodec) SerializationService(com.hazelcast.internal.serialization.SerializationService) Map(java.util.Map) MapSizeCodec(com.hazelcast.client.impl.protocol.codec.MapSizeCodec) MapSetWithMaxIdleCodec(com.hazelcast.client.impl.protocol.codec.MapSetWithMaxIdleCodec) ClientMapQueryPartitionIterable(com.hazelcast.client.map.impl.iterator.ClientMapQueryPartitionIterable) MapValuesWithPagingPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapValuesWithPagingPredicateCodec) MapExecuteOnAllKeysCodec(com.hazelcast.client.impl.protocol.codec.MapExecuteOnAllKeysCodec) MapClearCodec(com.hazelcast.client.impl.protocol.codec.MapClearCodec) ClientPartitionService(com.hazelcast.client.impl.spi.ClientPartitionService) Set(java.util.Set) EntryView(com.hazelcast.core.EntryView) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) MapRemovePartitionLostListenerCodec(com.hazelcast.client.impl.protocol.codec.MapRemovePartitionLostListenerCodec) MapReplaceCodec(com.hazelcast.client.impl.protocol.codec.MapReplaceCodec) MapRemoveIfSameCodec(com.hazelcast.client.impl.protocol.codec.MapRemoveIfSameCodec) MapKeySetCodec(com.hazelcast.client.impl.protocol.codec.MapKeySetCodec) UnmodifiableLazyList(com.hazelcast.spi.impl.UnmodifiableLazyList) MapPutIfAbsentCodec(com.hazelcast.client.impl.protocol.codec.MapPutIfAbsentCodec) MapRemoveCodec(com.hazelcast.client.impl.protocol.codec.MapRemoveCodec) Preconditions.checkNotInstanceOf(com.hazelcast.internal.util.Preconditions.checkNotInstanceOf) Preconditions.checkPositive(com.hazelcast.internal.util.Preconditions.checkPositive) IterationType(com.hazelcast.internal.util.IterationType) MapAggregateCodec(com.hazelcast.client.impl.protocol.codec.MapAggregateCodec) ClientMapQueryPartitionIterator(com.hazelcast.client.map.impl.iterator.ClientMapQueryPartitionIterator) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) MapAddInterceptorCodec(com.hazelcast.client.impl.protocol.codec.MapAddInterceptorCodec) MapFlushCodec(com.hazelcast.client.impl.protocol.codec.MapFlushCodec) MapPutCodec(com.hazelcast.client.impl.protocol.codec.MapPutCodec) ClientMapQueryIterable(com.hazelcast.client.map.impl.iterator.ClientMapQueryIterable) ClientQueryCacheContext(com.hazelcast.client.map.impl.querycache.ClientQueryCacheContext) MapAddEntryListenerToKeyCodec(com.hazelcast.client.impl.protocol.codec.MapAddEntryListenerToKeyCodec) DataAwareEntryEvent(com.hazelcast.map.impl.DataAwareEntryEvent) IMapEvent(com.hazelcast.map.IMapEvent) UNSET(com.hazelcast.map.impl.record.Record.UNSET) MapProjectWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapProjectWithPredicateCodec) ArrayList(java.util.ArrayList) MapAddEntryListenerToKeyWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapAddEntryListenerToKeyWithPredicateCodec) MapLoadAllCodec(com.hazelcast.client.impl.protocol.codec.MapLoadAllCodec) ClientContext(com.hazelcast.client.impl.spi.ClientContext) BiConsumer(java.util.function.BiConsumer) PagingPredicateHolder(com.hazelcast.client.impl.protocol.codec.holder.PagingPredicateHolder) MapAddEntryListenerCodec(com.hazelcast.client.impl.protocol.codec.MapAddEntryListenerCodec) Nullable(javax.annotation.Nullable) LocalMapStats(com.hazelcast.map.LocalMapStats) MapEntriesWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapEntriesWithPredicateCodec) MapKeySetWithPagingPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapKeySetWithPagingPredicateCodec) ThreadUtil.getThreadId(com.hazelcast.internal.util.ThreadUtil.getThreadId) MapSubmitToKeyCodec(com.hazelcast.client.impl.protocol.codec.MapSubmitToKeyCodec) ClientMapIterator(com.hazelcast.client.map.impl.iterator.ClientMapIterator) QueryCacheEndToEndProvider(com.hazelcast.map.impl.querycache.subscriber.QueryCacheEndToEndProvider) MapGetCodec(com.hazelcast.client.impl.protocol.codec.MapGetCodec) MapDeleteCodec(com.hazelcast.client.impl.protocol.codec.MapDeleteCodec) TimeUtil.timeInMsOrTimeIfNullUnit(com.hazelcast.internal.util.TimeUtil.timeInMsOrTimeIfNullUnit) MapProjectCodec(com.hazelcast.client.impl.protocol.codec.MapProjectCodec) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) LocalMapStatsImpl(com.hazelcast.internal.monitor.impl.LocalMapStatsImpl) ClientMapPartitionIterator(com.hazelcast.client.map.impl.iterator.ClientMapPartitionIterator) MapSetCodec(com.hazelcast.client.impl.protocol.codec.MapSetCodec) EntryProcessor(com.hazelcast.map.EntryProcessor) ReadOnly(com.hazelcast.core.ReadOnly) ClientMapIterable(com.hazelcast.client.map.impl.iterator.ClientMapIterable) ClientMapPartitionIterable(com.hazelcast.client.map.impl.iterator.ClientMapPartitionIterable) MapAddIndexCodec(com.hazelcast.client.impl.protocol.codec.MapAddIndexCodec) MapEvent(com.hazelcast.map.MapEvent) ListenerAdapter(com.hazelcast.map.impl.ListenerAdapter) MapExecuteOnKeyCodec(com.hazelcast.client.impl.protocol.codec.MapExecuteOnKeyCodec) MapLoadGivenKeysCodec(com.hazelcast.client.impl.protocol.codec.MapLoadGivenKeysCodec) Member(com.hazelcast.cluster.Member) BiFunction(java.util.function.BiFunction) ListenerAdapters.createListenerAdapter(com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter) MapPutIfAbsentWithMaxIdleCodec(com.hazelcast.client.impl.protocol.codec.MapPutIfAbsentWithMaxIdleCodec) CollectionUtil(com.hazelcast.internal.util.CollectionUtil) MapValuesWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapValuesWithPredicateCodec) EventHandler(com.hazelcast.client.impl.spi.EventHandler) MapContainsKeyCodec(com.hazelcast.client.impl.protocol.codec.MapContainsKeyCodec) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) MapAggregateWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapAggregateWithPredicateCodec) MapListener(com.hazelcast.map.listener.MapListener) MapAddPartitionLostListenerCodec(com.hazelcast.client.impl.protocol.codec.MapAddPartitionLostListenerCodec) PredicateUtils.unwrapPagingPredicate(com.hazelcast.query.impl.predicates.PredicateUtils.unwrapPagingPredicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexUtils(com.hazelcast.query.impl.IndexUtils) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) Predicate(com.hazelcast.query.Predicate) ClientLockReferenceIdGenerator(com.hazelcast.client.impl.clientside.ClientLockReferenceIdGenerator) EntryEvent(com.hazelcast.core.EntryEvent) MapPutWithMaxIdleCodec(com.hazelcast.client.impl.protocol.codec.MapPutWithMaxIdleCodec) MapIsLockedCodec(com.hazelcast.client.impl.protocol.codec.MapIsLockedCodec) Collection(java.util.Collection) UUID(java.util.UUID) SubscriberContext(com.hazelcast.map.impl.querycache.subscriber.SubscriberContext) IndexConfig(com.hazelcast.config.IndexConfig) MapEvictCodec(com.hazelcast.client.impl.protocol.codec.MapEvictCodec) List(java.util.List) MapEntriesWithPagingPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapEntriesWithPagingPredicateCodec) MapGetEntryViewCodec(com.hazelcast.client.impl.protocol.codec.MapGetEntryViewCodec) EventJournalMapEvent(com.hazelcast.map.EventJournalMapEvent) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture) MapEventJournalSubscribeCodec(com.hazelcast.client.impl.protocol.codec.MapEventJournalSubscribeCodec) MapReplaceIfSameCodec(com.hazelcast.client.impl.protocol.codec.MapReplaceIfSameCodec) QueryCacheRequest(com.hazelcast.map.impl.querycache.subscriber.QueryCacheRequest) TimeUtil.timeInMsOrOneIfResultIsZero(com.hazelcast.internal.util.TimeUtil.timeInMsOrOneIfResultIsZero) MapPartitionLostEvent(com.hazelcast.map.MapPartitionLostEvent) Projection(com.hazelcast.projection.Projection) MapExecuteWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapExecuteWithPredicateCodec) MapEventJournalReadCodec(com.hazelcast.client.impl.protocol.codec.MapEventJournalReadCodec) QueryCacheRequest.newQueryCacheRequest(com.hazelcast.map.impl.querycache.subscriber.QueryCacheRequest.newQueryCacheRequest) MapKeySetWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapKeySetWithPredicateCodec) MapRemoveInterceptorCodec(com.hazelcast.client.impl.protocol.codec.MapRemoveInterceptorCodec) ResponseParameters(com.hazelcast.client.impl.protocol.codec.MapEventJournalSubscribeCodec.ResponseParameters) CollectionUtil.objectToDataCollection(com.hazelcast.internal.util.CollectionUtil.objectToDataCollection) MapTryRemoveCodec(com.hazelcast.client.impl.protocol.codec.MapTryRemoveCodec) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) HashMap(java.util.HashMap) Function(java.util.function.Function) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Aggregator(com.hazelcast.aggregation.Aggregator) MapIsEmptyCodec(com.hazelcast.client.impl.protocol.codec.MapIsEmptyCodec) PagingPredicate(com.hazelcast.query.PagingPredicate) MapValuesCodec(com.hazelcast.client.impl.protocol.codec.MapValuesCodec) MapRemoveAllCodec(com.hazelcast.client.impl.protocol.codec.MapRemoveAllCodec) MapUnlockCodec(com.hazelcast.client.impl.protocol.codec.MapUnlockCodec) Nonnull(javax.annotation.Nonnull) MapListenerFlagOperator.setAndGetListenerFlags(com.hazelcast.map.impl.MapListenerFlagOperator.setAndGetListenerFlags) MapPutTransientCodec(com.hazelcast.client.impl.protocol.codec.MapPutTransientCodec) Collections.emptyMap(java.util.Collections.emptyMap) Iterator(java.util.Iterator) EntryEventType(com.hazelcast.core.EntryEventType) EventJournalReader(com.hazelcast.internal.journal.EventJournalReader) MapInterceptor(com.hazelcast.map.MapInterceptor) UnmodifiableLazySet(com.hazelcast.spi.impl.UnmodifiableLazySet) Data(com.hazelcast.internal.serialization.Data) MapPutAllCodec(com.hazelcast.client.impl.protocol.codec.MapPutAllCodec) MapEvictAllCodec(com.hazelcast.client.impl.protocol.codec.MapEvictAllCodec) MapTryPutCodec(com.hazelcast.client.impl.protocol.codec.MapTryPutCodec) ClientProxy(com.hazelcast.client.impl.spi.ClientProxy) MapExecuteOnKeysCodec(com.hazelcast.client.impl.protocol.codec.MapExecuteOnKeysCodec) TimeUnit(java.util.concurrent.TimeUnit) AbstractMap(java.util.AbstractMap) PagingPredicateImpl(com.hazelcast.query.impl.predicates.PagingPredicateImpl) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) QueryCache(com.hazelcast.map.QueryCache) MapPartitionLostListener(com.hazelcast.map.listener.MapPartitionLostListener) ReadResultSet(com.hazelcast.ringbuffer.ReadResultSet) EventJournalInitialSubscriberState(com.hazelcast.internal.journal.EventJournalInitialSubscriberState) Collections(java.util.Collections) MapReplaceAllCodec(com.hazelcast.client.impl.protocol.codec.MapReplaceAllCodec) IMap(com.hazelcast.map.IMap) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) 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) UnmodifiableLazyList(com.hazelcast.spi.impl.UnmodifiableLazyList) ArrayList(java.util.ArrayList) List(java.util.List) ClientPartitionService(com.hazelcast.client.impl.spi.ClientPartitionService) Map(java.util.Map) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Collections.emptyMap(java.util.Collections.emptyMap) AbstractMap(java.util.AbstractMap) IMap(com.hazelcast.map.IMap)

Example 4 with ClientPartitionService

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

the class ClientMapProxy method iterator.

@Override
@Nonnull
public Iterator<Entry<K, V>> iterator(int fetchSize) {
    ClientPartitionService partitionService = getContext().getPartitionService();
    int partitionCount = partitionService.getPartitionCount();
    return new ClientMapIterator<>(this, fetchSize, partitionCount, false);
}
Also used : ClientMapIterator(com.hazelcast.client.map.impl.iterator.ClientMapIterator) ClientPartitionService(com.hazelcast.client.impl.spi.ClientPartitionService) Nonnull(javax.annotation.Nonnull)

Example 5 with ClientPartitionService

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

the class ClientMapProxy method fillPartitionToKeyData.

protected void fillPartitionToKeyData(Set<K> keys, Map<Integer, List<Data>> partitionToKeyData, Map<Object, Data> keyMap, Map<Data, Object> reverseKeyMap) {
    ClientPartitionService partitionService = getContext().getPartitionService();
    for (K key : keys) {
        Data keyData = toData(key);
        int partitionId = partitionService.getPartitionId(keyData);
        List<Data> keyList = partitionToKeyData.get(partitionId);
        if (keyList == null) {
            keyList = new ArrayList<>();
            partitionToKeyData.put(partitionId, keyList);
        }
        keyList.add(keyData);
        if (keyMap != null) {
            keyMap.put(key, keyData);
        }
        if (reverseKeyMap != null) {
            reverseKeyMap.put(keyData, key);
        }
    }
}
Also used : Data(com.hazelcast.internal.serialization.Data) ClientPartitionService(com.hazelcast.client.impl.spi.ClientPartitionService)

Aggregations

ClientPartitionService (com.hazelcast.client.impl.spi.ClientPartitionService)11 Data (com.hazelcast.internal.serialization.Data)5 Nonnull (javax.annotation.Nonnull)4 ClientMapIterator (com.hazelcast.client.map.impl.iterator.ClientMapIterator)3 AbstractMap (java.util.AbstractMap)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ClientLockReferenceIdGenerator (com.hazelcast.client.impl.clientside.ClientLockReferenceIdGenerator)2 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)2 ClientContext (com.hazelcast.client.impl.spi.ClientContext)2 ClientProxy (com.hazelcast.client.impl.spi.ClientProxy)2 EventHandler (com.hazelcast.client.impl.spi.EventHandler)2 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)2 ListenerMessageCodec (com.hazelcast.client.impl.spi.impl.ListenerMessageCodec)2 Member (com.hazelcast.cluster.Member)2 EntryEvent (com.hazelcast.core.EntryEvent)2 EntryEventType (com.hazelcast.core.EntryEventType)2 CollectionUtil (com.hazelcast.internal.util.CollectionUtil)2 Preconditions.checkNotNull (com.hazelcast.internal.util.Preconditions.checkNotNull)2 Preconditions.checkPositive (com.hazelcast.internal.util.Preconditions.checkPositive)2