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