@Override protected Operation prepareOperation() { MapEntries mapEntries = new MapEntries(); for (Map.Entry<Data, Data> entry : parameters.entries) { mapEntries.add(entry.getKey(), entry.getValue()); } MapOperationProvider operationProvider = getMapOperationProvider(parameters.name); return operationProvider.createPutAllOperation(parameters.name, mapEntries, false); }
protected void addToResponses(Data key, Data response) { if (response == null) { return; } if (responses == null) { responses = new MapEntries(); } responses.add(new AbstractMap.SimpleImmutableEntry<Data, Data>(key, response)); }
/** {@link IMap#executeOnEntries(EntryProcessor, Predicate)} */ public void executeOnEntriesInternal( EntryProcessor entryProcessor, Predicate predicate, List<Data> result) { try { OperationFactory operation = operationProvider.createPartitionWideEntryWithPredicateOperationFactory( name, entryProcessor, predicate); Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, operation); for (Object object : results.values()) { if (object != null) { MapEntries mapEntries = (MapEntries) object; for (int i = 0; i < mapEntries.size(); i++) { result.add(mapEntries.getKey(i)); result.add(mapEntries.getValue(i)); } } } } catch (Throwable t) { throw rethrow(t); } }
public Map executeOnKeysInternal(Set<Data> keys, EntryProcessor entryProcessor) { // TODO: why are we not forwarding to executeOnKeysInternal(keys, entryProcessor, null) or some // other kind of fake // callback? now there is a lot of code duplication Map<Object, Object> result = new HashMap<Object, Object>(); Collection<Integer> partitionsForKeys = getPartitionsForKeys(keys); try { OperationFactory operationFactory = operationProvider.createMultipleEntryOperationFactory(name, keys, entryProcessor); Map<Integer, Object> results = operationService.invokeOnPartitions(SERVICE_NAME, operationFactory, partitionsForKeys); for (Object object : results.values()) { if (object != null) { MapEntries mapEntries = (MapEntries) object; mapEntries.putAllToMap(serializationService, result); } } } catch (Throwable t) { throw rethrow(t); } return result; }
protected void getAllObjectInternal(List<Data> keys, List<Object> resultingKeyValuePairs) { if (keys == null || keys.isEmpty()) { return; } if (keys.isEmpty()) { return; } Collection<Integer> partitions = getPartitionsForKeys(keys); Map<Integer, Object> responses; try { OperationFactory operationFactory = operationProvider.createGetAllOperationFactory(name, keys); responses = operationService.invokeOnPartitions(SERVICE_NAME, operationFactory, partitions); for (Object response : responses.values()) { MapEntries entries = toObject(response); for (int i = 0; i < entries.size(); i++) { resultingKeyValuePairs.add(toObject(entries.getKey(i))); resultingKeyValuePairs.add(toObject(entries.getValue(i))); } } } catch (Exception e) { throw rethrow(e); } }
/** * This method will group all puts per partition and send a {@link * com.hazelcast.map.impl.operation.PutAllPartitionAwareOperationFactory} per member. * * <p>If there are e.g. five keys for a single member, there will only be a single remote * invocation instead of having five remote invocations. * * <p>There is also an optional support for batching to send smaller packages. Takes care about * {@code null} checks for keys and values. */ @SuppressWarnings({"checkstyle:npathcomplexity", "UnnecessaryBoxing"}) @SuppressFBWarnings( value = "DM_NUMBER_CTOR", justification = "we need a shared counter object for each member per partition") protected void putAllInternal(Map<?, ?> map) { try { int mapSize = map.size(); if (mapSize == 0) { return; } boolean useBatching = isPutAllUseBatching(mapSize); int partitionCount = partitionService.getPartitionCount(); int initialSize = getPutAllInitialSize(useBatching, mapSize, partitionCount); Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap(); // init counters for batching MutableLong[] counterPerMember = null; Address[] addresses = null; if (useBatching) { counterPerMember = new MutableLong[partitionCount]; addresses = new Address[partitionCount]; for (Entry<Address, List<Integer>> addressListEntry : memberPartitionsMap.entrySet()) { MutableLong counter = new MutableLong(); Address address = addressListEntry.getKey(); for (int partitionId : addressListEntry.getValue()) { counterPerMember[partitionId] = counter; addresses[partitionId] = address; } } } // fill entriesPerPartition MapEntries[] entriesPerPartition = new MapEntries[partitionCount]; for (Entry entry : map.entrySet()) { checkNotNull(entry.getKey(), NULL_KEY_IS_NOT_ALLOWED); checkNotNull(entry.getValue(), NULL_VALUE_IS_NOT_ALLOWED); Data keyData = toData(entry.getKey(), partitionStrategy); int partitionId = partitionService.getPartitionId(keyData); MapEntries entries = entriesPerPartition[partitionId]; if (entries == null) { entries = new MapEntries(initialSize); entriesPerPartition[partitionId] = entries; } entries.add(keyData, toData(entry.getValue())); if (useBatching) { long currentSize = ++counterPerMember[partitionId].value; if (currentSize % putAllBatchSize == 0) { List<Integer> partitions = memberPartitionsMap.get(addresses[partitionId]); invokePutAllOperation(addresses[partitionId], partitions, entriesPerPartition); } } } // invoke operations for entriesPerPartition for (Entry<Address, List<Integer>> entry : memberPartitionsMap.entrySet()) { invokePutAllOperation(entry.getKey(), entry.getValue(), entriesPerPartition); } } catch (Exception e) { throw rethrow(e); } }