Search in sources :

Example 16 with CollectionItem

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();
}
Also used : ListContainer(com.hazelcast.collection.impl.list.ListContainer) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem)

Example 17 with CollectionItem

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;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ListService(com.hazelcast.collection.impl.list.ListService) Address(com.hazelcast.nio.Address) IPartitionService(com.hazelcast.spi.partition.IPartitionService) ArrayList(java.util.ArrayList) Data(com.hazelcast.nio.serialization.Data) ListContainer(com.hazelcast.collection.impl.list.ListContainer) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem)

Example 18 with CollectionItem

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());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationServiceBuilder(com.hazelcast.internal.serialization.SerializationServiceBuilder) DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with CollectionItem

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Data(com.hazelcast.nio.serialization.Data) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem)

Example 20 with CollectionItem

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;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) TransactionException(com.hazelcast.transaction.TransactionException) CollectionTxnAddOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionTxnAddOperation) CollectionReserveAddOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionReserveAddOperation) Data(com.hazelcast.nio.serialization.Data) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem)

Aggregations

CollectionItem (com.hazelcast.collection.impl.collection.CollectionItem)20 Data (com.hazelcast.nio.serialization.Data)9 TxCollectionItem (com.hazelcast.collection.impl.collection.TxCollectionItem)7 ListContainer (com.hazelcast.collection.impl.list.ListContainer)5 ArrayList (java.util.ArrayList)5 NodeEngine (com.hazelcast.spi.NodeEngine)3 TransactionException (com.hazelcast.transaction.TransactionException)3 CollectionReserveAddOperation (com.hazelcast.collection.impl.txncollection.operations.CollectionReserveAddOperation)2 CollectionTxnAddOperation (com.hazelcast.collection.impl.txncollection.operations.CollectionTxnAddOperation)2 Address (com.hazelcast.nio.Address)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 HashMap (java.util.HashMap)2 CollectionContainer (com.hazelcast.collection.impl.collection.CollectionContainer)1 ListService (com.hazelcast.collection.impl.list.ListService)1 SetContainer (com.hazelcast.collection.impl.set.SetContainer)1 SetService (com.hazelcast.collection.impl.set.SetService)1 CollectionReserveRemoveOperation (com.hazelcast.collection.impl.txncollection.operations.CollectionReserveRemoveOperation)1 CollectionTxnRemoveOperation (com.hazelcast.collection.impl.txncollection.operations.CollectionTxnRemoveOperation)1 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)1 SerializationServiceBuilder (com.hazelcast.internal.serialization.SerializationServiceBuilder)1