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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations