Search in sources :

Example 6 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 7 with CollectionItem

use of com.hazelcast.collection.impl.collection.CollectionItem in project hazelcast by hazelcast.

the class SetKeyValueSource method open.

@Override
public boolean open(NodeEngine nodeEngine) {
    NodeEngineImpl nei = (NodeEngineImpl) nodeEngine;
    ss = nei.getSerializationService();
    Address thisAddress = nei.getThisAddress();
    InternalPartitionService ps = nei.getPartitionService();
    Data data = ss.toData(setName, StringAndPartitionAwarePartitioningStrategy.INSTANCE);
    int partitionId = ps.getPartitionId(data);
    Address partitionOwner = ps.getPartitionOwner(partitionId);
    if (partitionOwner == null) {
        return false;
    }
    if (thisAddress.equals(partitionOwner)) {
        SetService setService = nei.getService(SetService.SERVICE_NAME);
        SetContainer setContainer = setService.getOrCreateContainer(setName, false);
        List<CollectionItem> items = new ArrayList<CollectionItem>(setContainer.getCollection());
        iterator = items.iterator();
    }
    return true;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) SetContainer(com.hazelcast.collection.impl.set.SetContainer) Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) SetService(com.hazelcast.collection.impl.set.SetService) ArrayList(java.util.ArrayList) Data(com.hazelcast.nio.serialization.Data) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem)

Example 8 with CollectionItem

use of com.hazelcast.collection.impl.collection.CollectionItem in project hazelcast by hazelcast.

the class ListContainer method addTxItemOrdered.

private void addTxItemOrdered(CollectionItem item) {
    ListIterator<CollectionItem> iterator = getCollection().listIterator();
    while (iterator.hasNext()) {
        CollectionItem collectionItem = iterator.next();
        if (item.getItemId() < collectionItem.getItemId()) {
            iterator.previous();
            break;
        }
    }
    iterator.add(item);
}
Also used : CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem) TxCollectionItem(com.hazelcast.collection.impl.collection.TxCollectionItem)

Example 9 with CollectionItem

use of com.hazelcast.collection.impl.collection.CollectionItem in project hazelcast by hazelcast.

the class ListContainer method getMap.

@Override
protected Map<Long, CollectionItem> getMap() {
    if (itemMap == null) {
        if (itemList != null && !itemList.isEmpty()) {
            itemMap = new HashMap<Long, CollectionItem>(itemList.size());
            for (CollectionItem item : itemList) {
                itemMap.put(item.getItemId(), item);
            }
            itemList.clear();
        } else {
            itemMap = new HashMap<Long, CollectionItem>(INITIAL_CAPACITY);
        }
        itemList = null;
    }
    return itemMap;
}
Also used : CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem) TxCollectionItem(com.hazelcast.collection.impl.collection.TxCollectionItem)

Example 10 with CollectionItem

use of com.hazelcast.collection.impl.collection.CollectionItem in project hazelcast by hazelcast.

the class ListContainer method setBackup.

public void setBackup(long oldItemId, long itemId, Data value) {
    getMap().remove(oldItemId);
    getMap().put(itemId, new CollectionItem(itemId, value));
}
Also used : CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem) TxCollectionItem(com.hazelcast.collection.impl.collection.TxCollectionItem)

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