Search in sources :

Example 16 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class QueueProxyImpl method toArray.

@Override
public <T> T[] toArray(T[] ts) {
    T[] tsParam = ts;
    final NodeEngine nodeEngine = getNodeEngine();
    List<Data> list = listInternal();
    int size = list.size();
    if (tsParam.length < size) {
        tsParam = (T[]) java.lang.reflect.Array.newInstance(tsParam.getClass().getComponentType(), size);
    }
    for (int i = 0; i < size; i++) {
        tsParam[i] = nodeEngine.toObject(list.get(i));
    }
    return tsParam;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Data(com.hazelcast.nio.serialization.Data)

Example 17 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class QueueProxyImpl method offer.

@Override
public boolean offer(E e, long timeout, TimeUnit timeUnit) throws InterruptedException {
    final NodeEngine nodeEngine = getNodeEngine();
    final Data data = nodeEngine.toData(e);
    return offerInternal(data, timeUnit.toMillis(timeout));
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Data(com.hazelcast.nio.serialization.Data)

Example 18 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class AbstractTransactionalCollectionProxy method remove.

public boolean remove(E e) {
    checkTransactionActive();
    checkObjectNotNull(e);
    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 {
        final OperationService operationService = nodeEngine.getOperationService();
        Future<CollectionItem> f = operationService.invokeOnPartition(getServiceName(), operation, partitionId);
        CollectionItem item = f.get();
        if (item != null) {
            if (reservedItemId == item.getItemId()) {
                iterator.remove();
                removeFromRecord(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());
            putToRecord(op);
            return true;
        }
    } catch (Throwable t) {
        throw ExceptionUtil.rethrow(t);
    }
    return false;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) CollectionReserveRemoveOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionReserveRemoveOperation) TransactionException(com.hazelcast.transaction.TransactionException) CollectionTxnRemoveOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionTxnRemoveOperation) Data(com.hazelcast.nio.serialization.Data) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem) OperationService(com.hazelcast.spi.OperationService)

Example 19 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class TransactionalSetProxy method add.

@Override
public boolean add(E e) {
    checkTransactionActive();
    checkObjectNotNull(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);
        Long itemId = f.get();
        if (itemId != null) {
            if (!itemIdSet.add(itemId)) {
                throw new TransactionException("Duplicate itemId: " + itemId);
            }
            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)

Example 20 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class QueueService method createLocalQueueStats.

/**
     * Returns the local queue statistics for the queue with the given {@code name}. If this node is the owner of the queue,
     * returned stats contain {@link LocalQueueStats#getOwnedItemCount()}, otherwise it contains
     * {@link LocalQueueStats#getBackupItemCount()}.
     *
     * @param name the name of the queue for which the statistics are returned
     * @return the statistics
     */
public LocalQueueStats createLocalQueueStats(String name) {
    SerializationService serializationService = nodeEngine.getSerializationService();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    Data keyData = serializationService.toData(name, StringPartitioningStrategy.INSTANCE);
    int partitionId = partitionService.getPartitionId(keyData);
    return createLocalQueueStats(name, partitionId);
}
Also used : IPartitionService(com.hazelcast.spi.partition.IPartitionService) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Aggregations

Data (com.hazelcast.nio.serialization.Data)773 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)140 Test (org.junit.Test)121 QuickTest (com.hazelcast.test.annotation.QuickTest)118 ParallelTest (com.hazelcast.test.annotation.ParallelTest)108 ArrayList (java.util.ArrayList)81 Map (java.util.Map)64 SerializationService (com.hazelcast.spi.serialization.SerializationService)54 HashMap (java.util.HashMap)54 NodeEngine (com.hazelcast.spi.NodeEngine)50 HashSet (java.util.HashSet)39 Address (com.hazelcast.nio.Address)28 AbstractMap (java.util.AbstractMap)28 Record (com.hazelcast.map.impl.record.Record)27 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 HeapData (com.hazelcast.internal.serialization.impl.HeapData)26 List (java.util.List)20 Future (java.util.concurrent.Future)20 CacheEventData (com.hazelcast.cache.impl.CacheEventData)19 Operation (com.hazelcast.spi.Operation)18