use of com.hazelcast.collection.impl.collection.CollectionItem in project hazelcast by hazelcast.
the class ListSetOperation method run.
@Override
public void run() throws Exception {
ListContainer listContainer = getOrCreateListContainer();
itemId = listContainer.nextId();
CollectionItem item = listContainer.set(index, itemId, value);
oldItemId = item.getItemId();
response = item.getValue();
}
use of com.hazelcast.collection.impl.collection.CollectionItem in project hazelcast by hazelcast.
the class ListKeyValueSource method open.
@Override
public boolean open(NodeEngine nodeEngine) {
NodeEngineImpl nei = (NodeEngineImpl) nodeEngine;
ss = nei.getSerializationService();
Address thisAddress = nei.getThisAddress();
IPartitionService ps = nei.getPartitionService();
Data data = ss.toData(listName, StringAndPartitionAwarePartitioningStrategy.INSTANCE);
int partitionId = ps.getPartitionId(data);
Address partitionOwner = ps.getPartitionOwner(partitionId);
if (partitionOwner == null) {
return false;
}
if (thisAddress.equals(partitionOwner)) {
ListService listService = nei.getService(ListService.SERVICE_NAME);
ListContainer listContainer = listService.getOrCreateContainer(listName, false);
List<CollectionItem> items = new ArrayList<CollectionItem>(listContainer.getCollection());
iterator = items.iterator();
}
return true;
}
use of com.hazelcast.collection.impl.collection.CollectionItem in project hazelcast by hazelcast.
the class SetEqualsHashTest method testCollectionItem_equalsAndHash.
@Test
public void testCollectionItem_equalsAndHash() {
SerializationServiceBuilder serializationServiceBuilder = new DefaultSerializationServiceBuilder();
SerializationService build = serializationServiceBuilder.build();
Data value = build.toData(randomString());
CollectionItem firstItem = new CollectionItem(1, value);
CollectionItem secondItem = new CollectionItem(2, value);
assertTrue(firstItem.equals(secondItem));
assertEquals(firstItem.hashCode(), secondItem.hashCode());
}
use of com.hazelcast.collection.impl.collection.CollectionItem in project hazelcast by hazelcast.
the class SetContainer method addAll.
@Override
public Map<Long, Data> addAll(List<Data> valueList) {
final int size = valueList.size();
final Map<Long, Data> map = new HashMap<Long, Data>(size);
List<CollectionItem> list = new ArrayList<CollectionItem>(size);
for (Data value : valueList) {
final long itemId = nextId();
final CollectionItem item = new CollectionItem(itemId, value);
if (!getCollection().contains(item)) {
list.add(item);
map.put(itemId, value);
}
}
getCollection().addAll(list);
return map;
}
use of com.hazelcast.collection.impl.collection.CollectionItem in project hazelcast by hazelcast.
the class AbstractTransactionalCollectionProxy method add.
public boolean add(E e) {
checkTransactionActive();
checkObjectNotNull(e);
final NodeEngine nodeEngine = getNodeEngine();
final Data value = nodeEngine.toData(e);
CollectionReserveAddOperation operation = new CollectionReserveAddOperation(name, tx.getTxnId(), null);
try {
Future<Long> f = nodeEngine.getOperationService().invokeOnPartition(getServiceName(), operation, partitionId);
Long itemId = f.get();
if (itemId != null) {
if (!itemIdSet.add(itemId)) {
throw new TransactionException("Duplicate itemId: " + itemId);
}
getCollection().add(new CollectionItem(itemId, value));
CollectionTxnAddOperation op = new CollectionTxnAddOperation(name, itemId, value);
putToRecord(op);
return true;
}
} catch (Throwable t) {
throw ExceptionUtil.rethrow(t);
}
return false;
}
Aggregations