Search in sources :

Example 1 with ClientPartitionService

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

the class ClientMapProxy method getAll.

@Override
@SuppressWarnings("unchecked")
public Map<K, V> getAll(Set<K> keys) {
    if (CollectionUtil.isEmpty(keys)) {
        return emptyMap();
    }
    Map<Integer, List<Data>> partitionToKeyData = new HashMap<Integer, List<Data>>();
    ClientPartitionService partitionService = getContext().getPartitionService();
    for (Object key : keys) {
        Data keyData = toData(key);
        int partitionId = partitionService.getPartitionId(keyData);
        List<Data> keyList = partitionToKeyData.get(partitionId);
        if (keyList == null) {
            keyList = new ArrayList<Data>();
            partitionToKeyData.put(partitionId, keyList);
        }
        keyList.add(keyData);
    }
    Map<K, V> result = new HashMap<K, V>();
    getAllInternal(partitionToKeyData, result);
    return result;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Data(com.hazelcast.nio.serialization.Data) UnmodifiableLazyList(com.hazelcast.spi.impl.UnmodifiableLazyList) ArrayList(java.util.ArrayList) List(java.util.List) ClientPartitionService(com.hazelcast.client.spi.ClientPartitionService)

Example 2 with ClientPartitionService

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

the class ClientMapProxy method putAll.

@Override
public void putAll(Map<? extends K, ? extends V> m) {
    ClientPartitionService partitionService = getContext().getPartitionService();
    Map<Integer, List<Map.Entry<Data, Data>>> entryMap = new HashMap<Integer, List<Map.Entry<Data, Data>>>(partitionService.getPartitionCount());
    for (Entry<? extends K, ? extends V> entry : m.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<Map.Entry<Data, Data>>();
            entryMap.put(partitionId, partition);
        }
        partition.add(new AbstractMap.SimpleEntry<Data, Data>(keyData, toData(entry.getValue())));
    }
    putAllInternal(entryMap);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Data(com.hazelcast.nio.serialization.Data) AbstractMap(java.util.AbstractMap) LazyMapEntry(com.hazelcast.map.impl.LazyMapEntry) UnmodifiableLazyList(com.hazelcast.spi.impl.UnmodifiableLazyList) ArrayList(java.util.ArrayList) List(java.util.List) ClientPartitionService(com.hazelcast.client.spi.ClientPartitionService) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Collections.emptyMap(java.util.Collections.emptyMap) AbstractMap(java.util.AbstractMap) IMap(com.hazelcast.core.IMap)

Example 3 with ClientPartitionService

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

the class AbstractClientCacheProxy method putAll.

@Override
public void putAll(Map<? extends K, ? extends V> map, ExpiryPolicy expiryPolicy) {
    final long start = System.nanoTime();
    ensureOpen();
    validateNotNull(map);
    try {
        ClientPartitionService partitionService = clientContext.getPartitionService();
        int partitionCount = partitionService.getPartitionCount();
        // First we fill entry set per partition
        List<Map.Entry<Data, Data>>[] entriesPerPartition = groupDataToPartitions(map, partitionService, partitionCount);
        // Then we invoke the operations and sync on completion of these operations
        putToAllPartitionsAndWaitForCompletion(entriesPerPartition, expiryPolicy, start);
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Data(com.hazelcast.nio.serialization.Data) ClientPartitionService(com.hazelcast.client.spi.ClientPartitionService) MapUtil.createHashMap(com.hazelcast.util.MapUtil.createHashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) AbstractMap(java.util.AbstractMap) CacheException(javax.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with ClientPartitionService

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

the class ClientDurableExecutorServiceProxy method onInitialize.

@Override
protected void onInitialize() {
    ClientContext context = getContext();
    ClientPartitionService partitionService = context.getPartitionService();
    partitionCount = partitionService.getPartitionCount();
}
Also used : ClientContext(com.hazelcast.client.spi.ClientContext) ClientPartitionService(com.hazelcast.client.spi.ClientPartitionService)

Example 5 with ClientPartitionService

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

the class ClientPartitionServiceLiteMemberTest method testPartitionsBlockingSucceedsWithLiteMemberAndDataMember.

@Test
public void testPartitionsBlockingSucceedsWithLiteMemberAndDataMember() {
    factory.newHazelcastInstance();
    factory.newHazelcastInstance(new Config().setLiteMember(true));
    final HazelcastInstance client = factory.newHazelcastClient();
    final ClientPartitionService clientPartitionService = getClientPartitionService(client);
    assertNotNull(clientPartitionService.getPartitionOwner(0));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ClientPartitionService(com.hazelcast.client.spi.ClientPartitionService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ClientPartitionService (com.hazelcast.client.spi.ClientPartitionService)7 Data (com.hazelcast.nio.serialization.Data)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 AbstractMap (java.util.AbstractMap)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Config (com.hazelcast.config.Config)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 IMap (com.hazelcast.core.IMap)2 UnmodifiableLazyList (com.hazelcast.spi.impl.UnmodifiableLazyList)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Collections.emptyMap (java.util.Collections.emptyMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Test (org.junit.Test)2 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 MapPutAllCodec (com.hazelcast.client.impl.protocol.codec.MapPutAllCodec)1 ClientMapProxy (com.hazelcast.client.proxy.ClientMapProxy)1