use of com.hazelcast.multimap.impl.MultiMapValue in project hazelcast by hazelcast.
the class MultiMapMigrationOperation method writeInternal.
@Override
protected void writeInternal(ObjectDataOutput out) throws IOException {
out.writeInt(map.size());
for (Map.Entry<String, Map> entry : map.entrySet()) {
String name = entry.getKey();
out.writeUTF(name);
Map<Data, MultiMapValue> collections = entry.getValue();
out.writeInt(collections.size());
for (Map.Entry<Data, MultiMapValue> collectionEntry : collections.entrySet()) {
Data key = collectionEntry.getKey();
out.writeData(key);
MultiMapValue multiMapValue = collectionEntry.getValue();
Collection<MultiMapRecord> coll = multiMapValue.getCollection(false);
out.writeInt(coll.size());
String collectionType = MultiMapConfig.ValueCollectionType.SET.name();
if (coll instanceof List) {
collectionType = MultiMapConfig.ValueCollectionType.LIST.name();
}
out.writeUTF(collectionType);
for (MultiMapRecord record : coll) {
record.writeData(out);
}
}
}
}
use of com.hazelcast.multimap.impl.MultiMapValue in project hazelcast by hazelcast.
the class MultiMapMigrationOperation method readInternal.
@Override
protected void readInternal(ObjectDataInput in) throws IOException {
int mapSize = in.readInt();
map = new HashMap<String, Map>(mapSize);
for (int i = 0; i < mapSize; i++) {
String name = in.readUTF();
int collectionSize = in.readInt();
Map<Data, MultiMapValue> collections = new HashMap<Data, MultiMapValue>();
for (int j = 0; j < collectionSize; j++) {
Data key = in.readData();
int collSize = in.readInt();
String collectionType = in.readUTF();
Collection<MultiMapRecord> coll;
if (collectionType.equals(MultiMapConfig.ValueCollectionType.SET.name())) {
coll = new HashSet<MultiMapRecord>();
} else {
coll = new LinkedList<MultiMapRecord>();
}
for (int k = 0; k < collSize; k++) {
MultiMapRecord record = new MultiMapRecord();
record.readData(in);
coll.add(record);
}
collections.put(key, new MultiMapValue(coll));
}
map.put(name, collections);
}
}
use of com.hazelcast.multimap.impl.MultiMapValue 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();
}
}
use of com.hazelcast.multimap.impl.MultiMapValue 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();
}
}
use of com.hazelcast.multimap.impl.MultiMapValue 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;
}
Aggregations