Search in sources :

Example 1 with ReplicatedMapEntries

use of com.hazelcast.replicatedmap.impl.client.ReplicatedMapEntries in project hazelcast by hazelcast.

the class ReplicatedMapProxy method putAll.

@Override
public void putAll(Map<? extends K, ? extends V> entries) {
    checkNotNull(entries, "entries cannot be null");
    int mapSize = entries.size();
    if (mapSize == 0) {
        return;
    }
    int partitionCount = partitionService.getPartitionCount();
    int initialSize = getPutAllInitialSize(mapSize, partitionCount);
    try {
        List<Future> futures = new ArrayList<Future>(partitionCount);
        ReplicatedMapEntries[] entrySetPerPartition = new ReplicatedMapEntries[partitionCount];
        // first we fill entrySetPerPartition
        for (Entry entry : entries.entrySet()) {
            isNotNull(entry.getKey(), "key");
            isNotNull(entry.getValue(), "value");
            int partitionId = partitionService.getPartitionId(entry.getKey());
            ReplicatedMapEntries mapEntries = entrySetPerPartition[partitionId];
            if (mapEntries == null) {
                mapEntries = new ReplicatedMapEntries(initialSize);
                entrySetPerPartition[partitionId] = mapEntries;
            }
            Data keyData = serializationService.toData(entry.getKey());
            Data valueData = serializationService.toData(entry.getValue());
            mapEntries.add(keyData, valueData);
        }
        // then we invoke the operations
        for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
            ReplicatedMapEntries entrySet = entrySetPerPartition[partitionId];
            if (entrySet != null) {
                Future future = createPutAllOperationFuture(name, entrySet, partitionId);
                futures.add(future);
            }
        }
        // then we sync on completion of these operations
        for (Future future : futures) {
            future.get();
        }
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ArrayList(java.util.ArrayList) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Future(java.util.concurrent.Future) Data(com.hazelcast.nio.serialization.Data) ReplicatedMapEntries(com.hazelcast.replicatedmap.impl.client.ReplicatedMapEntries)

Example 2 with ReplicatedMapEntries

use of com.hazelcast.replicatedmap.impl.client.ReplicatedMapEntries in project hazelcast by hazelcast.

the class EntrySetOperation method run.

@Override
public void run() throws Exception {
    ReplicatedMapService service = getService();
    Collection<ReplicatedRecordStore> stores = service.getAllReplicatedRecordStores(name);
    List<Map.Entry<Object, ReplicatedRecord>> entries = new ArrayList<Map.Entry<Object, ReplicatedRecord>>();
    for (ReplicatedRecordStore store : stores) {
        entries.addAll(store.entrySet(false));
    }
    ArrayList<Map.Entry<Data, Data>> dataEntries = new ArrayList<Map.Entry<Data, Data>>(entries.size());
    SerializationService serializationService = getNodeEngine().getSerializationService();
    for (Map.Entry<Object, ReplicatedRecord> entry : entries) {
        Data key = serializationService.toData(entry.getKey());
        Data value = serializationService.toData(entry.getValue().getValue());
        dataEntries.add(new AbstractMap.SimpleImmutableEntry<Data, Data>(key, value));
    }
    response = new ReplicatedMapEntries(dataEntries);
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) AbstractMap(java.util.AbstractMap) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) AbstractMap(java.util.AbstractMap) Map(java.util.Map) ReplicatedMapEntries(com.hazelcast.replicatedmap.impl.client.ReplicatedMapEntries)

Aggregations

Data (com.hazelcast.nio.serialization.Data)2 ReplicatedMapEntries (com.hazelcast.replicatedmap.impl.client.ReplicatedMapEntries)2 ArrayList (java.util.ArrayList)2 ReplicatedMapService (com.hazelcast.replicatedmap.impl.ReplicatedMapService)1 ReplicatedRecord (com.hazelcast.replicatedmap.impl.record.ReplicatedRecord)1 ReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore)1 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)1 SerializationService (com.hazelcast.spi.serialization.SerializationService)1 AbstractMap (java.util.AbstractMap)1 Map (java.util.Map)1 Future (java.util.concurrent.Future)1