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);
}
}
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);
}
Aggregations