Search in sources :

Example 11 with MultiMapRecord

use of com.hazelcast.multimap.impl.MultiMapRecord in project hazelcast by hazelcast.

the class MultiMapValuesMessageTask method reduce.

@Override
protected Object reduce(Map<Integer, Object> map) {
    List<Data> list = new ArrayList<Data>();
    for (Object obj : map.values()) {
        if (obj == null) {
            continue;
        }
        MultiMapResponse response = (MultiMapResponse) obj;
        Collection<MultiMapRecord> coll = response.getCollection();
        if (coll == null) {
            continue;
        }
        for (MultiMapRecord record : coll) {
            list.add(serializationService.toData(record.getObject()));
        }
    }
    return list;
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse) ArrayList(java.util.ArrayList) Data(com.hazelcast.nio.serialization.Data)

Example 12 with MultiMapRecord

use of com.hazelcast.multimap.impl.MultiMapRecord in project hazelcast by hazelcast.

the class MultiMapMigrationOperation method writeInternal.

@Override
protected void writeInternal(ObjectDataOutput out) throws IOException {
    out.writeInt(map.size());
    for (Map.Entry<String, Map> entry : map.entrySet()) {
        String name = entry.getKey();
        out.writeUTF(name);
        Map<Data, MultiMapValue> collections = entry.getValue();
        out.writeInt(collections.size());
        for (Map.Entry<Data, MultiMapValue> collectionEntry : collections.entrySet()) {
            Data key = collectionEntry.getKey();
            out.writeData(key);
            MultiMapValue multiMapValue = collectionEntry.getValue();
            Collection<MultiMapRecord> coll = multiMapValue.getCollection(false);
            out.writeInt(coll.size());
            String collectionType = MultiMapConfig.ValueCollectionType.SET.name();
            if (coll instanceof List) {
                collectionType = MultiMapConfig.ValueCollectionType.LIST.name();
            }
            out.writeUTF(collectionType);
            for (MultiMapRecord record : coll) {
                record.writeData(out);
            }
        }
    }
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) MultiMapValue(com.hazelcast.multimap.impl.MultiMapValue) Data(com.hazelcast.nio.serialization.Data) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with MultiMapRecord

use of com.hazelcast.multimap.impl.MultiMapRecord in project hazelcast by hazelcast.

the class MultiMapMigrationOperation method readInternal.

@Override
protected void readInternal(ObjectDataInput in) throws IOException {
    int mapSize = in.readInt();
    map = new HashMap<String, Map>(mapSize);
    for (int i = 0; i < mapSize; i++) {
        String name = in.readUTF();
        int collectionSize = in.readInt();
        Map<Data, MultiMapValue> collections = new HashMap<Data, MultiMapValue>();
        for (int j = 0; j < collectionSize; j++) {
            Data key = in.readData();
            int collSize = in.readInt();
            String collectionType = in.readUTF();
            Collection<MultiMapRecord> coll;
            if (collectionType.equals(MultiMapConfig.ValueCollectionType.SET.name())) {
                coll = new HashSet<MultiMapRecord>();
            } else {
                coll = new LinkedList<MultiMapRecord>();
            }
            for (int k = 0; k < collSize; k++) {
                MultiMapRecord record = new MultiMapRecord();
                record.readData(in);
                coll.add(record);
            }
            collections.put(key, new MultiMapValue(coll));
        }
        map.put(name, collections);
    }
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) MultiMapValue(com.hazelcast.multimap.impl.MultiMapValue) HashMap(java.util.HashMap) Data(com.hazelcast.nio.serialization.Data) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with MultiMapRecord

use of com.hazelcast.multimap.impl.MultiMapRecord in project hazelcast by hazelcast.

the class MultiMapResponse method getRecordCollection.

public Collection<MultiMapRecord> getRecordCollection(NodeEngine nodeEngine) {
    if (collection == null) {
        return emptyCollection(collectionType);
    }
    final Collection<MultiMapRecord> newCollection = createCollection(collectionType, collection.size());
    for (Object obj : collection) {
        MultiMapRecord record = nodeEngine.toObject(obj);
        newCollection.add(record);
    }
    return newCollection;
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord)

Example 15 with MultiMapRecord

use of com.hazelcast.multimap.impl.MultiMapRecord in project hazelcast by hazelcast.

the class MultiMapResponse method getObjectCollection.

public Collection getObjectCollection(NodeEngine nodeEngine) {
    if (collection == null) {
        return emptyCollection(collectionType);
    }
    final Collection newCollection = createCollection(collectionType, collection.size());
    for (Object obj : collection) {
        MultiMapRecord record = nodeEngine.toObject(obj);
        newCollection.add(nodeEngine.toObject(record.getObject()));
    }
    return newCollection;
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) ValueCollectionFactory.emptyCollection(com.hazelcast.multimap.impl.ValueCollectionFactory.emptyCollection) Collection(java.util.Collection) ValueCollectionFactory.createCollection(com.hazelcast.multimap.impl.ValueCollectionFactory.createCollection)

Aggregations

MultiMapRecord (com.hazelcast.multimap.impl.MultiMapRecord)26 MultiMapValue (com.hazelcast.multimap.impl.MultiMapValue)11 MultiMapContainer (com.hazelcast.multimap.impl.MultiMapContainer)8 MultiMapResponse (com.hazelcast.multimap.impl.operations.MultiMapResponse)8 Data (com.hazelcast.nio.serialization.Data)7 ArrayList (java.util.ArrayList)5 ConcurrentModificationException (java.util.ConcurrentModificationException)3 List (java.util.List)3 OperationService (com.hazelcast.spi.OperationService)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MultiMapService (com.hazelcast.multimap.impl.MultiMapService)1 ValueCollectionFactory.createCollection (com.hazelcast.multimap.impl.ValueCollectionFactory.createCollection)1 ValueCollectionFactory.emptyCollection (com.hazelcast.multimap.impl.ValueCollectionFactory.emptyCollection)1 CountOperation (com.hazelcast.multimap.impl.operations.CountOperation)1 GetAllOperation (com.hazelcast.multimap.impl.operations.GetAllOperation)1 TransactionException (com.hazelcast.transaction.TransactionException)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1