Search in sources :

Example 6 with MultiMapValue

use of com.hazelcast.multimap.impl.MultiMapValue 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 7 with MultiMapValue

use of com.hazelcast.multimap.impl.MultiMapValue 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 8 with MultiMapValue

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

the class TxnRemoveAllBackupOperation method run.

@Override
public void run() throws Exception {
    MultiMapContainer container = getOrCreateContainer();
    MultiMapValue multiMapValue = container.getOrCreateMultiMapValue(dataKey);
    response = true;
    for (Long recordId : recordIds) {
        if (!multiMapValue.containsRecordId(recordId)) {
            response = false;
            return;
        }
    }
    Collection<MultiMapRecord> coll = multiMapValue.getCollection(false);
    for (Long recordId : recordIds) {
        Iterator<MultiMapRecord> iter = coll.iterator();
        while (iter.hasNext()) {
            MultiMapRecord record = iter.next();
            if (record.getRecordId() == recordId) {
                iter.remove();
                break;
            }
        }
    }
    if (coll.isEmpty()) {
        delete();
    }
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) MultiMapValue(com.hazelcast.multimap.impl.MultiMapValue) MultiMapContainer(com.hazelcast.multimap.impl.MultiMapContainer)

Example 9 with MultiMapValue

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

the class TxnRemoveAllOperation method run.

@Override
public void run() throws Exception {
    begin = Clock.currentTimeMillis();
    MultiMapContainer container = getOrCreateContainer();
    MultiMapValue multiMapValue = container.getOrCreateMultiMapValue(dataKey);
    response = true;
    for (Long recordId : recordIds) {
        if (!multiMapValue.containsRecordId(recordId)) {
            response = false;
            return;
        }
    }
    Collection<MultiMapRecord> coll = multiMapValue.getCollection(false);
    removed = new LinkedList<MultiMapRecord>();
    for (Long recordId : recordIds) {
        Iterator<MultiMapRecord> iter = coll.iterator();
        while (iter.hasNext()) {
            MultiMapRecord record = iter.next();
            if (record.getRecordId() == recordId) {
                iter.remove();
                removed.add(record);
                break;
            }
        }
    }
    if (coll.isEmpty()) {
        delete();
    }
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) MultiMapValue(com.hazelcast.multimap.impl.MultiMapValue) MultiMapContainer(com.hazelcast.multimap.impl.MultiMapContainer)

Example 10 with MultiMapValue

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

the class TxnLockAndGetOperation method run.

@Override
public void run() throws Exception {
    MultiMapContainer container = getOrCreateContainer();
    if (!container.txnLock(dataKey, getCallerUuid(), threadId, getCallId(), ttl, blockReads)) {
        throw new TransactionException("Transaction couldn't obtain lock!");
    }
    MultiMapValue multiMapValue = getMultiMapValueOrNull();
    boolean isLocal = executedLocally();
    Collection<MultiMapRecord> collection = multiMapValue == null ? null : multiMapValue.getCollection(isLocal);
    MultiMapResponse multiMapResponse = new MultiMapResponse(collection, getValueCollectionType(container));
    multiMapResponse.setNextRecordId(container.nextId());
    response = multiMapResponse;
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) TransactionException(com.hazelcast.transaction.TransactionException) MultiMapValue(com.hazelcast.multimap.impl.MultiMapValue) MultiMapContainer(com.hazelcast.multimap.impl.MultiMapContainer) MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse)

Aggregations

MultiMapValue (com.hazelcast.multimap.impl.MultiMapValue)14 MultiMapRecord (com.hazelcast.multimap.impl.MultiMapRecord)11 MultiMapContainer (com.hazelcast.multimap.impl.MultiMapContainer)9 Data (com.hazelcast.nio.serialization.Data)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MultiMapResponse (com.hazelcast.multimap.impl.operations.MultiMapResponse)1 TransactionException (com.hazelcast.transaction.TransactionException)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1