Search in sources :

Example 1 with MultiMapResponse

use of com.hazelcast.multimap.impl.operations.MultiMapResponse in project hazelcast by hazelcast.

the class MultiMapKeySetMessageTask method reduce.

@Override
protected Object reduce(Map<Integer, Object> map) {
    List<Data> keys = new ArrayList<Data>();
    for (Object obj : map.values()) {
        if (obj == null) {
            continue;
        }
        MultiMapResponse response = (MultiMapResponse) obj;
        Collection<Data> coll = response.getCollection();
        if (coll != null) {
            keys.addAll(coll);
        }
    }
    return keys;
}
Also used : MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse) ArrayList(java.util.ArrayList) Data(com.hazelcast.nio.serialization.Data)

Example 2 with MultiMapResponse

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

use of com.hazelcast.multimap.impl.operations.MultiMapResponse in project hazelcast by hazelcast.

the class MultiMapDataSerializerHook method createFactory.

public DataSerializableFactory createFactory() {
    ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[ENTRY_SET_RESPONSE + 1];
    constructors[CLEAR_BACKUP] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new ClearBackupOperation();
        }
    };
    constructors[CLEAR] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new ClearOperation();
        }
    };
    constructors[CONTAINS_ENTRY] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new ContainsEntryOperation();
        }
    };
    constructors[COUNT] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new CountOperation();
        }
    };
    constructors[ENTRY_SET] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new EntrySetOperation();
        }
    };
    constructors[GET_ALL] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new GetAllOperation();
        }
    };
    constructors[KEY_SET] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new KeySetOperation();
        }
    };
    constructors[PUT_BACKUP] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new PutBackupOperation();
        }
    };
    constructors[PUT] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new PutOperation();
        }
    };
    constructors[REMOVE_ALL_BACKUP] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new RemoveAllBackupOperation();
        }
    };
    constructors[REMOVE_ALL] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new RemoveAllOperation();
        }
    };
    constructors[REMOVE_BACKUP] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new RemoveBackupOperation();
        }
    };
    constructors[REMOVE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new RemoveOperation();
        }
    };
    constructors[SIZE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new SizeOperation();
        }
    };
    constructors[VALUES] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new ValuesOperation();
        }
    };
    constructors[TXN_COMMIT_BACKUP] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnCommitBackupOperation();
        }
    };
    constructors[TXN_COMMIT] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnCommitOperation();
        }
    };
    constructors[TXN_GENERATE_RECORD_ID] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnGenerateRecordIdOperation();
        }
    };
    constructors[TXN_LOCK_AND_GET] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnLockAndGetOperation();
        }
    };
    constructors[TXN_PREPARE_BACKUP] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnPrepareBackupOperation();
        }
    };
    constructors[TXN_PREPARE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnPrepareOperation();
        }
    };
    constructors[TXN_PUT] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnPutOperation();
        }
    };
    constructors[TXN_PUT_BACKUP] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnPutBackupOperation();
        }
    };
    constructors[TXN_REMOVE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnRemoveOperation();
        }
    };
    constructors[TXN_REMOVE_BACKUP] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnRemoveBackupOperation();
        }
    };
    constructors[TXN_REMOVE_ALL] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnRemoveAllOperation();
        }
    };
    constructors[TXN_REMOVE_ALL_BACKUP] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnRemoveAllBackupOperation();
        }
    };
    constructors[TXN_ROLLBACK_BACKUP] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnRollbackBackupOperation();
        }
    };
    constructors[TXN_ROLLBACK] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new TxnRollbackOperation();
        }
    };
    constructors[MULTIMAP_OP_FACTORY] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new MultiMapOperationFactory();
        }
    };
    constructors[MULTIMAP_TRANSACTION_LOG_RECORD] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new MultiMapTransactionLogRecord();
        }
    };
    constructors[MULTIMAP_EVENT_FILTER] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new MultiMapEventFilter();
        }
    };
    constructors[MULTIMAP_RECORD] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new MultiMapRecord();
        }
    };
    constructors[MULTIMAP_MIGRATION_OPERATION] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new MultiMapMigrationOperation();
        }
    };
    constructors[MULTIMAP_RESPONSE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new MultiMapResponse();
        }
    };
    constructors[ENTRY_SET_RESPONSE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new EntrySetResponse();
        }
    };
    return new ArrayDataSerializableFactory(constructors);
}
Also used : TxnRemoveAllOperation(com.hazelcast.multimap.impl.txn.TxnRemoveAllOperation) RemoveAllOperation(com.hazelcast.multimap.impl.operations.RemoveAllOperation) GetAllOperation(com.hazelcast.multimap.impl.operations.GetAllOperation) TxnRemoveBackupOperation(com.hazelcast.multimap.impl.txn.TxnRemoveBackupOperation) TxnPrepareBackupOperation(com.hazelcast.multimap.impl.txn.TxnPrepareBackupOperation) EntrySetResponse(com.hazelcast.multimap.impl.operations.EntrySetResponse) ClearBackupOperation(com.hazelcast.multimap.impl.operations.ClearBackupOperation) MultiMapMigrationOperation(com.hazelcast.multimap.impl.operations.MultiMapMigrationOperation) TxnCommitOperation(com.hazelcast.multimap.impl.txn.TxnCommitOperation) MultiMapOperationFactory(com.hazelcast.multimap.impl.operations.MultiMapOperationFactory) TxnRemoveAllOperation(com.hazelcast.multimap.impl.txn.TxnRemoveAllOperation) TxnPrepareOperation(com.hazelcast.multimap.impl.txn.TxnPrepareOperation) KeySetOperation(com.hazelcast.multimap.impl.operations.KeySetOperation) PutBackupOperation(com.hazelcast.multimap.impl.operations.PutBackupOperation) TxnPutBackupOperation(com.hazelcast.multimap.impl.txn.TxnPutBackupOperation) ContainsEntryOperation(com.hazelcast.multimap.impl.operations.ContainsEntryOperation) CountOperation(com.hazelcast.multimap.impl.operations.CountOperation) SizeOperation(com.hazelcast.multimap.impl.operations.SizeOperation) TxnPutOperation(com.hazelcast.multimap.impl.txn.TxnPutOperation) MultiMapTransactionLogRecord(com.hazelcast.multimap.impl.txn.MultiMapTransactionLogRecord) IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) TxnRollbackOperation(com.hazelcast.multimap.impl.txn.TxnRollbackOperation) PutOperation(com.hazelcast.multimap.impl.operations.PutOperation) TxnPutOperation(com.hazelcast.multimap.impl.txn.TxnPutOperation) TxnRemoveAllBackupOperation(com.hazelcast.multimap.impl.txn.TxnRemoveAllBackupOperation) TxnRemoveOperation(com.hazelcast.multimap.impl.txn.TxnRemoveOperation) RemoveOperation(com.hazelcast.multimap.impl.operations.RemoveOperation) ClearOperation(com.hazelcast.multimap.impl.operations.ClearOperation) EntrySetOperation(com.hazelcast.multimap.impl.operations.EntrySetOperation) TxnRemoveOperation(com.hazelcast.multimap.impl.txn.TxnRemoveOperation) ConstructorFunction(com.hazelcast.util.ConstructorFunction) TxnPutBackupOperation(com.hazelcast.multimap.impl.txn.TxnPutBackupOperation) TxnCommitBackupOperation(com.hazelcast.multimap.impl.txn.TxnCommitBackupOperation) TxnLockAndGetOperation(com.hazelcast.multimap.impl.txn.TxnLockAndGetOperation) TxnRemoveAllBackupOperation(com.hazelcast.multimap.impl.txn.TxnRemoveAllBackupOperation) RemoveAllBackupOperation(com.hazelcast.multimap.impl.operations.RemoveAllBackupOperation) TxnGenerateRecordIdOperation(com.hazelcast.multimap.impl.txn.TxnGenerateRecordIdOperation) MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse) TxnRollbackBackupOperation(com.hazelcast.multimap.impl.txn.TxnRollbackBackupOperation) RemoveBackupOperation(com.hazelcast.multimap.impl.operations.RemoveBackupOperation) TxnRemoveBackupOperation(com.hazelcast.multimap.impl.txn.TxnRemoveBackupOperation) ArrayDataSerializableFactory(com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory) ValuesOperation(com.hazelcast.multimap.impl.operations.ValuesOperation)

Example 4 with MultiMapResponse

use of com.hazelcast.multimap.impl.operations.MultiMapResponse in project hazelcast by hazelcast.

the class MultiMapProxySupport method keySetInternal.

protected Set<Data> keySetInternal() {
    final NodeEngine nodeEngine = getNodeEngine();
    try {
        Map<Integer, Object> results = nodeEngine.getOperationService().invokeOnAllPartitions(MultiMapService.SERVICE_NAME, new MultiMapOperationFactory(name, OperationFactoryType.KEY_SET));
        Set<Data> keySet = new HashSet<Data>();
        for (Object result : results.values()) {
            if (result == null) {
                continue;
            }
            MultiMapResponse response = nodeEngine.toObject(result);
            if (response.getCollection() != null) {
                keySet.addAll(response.getCollection());
            }
        }
        return keySet;
    } catch (Throwable throwable) {
        throw ExceptionUtil.rethrow(throwable);
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) MultiMapOperationFactory(com.hazelcast.multimap.impl.operations.MultiMapOperationFactory) MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) Data(com.hazelcast.nio.serialization.Data) HashSet(java.util.HashSet)

Example 5 with MultiMapResponse

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

Aggregations

MultiMapResponse (com.hazelcast.multimap.impl.operations.MultiMapResponse)14 MultiMapRecord (com.hazelcast.multimap.impl.MultiMapRecord)8 Data (com.hazelcast.nio.serialization.Data)6 NodeEngine (com.hazelcast.spi.NodeEngine)4 ArrayList (java.util.ArrayList)4 ConcurrentModificationException (java.util.ConcurrentModificationException)3 GetAllOperation (com.hazelcast.multimap.impl.operations.GetAllOperation)2 MultiMapOperationFactory (com.hazelcast.multimap.impl.operations.MultiMapOperationFactory)2 MultiMap (com.hazelcast.core.MultiMap)1 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1 MultiMapContainer (com.hazelcast.multimap.impl.MultiMapContainer)1 MultiMapValue (com.hazelcast.multimap.impl.MultiMapValue)1 ClearBackupOperation (com.hazelcast.multimap.impl.operations.ClearBackupOperation)1 ClearOperation (com.hazelcast.multimap.impl.operations.ClearOperation)1 ContainsEntryOperation (com.hazelcast.multimap.impl.operations.ContainsEntryOperation)1 CountOperation (com.hazelcast.multimap.impl.operations.CountOperation)1 EntrySetOperation (com.hazelcast.multimap.impl.operations.EntrySetOperation)1 EntrySetResponse (com.hazelcast.multimap.impl.operations.EntrySetResponse)1 KeySetOperation (com.hazelcast.multimap.impl.operations.KeySetOperation)1 MultiMapMigrationOperation (com.hazelcast.multimap.impl.operations.MultiMapMigrationOperation)1