Package com.hazelcast.collection

Examples of com.hazelcast.collection.CollectionItem


    public boolean add(E e) {
        checkTransactionState();
        throwExceptionIfNull(e);
        final NodeEngine nodeEngine = getNodeEngine();
        final Data value = nodeEngine.toData(e);
        if (!getCollection().add(new CollectionItem(-1, value))){
            return false;
        }
        CollectionReserveAddOperation operation = new CollectionReserveAddOperation(name, tx.getTxnId(), value);
        try {
            Future<Long> f = nodeEngine.getOperationService().invokeOnPartition(getServiceName(), operation, partitionId);
View Full Code Here


            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);
                tx.addTransactionLog(new CollectionTransactionLog(itemId, name, partitionId, getServiceName(), tx.getTxnId(), op));
                return true;
            }
        } catch (Throwable t) {
View Full Code Here

        final NodeEngine nodeEngine = getNodeEngine();
        final Data value = nodeEngine.toData(e);
        final Iterator<CollectionItem> iterator = getCollection().iterator();
        long reservedItemId = -1;
        while (iterator.hasNext()){
            final CollectionItem item = iterator.next();
            if (value.equals(item.getValue())){
                reservedItemId = item.getItemId();
                break;
            }
        }
        final CollectionReserveRemoveOperation operation = new CollectionReserveRemoveOperation(name, reservedItemId, value, tx.getTxnId());
        try {
            Future<CollectionItem> f = nodeEngine.getOperationService().invokeOnPartition(getServiceName(), operation, partitionId);
            CollectionItem item = f.get();
            if (item != null) {
                if (reservedItemId == item.getItemId()){
                    iterator.remove();
                    tx.removeTransactionLog(reservedItemId);
                    itemIdSet.remove(reservedItemId);
                    return true;
                }
                if (!itemIdSet.add(item.getItemId())) {
                    throw new TransactionException("Duplicate itemId: " + item.getItemId());
                }
                CollectionTxnRemoveOperation op = new CollectionTxnRemoveOperation(name, item.getItemId());
                tx.addTransactionLog(new CollectionTransactionLog(item.getItemId(), name, partitionId, getServiceName(), tx.getTxnId(), op));
                return true;
            }
        } catch (Throwable t) {
            throw ExceptionUtil.rethrow(t);
        }
View Full Code Here

        publishEvent(ItemEventType.ADDED, (Data)response);
    }

    @Override
    public void run() throws Exception {
        final CollectionItem item = getOrCreateListContainer().remove(index);
        itemId = item.getItemId();
        response = item.getValue();
    }
View Full Code Here

    public void beforeRun() throws Exception {
    }

    @Override
    public void run() throws Exception {
        final CollectionItem item = getOrCreateListContainer().get(index);
        response = item.getValue();
    }
View Full Code Here

    @Override
    public void run() throws Exception {
        final ListContainer container = getOrCreateListContainer();
        itemId = container.nextId();
        final CollectionItem item = container.set(index, itemId, value);
        oldItemId = item.getItemId();
        response = item.getValue();
    }
View Full Code Here

        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);
            }
        }
View Full Code Here

        }
        return config;
    }

    protected CollectionItem add(int index, Data value){
        final CollectionItem item = new CollectionItem(nextId(), value);
        if (index < 0){
            return getCollection().add(item) ? item : null;
        } else {
            getCollection().add(index, item);
            return item;
View Full Code Here

    protected CollectionItem get(int index){
        return getCollection().get(index);
    }

    protected CollectionItem set(int index, long itemId, Data value){
        return getCollection().set(index, new CollectionItem(itemId, value));
    }
View Full Code Here

        return getCollection().set(index, new CollectionItem(itemId, value));
    }

    protected void setBackup(long oldItemId, long itemId, Data value){
        getMap().remove(oldItemId);
        getMap().put(itemId, new CollectionItem(itemId, value));

    }
View Full Code Here

TOP

Related Classes of com.hazelcast.collection.CollectionItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.