Search in sources :

Example 21 with MultiMapRecord

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

the class TransactionalMultiMapProxySupport method getInternal.

protected Collection<MultiMapRecord> getInternal(Data key) {
    checkObjectNotNull(key);
    Collection<MultiMapRecord> coll = txMap.get(key);
    if (coll == null) {
        GetAllOperation operation = new GetAllOperation(name, key);
        operation.setThreadId(ThreadUtil.getThreadId());
        try {
            int partitionId = getNodeEngine().getPartitionService().getPartitionId(key);
            final OperationService operationService = getNodeEngine().getOperationService();
            Future<MultiMapResponse> f = operationService.invokeOnPartition(MultiMapService.SERVICE_NAME, operation, partitionId);
            MultiMapResponse response = f.get();
            coll = response.getRecordCollection(getNodeEngine());
        } catch (Throwable t) {
            throw ExceptionUtil.rethrow(t);
        }
    }
    return coll;
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) GetAllOperation(com.hazelcast.multimap.impl.operations.GetAllOperation) MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse) OperationService(com.hazelcast.spi.OperationService)

Example 22 with MultiMapRecord

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

Example 23 with MultiMapRecord

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

the class RemoveBackupOperation method run.

@Override
public void run() throws Exception {
    MultiMapValue multiMapValue = getMultiMapValueOrNull();
    response = false;
    if (multiMapValue == null) {
        return;
    }
    Collection<MultiMapRecord> coll = multiMapValue.getCollection(false);
    Iterator<MultiMapRecord> iter = coll.iterator();
    while (iter.hasNext()) {
        if (iter.next().getRecordId() == recordId) {
            iter.remove();
            response = true;
            if (coll.isEmpty()) {
                delete();
            }
            break;
        }
    }
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) MultiMapValue(com.hazelcast.multimap.impl.MultiMapValue)

Example 24 with MultiMapRecord

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

the class RemoveOperation method run.

@Override
public void run() throws Exception {
    response = false;
    MultiMapValue multiMapValue = getMultiMapValueOrNull();
    if (multiMapValue == null) {
        return;
    }
    Collection<MultiMapRecord> coll = multiMapValue.getCollection(false);
    MultiMapRecord record = new MultiMapRecord(isBinary() ? value : toObject(value));
    Iterator<MultiMapRecord> iter = coll.iterator();
    while (iter.hasNext()) {
        MultiMapRecord r = iter.next();
        if (r.equals(record)) {
            iter.remove();
            recordId = r.getRecordId();
            response = true;
            if (coll.isEmpty()) {
                delete();
            }
            break;
        }
    }
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) MultiMapValue(com.hazelcast.multimap.impl.MultiMapValue)

Example 25 with MultiMapRecord

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

the class TransactionalMultiMapProxy method get.

@Override
public Collection<V> get(K key) {
    checkTransactionActive();
    Data dataKey = getNodeEngine().toData(key);
    Collection<MultiMapRecord> coll = getInternal(dataKey);
    Collection<V> collection = new ArrayList<V>(coll.size());
    for (MultiMapRecord record : coll) {
        collection.add((V) toObjectIfNeeded(record.getObject()));
    }
    return collection;
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) ArrayList(java.util.ArrayList) Data(com.hazelcast.nio.serialization.Data)

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