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;
}
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));
}
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;
}
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;
}
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);
}
Aggregations