/** * @param c EntryProcessor to be applied for queue header. * @return Value computed by the entry processor. * @throws IgniteCheckedException If failed. */ @SuppressWarnings("unchecked") @Nullable private Long transformHeader(EntryProcessor<GridCacheQueueHeaderKey, GridCacheQueueHeader, Long> c) throws IgniteCheckedException { return (Long)cache.invoke(queueKey, c).get(); } }
@Override public Boolean call() throws Exception { boolean retVal; try (GridNearTxLocal tx = cache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { Long idx = (Long)cache.invoke(queueKey, new AddProcessor(id, items.size())).get(); if (idx != null) { checkRemoved(idx); Map<QueueItemKey, T> putMap = new HashMap<>(); for (T item : items) { putMap.put(itemKey(idx), item); idx++; } cache.putAll(putMap); retVal = true; } else retVal = false; tx.commit(); return retVal; } } });
@Override public Object call() throws Exception { try (GridNearTxLocal tx = cache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { Long idx = (Long)cache.invoke(queueKey, new RemoveProcessor(id, rmvIdx)).get(); if (idx != null) { checkRemoved(idx); cache.remove(itemKey(idx)); } tx.commit(); } return null; } });
@Override public Boolean call() throws Exception { boolean retVal; try (GridNearTxLocal tx = cache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { Long idx = (Long)cache.invoke(queueKey, new AddProcessor(id, 1)).get(); if (idx != null) { checkRemoved(idx); cache.getAndPut(itemKey(idx), item); retVal = true; } else retVal = false; tx.commit(); return retVal; } } });
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected void removeItem(long rmvIdx) throws IgniteCheckedException { Long idx = (Long)cache.invoke(queueKey, new RemoveProcessor(id, rmvIdx)).get(); if (idx != null) { checkRemoved(idx); QueueItemKey key = itemKey(idx); if (cache.remove(key)) return; long stop = U.currentTimeMillis() + RETRY_TIMEOUT; while (U.currentTimeMillis() < stop) { if (cache.remove(key)) return; } U.warn(log, "Failed to remove item, [queue=" + queueName + ", idx=" + idx + ']'); } }
@Override public T call() throws Exception { T retVal; while (true) { try (GridNearTxLocal tx = cache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { Long idx = (Long)cache.invoke(queueKey, new PollProcessor(id)).get(); if (idx != null) { checkRemoved(idx); retVal = (T)cache.getAndRemove(itemKey(idx)); if (retVal == null) { // Possible if data was lost. tx.commit(); continue; } } else retVal = null; tx.commit(); return retVal; } } } });
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public void clear(int batchSize) throws IgniteException { A.ensure(batchSize >= 0, "Batch size cannot be negative: " + batchSize); try { Object obj = cache.invoke(queueKey, new ClearProcessor(id)).get(); if (obj == null) return; IgniteBiTuple<Long, Long> t = obj instanceof BinaryObject ? ((BinaryObject)obj).deserialize() : (IgniteBiTuple<Long, Long>)obj; checkRemoved(t.get1()); removeKeys(cache, id, queueName, collocated, t.get1(), t.get2(), batchSize); } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** * @param c EntryProcessor to be applied for queue header. * @return Value computed by the entry processor. * @throws IgniteCheckedException If failed. */ @SuppressWarnings("unchecked") @Nullable private Long transformHeader(EntryProcessor<GridCacheQueueHeaderKey, GridCacheQueueHeader, Long> c) throws IgniteCheckedException { return (Long)cache.invoke(queueKey, c).get(); } }
@Override public Boolean call() throws Exception { boolean retVal; try (GridNearTxLocal tx = cache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { Long idx = (Long)cache.invoke(queueKey, new AddProcessor(id, items.size())).get(); if (idx != null) { checkRemoved(idx); Map<QueueItemKey, T> putMap = new HashMap<>(); for (T item : items) { putMap.put(itemKey(idx), item); idx++; } cache.putAll(putMap); retVal = true; } else retVal = false; tx.commit(); return retVal; } } });
@Override public Object call() throws Exception { try (GridNearTxLocal tx = cache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { Long idx = (Long)cache.invoke(queueKey, new RemoveProcessor(id, rmvIdx)).get(); if (idx != null) { checkRemoved(idx); cache.remove(itemKey(idx)); } tx.commit(); } return null; } });
@Override public Boolean call() throws Exception { boolean retVal; try (GridNearTxLocal tx = cache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { Long idx = (Long)cache.invoke(queueKey, new AddProcessor(id, 1)).get(); if (idx != null) { checkRemoved(idx); cache.getAndPut(itemKey(idx), item); retVal = true; } else retVal = false; tx.commit(); return retVal; } } });
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected void removeItem(long rmvIdx) throws IgniteCheckedException { Long idx = (Long)cache.invoke(queueKey, new RemoveProcessor(id, rmvIdx)).get(); if (idx != null) { checkRemoved(idx); QueueItemKey key = itemKey(idx); if (cache.remove(key)) return; long stop = U.currentTimeMillis() + RETRY_TIMEOUT; while (U.currentTimeMillis() < stop) { if (cache.remove(key)) return; } U.warn(log, "Failed to remove item, [queue=" + queueName + ", idx=" + idx + ']'); } }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public void clear(int batchSize) throws IgniteException { A.ensure(batchSize >= 0, "Batch size cannot be negative: " + batchSize); try { IgniteBiTuple<Long, Long> t = (IgniteBiTuple<Long, Long>)cache.invoke(queueKey, new ClearProcessor(id)).get(); if (t == null) return; checkRemoved(t.get1()); removeKeys(cache, id, queueName, collocated, t.get1(), t.get2(), batchSize); } catch (IgniteCheckedException e) { throw U.convertException(e); } }
@Override public T call() throws Exception { T retVal; while (true) { try (GridNearTxLocal tx = cache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { Long idx = (Long)cache.invoke(queueKey, new PollProcessor(id)).get(); if (idx != null) { checkRemoved(idx); retVal = (T)cache.getAndRemove(itemKey(idx)); if (retVal == null) { // Possible if data was lost. tx.commit(); continue; } } else retVal = null; tx.commit(); return retVal; } } } });