Search in sources :

Example 1 with MultiMapRecord

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

the class MultiMapRemoveMessageTask method encodeResponse.

@Override
protected ClientMessage encodeResponse(Object response) {
    MultiMapResponse multiMapResponse = (MultiMapResponse) response;
    Collection<MultiMapRecord> collection = multiMapResponse.getCollection();
    List<Data> resultCollection = new ArrayList<Data>(collection.size());
    for (MultiMapRecord multiMapRecord : collection) {
        resultCollection.add(serializationService.toData(multiMapRecord.getObject()));
    }
    return MultiMapRemoveCodec.encodeResponse(resultCollection);
}
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 2 with MultiMapRecord

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

the class TransactionalMultiMapProxySupport method removeAllInternal.

protected Collection<MultiMapRecord> removeAllInternal(Data key) {
    checkObjectNotNull(key);
    long timeout = tx.getTimeoutMillis();
    long ttl = extendTimeout(timeout);
    Collection<MultiMapRecord> coll = txMap.get(key);
    final MultiMapTransactionLogRecord logRecord;
    if (coll == null) {
        MultiMapResponse response = lockAndGet(key, timeout, ttl);
        if (response == null) {
            throw new ConcurrentModificationException("Transaction couldn't obtain lock " + getThreadId());
        }
        coll = createCollection(response.getRecordCollection(getNodeEngine()));
        logRecord = new MultiMapTransactionLogRecord(getPartitionId(key), key, name, ttl, getThreadId());
        tx.add(logRecord);
    } else {
        logRecord = (MultiMapTransactionLogRecord) tx.get(getRecordLogKey(key));
    }
    txMap.put(key, createCollection());
    TxnRemoveAllOperation operation = new TxnRemoveAllOperation(name, key, coll);
    logRecord.addOperation(operation);
    return coll;
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) ConcurrentModificationException(java.util.ConcurrentModificationException) MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse)

Example 3 with MultiMapRecord

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

the class TransactionalMultiMapProxySupport method putInternal.

protected boolean putInternal(Data key, Data value) {
    checkObjectNotNull(key);
    checkObjectNotNull(value);
    Collection<MultiMapRecord> coll = txMap.get(key);
    long recordId = -1;
    long timeout = tx.getTimeoutMillis();
    long ttl = extendTimeout(timeout);
    final MultiMapTransactionLogRecord logRecord;
    if (coll == null) {
        MultiMapResponse response = lockAndGet(key, timeout, ttl);
        if (response == null) {
            throw new ConcurrentModificationException("Transaction couldn't obtain lock " + getThreadId());
        }
        recordId = response.getNextRecordId();
        coll = createCollection(response.getRecordCollection(getNodeEngine()));
        txMap.put(key, coll);
        logRecord = new MultiMapTransactionLogRecord(getPartitionId(key), key, name, ttl, getThreadId());
        tx.add(logRecord);
    } else {
        logRecord = (MultiMapTransactionLogRecord) tx.get(getRecordLogKey(key));
    }
    MultiMapRecord record = new MultiMapRecord(config.isBinary() ? value : toObjectIfNeeded(value));
    if (coll.add(record)) {
        if (recordId == -1) {
            recordId = nextId(key);
        }
        record.setRecordId(recordId);
        TxnPutOperation operation = new TxnPutOperation(name, key, value, recordId);
        logRecord.addOperation(operation);
        return true;
    }
    return false;
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) ConcurrentModificationException(java.util.ConcurrentModificationException) MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse)

Example 4 with MultiMapRecord

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

the class TransactionalMultiMapProxySupport method removeInternal.

protected boolean removeInternal(Data key, Data value) {
    checkObjectNotNull(key);
    checkObjectNotNull(value);
    Collection<MultiMapRecord> coll = txMap.get(key);
    long timeout = tx.getTimeoutMillis();
    long ttl = extendTimeout(timeout);
    final MultiMapTransactionLogRecord logRecord;
    if (coll == null) {
        MultiMapResponse response = lockAndGet(key, timeout, ttl);
        if (response == null) {
            throw new ConcurrentModificationException("Transaction couldn't obtain lock " + getThreadId());
        }
        coll = createCollection(response.getRecordCollection(getNodeEngine()));
        txMap.put(key, coll);
        logRecord = new MultiMapTransactionLogRecord(getPartitionId(key), key, name, ttl, getThreadId());
        tx.add(logRecord);
    } else {
        logRecord = (MultiMapTransactionLogRecord) tx.get(getRecordLogKey(key));
    }
    MultiMapRecord record = new MultiMapRecord(config.isBinary() ? value : toObjectIfNeeded(value));
    Iterator<MultiMapRecord> iterator = coll.iterator();
    long recordId = -1;
    while (iterator.hasNext()) {
        MultiMapRecord r = iterator.next();
        if (r.equals(record)) {
            iterator.remove();
            recordId = r.getRecordId();
            break;
        }
    }
    if (recordId != -1) {
        TxnRemoveOperation operation = new TxnRemoveOperation(name, key, recordId, value);
        logRecord.addOperation(operation);
        return recordId != -1;
    }
    return false;
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) ConcurrentModificationException(java.util.ConcurrentModificationException) MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse)

Example 5 with MultiMapRecord

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

the class TxnPutBackupOperation method run.

@Override
public void run() throws Exception {
    MultiMapContainer container = getOrCreateContainer();
    MultiMapValue multiMapValue = container.getOrCreateMultiMapValue(dataKey);
    response = true;
    if (multiMapValue.containsRecordId(recordId)) {
        response = false;
        return;
    }
    Collection<MultiMapRecord> coll = multiMapValue.getCollection(false);
    MultiMapRecord record = new MultiMapRecord(recordId, isBinary() ? value : toObject(value));
    coll.add(record);
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) MultiMapValue(com.hazelcast.multimap.impl.MultiMapValue) MultiMapContainer(com.hazelcast.multimap.impl.MultiMapContainer)

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