Search in sources :

Example 11 with MapEntries

use of com.hazelcast.map.impl.MapEntries in project hazelcast by hazelcast.

the class PutAllPartitionAwareOperationFactory method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    name = in.readUTF();
    partitions = in.readIntArray();
    mapEntries = new MapEntries[partitions.length];
    for (int i = 0; i < partitions.length; i++) {
        MapEntries entry = new MapEntries();
        entry.readData(in);
        mapEntries[i] = entry;
    }
}
Also used : MapEntries(com.hazelcast.map.impl.MapEntries)

Example 12 with MapEntries

use of com.hazelcast.map.impl.MapEntries in project hazelcast by hazelcast.

the class MultipleEntryOperation method run.

@Override
@SuppressWarnings("checkstyle:npathcomplexity")
public void run() throws Exception {
    long now = getNow();
    boolean shouldClone = mapContainer.shouldCloneOnEntryProcessing();
    SerializationService serializationService = getNodeEngine().getSerializationService();
    responses = new MapEntries(keys.size());
    for (Data key : keys) {
        if (!isKeyProcessable(key)) {
            continue;
        }
        Object oldValue = recordStore.get(key, false);
        Object value = shouldClone ? serializationService.toObject(serializationService.toData(oldValue)) : oldValue;
        Map.Entry entry = createMapEntry(key, value);
        if (!isEntryProcessable(entry)) {
            continue;
        }
        Data response = process(entry);
        if (response != null) {
            responses.add(key, response);
        }
        // first call noOp, other if checks below depends on it.
        if (noOp(entry, oldValue, now)) {
            continue;
        }
        if (entryRemoved(entry, key, oldValue, now)) {
            continue;
        }
        entryAddedOrUpdated(entry, key, oldValue, now);
        evict(key);
    }
}
Also used : MapEntries(com.hazelcast.map.impl.MapEntries) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) Map(java.util.Map)

Example 13 with MapEntries

use of com.hazelcast.map.impl.MapEntries in project hazelcast by hazelcast.

the class MapProxySupport method executeOnKeysInternal.

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;
}
Also used : HashMap(java.util.HashMap) MapEntries(com.hazelcast.map.impl.MapEntries) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.InitializingObject) OperationFactory(com.hazelcast.spi.OperationFactory) IsEmptyOperationFactory(com.hazelcast.map.impl.operation.IsEmptyOperationFactory) BinaryOperationFactory(com.hazelcast.spi.impl.BinaryOperationFactory) IsPartitionLoadedOperationFactory(com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory)

Example 14 with MapEntries

use of com.hazelcast.map.impl.MapEntries in project hazelcast by hazelcast.

the class MapPutAllWrongTargetForPartitionTest method createPutAllOperationFactory.

private PartitionAwareOperationFactory createPutAllOperationFactory(int entriesPerPartition, String mapName, HazelcastInstance hz, SerializationService serializationService) {
    int[] partitions = new int[INSTANCE_COUNT];
    MapEntries[] entries = new MapEntries[INSTANCE_COUNT];
    for (int partitionId = 0; partitionId < INSTANCE_COUNT; partitionId++) {
        MapEntries mapEntries = new MapEntries(entriesPerPartition);
        for (int i = 0; i < entriesPerPartition; i++) {
            String key = generateKeyForPartition(hz, partitionId);
            Data data = serializationService.toData(key);
            mapEntries.add(data, data);
        }
        partitions[partitionId] = partitionId;
        entries[partitionId] = mapEntries;
    }
    return getPutAllPartitionAwareOperationFactory(mapName, partitions, entries);
}
Also used : MapEntries(com.hazelcast.map.impl.MapEntries) Data(com.hazelcast.nio.serialization.Data)

Example 15 with MapEntries

use of com.hazelcast.map.impl.MapEntries in project hazelcast by hazelcast.

the class MapProxySupport method putAllInternal.

/**
     * 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);
    }
}
Also used : Address(com.hazelcast.nio.Address) Data(com.hazelcast.nio.serialization.Data) MutableLong(com.hazelcast.util.MutableLong) Entry(java.util.Map.Entry) MapEntries(com.hazelcast.map.impl.MapEntries) List(java.util.List) ArrayList(java.util.ArrayList) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

MapEntries (com.hazelcast.map.impl.MapEntries)19 Data (com.hazelcast.nio.serialization.Data)11 Map (java.util.Map)7 ArrayList (java.util.ArrayList)5 OperationFactory (com.hazelcast.spi.OperationFactory)4 MapService (com.hazelcast.map.impl.MapService)3 IsEmptyOperationFactory (com.hazelcast.map.impl.operation.IsEmptyOperationFactory)3 IsPartitionLoadedOperationFactory (com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory)3 AbstractDistributedObject (com.hazelcast.spi.AbstractDistributedObject)3 InitializingObject (com.hazelcast.spi.InitializingObject)3 BinaryOperationFactory (com.hazelcast.spi.impl.BinaryOperationFactory)3 Record (com.hazelcast.map.impl.record.Record)2 SerializationService (com.hazelcast.spi.serialization.SerializationService)2 HashMap (java.util.HashMap)2 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)1 MapOperationProvider (com.hazelcast.map.impl.operation.MapOperationProvider)1 RecordInfo (com.hazelcast.map.impl.record.RecordInfo)1 Records.applyRecordInfo (com.hazelcast.map.impl.record.Records.applyRecordInfo)1 Address (com.hazelcast.nio.Address)1 OperationService (com.hazelcast.spi.OperationService)1