/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public boolean offer(T item) throws IgniteException { try { Long idx = transformHeader(new AddProcessor(id, 1)); if (idx == null) return false; checkRemoved(idx); QueueItemKey key = itemKey(idx); cache.getAndPut(key, item); return true; } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** {@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 + ']'); } }
queue = new GridCacheQueueProxy(cctx, cctx.atomic() ? new GridAtomicCacheQueueImpl<>(name, hdr, cctx) : new GridTransactionalCacheQueueImpl<>(name, hdr, cctx));
/** {@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 + ']'); } }
queue = new GridCacheQueueProxy(cctx, cctx.atomic() ? new GridAtomicCacheQueueImpl<>(name, hdr, cctx) : new GridTransactionalCacheQueueImpl<>(name, hdr, cctx));
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public boolean addAll(Collection<? extends T> items) { A.notNull(items, "items"); try { Long idx = transformHeader(new AddProcessor(id, items.size())); if (idx == null) return false; checkRemoved(idx); Map<QueueItemKey, T> putMap = new HashMap<>(); for (T item : items) { putMap.put(itemKey(idx), item); idx++; } cache.putAll(putMap); return true; } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Nullable @Override public T poll() throws IgniteException { try { while (true) { Long idx = transformHeader(new PollProcessor(id)); if (idx == null) return null; checkRemoved(idx); QueueItemKey key = itemKey(idx); T data = (T)cache.getAndRemove(key); if (data != null) return data; long stop = U.currentTimeMillis() + RETRY_TIMEOUT; while (U.currentTimeMillis() < stop) { data = (T)cache.getAndRemove(key); if (data != null) return data; } U.warn(log, "Failed to get item due to poll timeout [queue=" + queueName + ", idx=" + idx + "]. " + "Poll timeout can be redefined by 'IGNITE_ATOMIC_CACHE_QUEUE_RETRY_TIMEOUT' system property."); } } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public boolean offer(T item) throws IgniteException { try { Long idx = transformHeader(new AddProcessor(id, 1)); if (idx == null) return false; checkRemoved(idx); QueueItemKey key = itemKey(idx); cache.getAndPut(key, item); return true; } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public boolean addAll(Collection<? extends T> items) { A.notNull(items, "items"); try { Long idx = transformHeader(new AddProcessor(id, items.size())); if (idx == null) return false; checkRemoved(idx); Map<QueueItemKey, T> putMap = new HashMap<>(); for (T item : items) { putMap.put(itemKey(idx), item); idx++; } cache.putAll(putMap); return true; } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Nullable @Override public T poll() throws IgniteException { try { while (true) { Long idx = transformHeader(new PollProcessor(id)); if (idx == null) return null; checkRemoved(idx); QueueItemKey key = itemKey(idx); T data = (T)cache.getAndRemove(key); if (data != null) return data; long stop = U.currentTimeMillis() + RETRY_TIMEOUT; while (U.currentTimeMillis() < stop) { data = (T)cache.getAndRemove(key); if (data != null) return data; } U.warn(log, "Failed to get item due to poll timeout [queue=" + queueName + ", idx=" + idx + "]. " + "Poll timeout can be redefined by 'IGNITE_ATOMIC_CACHE_QUEUE_RETRY_TIMEOUT' system property."); } } catch (IgniteCheckedException e) { throw U.convertException(e); } }