Search in sources :

Example 16 with MultiMapRecord

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

the class PutBackupOperation method run.

@Override
public void run() throws Exception {
    MultiMapRecord record = new MultiMapRecord(recordId, isBinary() ? value : toObject(value));
    Collection<MultiMapRecord> coll = getOrCreateMultiMapValue().getCollection(false);
    if (index == -1) {
        response = coll.add(record);
    } else {
        try {
            ((List<MultiMapRecord>) coll).add(index, record);
            response = true;
        } catch (IndexOutOfBoundsException e) {
            response = e;
        }
    }
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) List(java.util.List)

Example 17 with MultiMapRecord

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

the class PutOperation method run.

@Override
public void run() throws Exception {
    MultiMapContainer container = getOrCreateContainer();
    recordId = container.nextId();
    MultiMapRecord record = new MultiMapRecord(recordId, isBinary() ? value : toObject(value));
    Collection<MultiMapRecord> coll = container.getOrCreateMultiMapValue(dataKey).getCollection(false);
    if (index == -1) {
        response = coll.add(record);
    } else {
        try {
            ((List<MultiMapRecord>) coll).add(index, record);
            response = true;
        } catch (IndexOutOfBoundsException e) {
            response = e;
        }
    }
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) MultiMapContainer(com.hazelcast.multimap.impl.MultiMapContainer) List(java.util.List)

Example 18 with MultiMapRecord

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

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

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

the class TxnRemoveAllOperation method afterRun.

@Override
public void afterRun() throws Exception {
    long elapsed = Math.max(0, Clock.currentTimeMillis() - begin);
    final MultiMapService service = getService();
    service.getLocalMultiMapStatsImpl(name).incrementRemoves(elapsed);
    if (removed != null) {
        getOrCreateContainer().update();
        for (MultiMapRecord record : removed) {
            publishEvent(EntryEventType.REMOVED, dataKey, null, record.getObject());
        }
    }
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) MultiMapService(com.hazelcast.multimap.impl.MultiMapService)

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