private T next() { T ret = null; if (!flushBuffer) { ret = getInMemoryQueue().poll(); } else { if (thisIterator == null) { thisIterator = new SegmentQueueFileIterator(); } ret = thisIterator.next(); } if (ret == null) { close(); } return ret; }
@Override public boolean offer(T e) { if (isClosed || flushBuffer) return false; boolean added = getInMemoryQueue().add(e); if (added) { try { flush(e); } catch (IOException ex) { throw new RuntimeException(ex); } } return added; }
@Override public boolean offer(T e) { boolean startNewQueue = this.currentQueue == null || this.currentQueue.isFlushed(); if (startNewQueue) { currentIndex++; if (currentIndex < queues.size()) { currentQueue = queues.get(currentIndex); } else { currentQueue = createSegmentQueue(currentIndex, thresholdBytes); queues.add(currentQueue); } } return this.currentQueue.offer(e); }
private void flush(T entry) throws IOException { Queue<T> inMemQueue = getInMemoryQueue(); int resultSize = sizeOf(entry); maxResultSize = Math.max(maxResultSize, resultSize); totalResultSize = hasMaxQueueSize ? maxResultSize * inMemQueue.size() : (totalResultSize + resultSize); for (int i = 0; i < resSize; i++) { T e = inMemQueue.poll(); writeToBuffer(writeBuffer, e);
private void flush(T entry) throws IOException { Queue<T> inMemQueue = getInMemoryQueue(); int resultSize = sizeOf(entry); maxResultSize = Math.max(maxResultSize, resultSize); totalResultSize = hasMaxQueueSize ? maxResultSize * inMemQueue.size() : (totalResultSize + resultSize); for (int i = 0; i < resSize; i++) { T e = inMemQueue.poll(); writeToBuffer(writeBuffer, e);
this.currentIter = queueIter.hasNext() ? queueIter.next().iterator() : null;
this.currentIter = queueIter.hasNext() ? queueIter.next().iterator() : null;
@Override public void clear() { getInMemoryQueue().clear(); this.totalResultSize = 0; this.maxResultSize = 0; this.mappingSize = 0; this.flushBuffer = false; this.flushedCount = 0; this.current = null; if (thisIterator != null) { thisIterator.close(); thisIterator = null; } for (SegmentQueueFileIterator iter : iterators) { iter.close(); } iterators.clear(); if (this.file != null) { file.delete(); file = null; } }
@Override public void clear() { getInMemoryQueue().clear(); this.totalResultSize = 0; this.maxResultSize = 0; this.mappingSize = 0; this.flushBuffer = false; this.flushedCount = 0; this.current = null; if (thisIterator != null) { thisIterator.close(); thisIterator = null; } for (SegmentQueueFileIterator iter : iterators) { iter.close(); } iterators.clear(); if (this.file != null) { file.delete(); file = null; } }
private T next() { T ret = null; if (!flushBuffer) { ret = getInMemoryQueue().poll(); } else { if (thisIterator == null) { thisIterator = new SegmentQueueFileIterator(); } ret = thisIterator.next(); } if (ret == null) { close(); } return ret; }
public long getByteSize() { return currentQueue == null ? 0 : currentQueue.getInMemByteSize(); }
public long getByteSize() { return currentQueue == null ? 0 : currentQueue.getInMemByteSize(); }
private T next() { T ret = null; if (!flushBuffer) { ret = getInMemoryQueue().poll(); } else { if (thisIterator == null) { thisIterator = new SegmentQueueFileIterator(); } ret = thisIterator.next(); } if (ret == null) { close(); } return ret; }
@Override public boolean offer(T e) { if (isClosed || flushBuffer) return false; boolean added = getInMemoryQueue().add(e); if (added) { try { flush(e); } catch (IOException ex) { throw new RuntimeException(ex); } } return added; }
@Override public boolean offer(T e) { if (isClosed || flushBuffer) return false; boolean added = getInMemoryQueue().add(e); if (added) { try { flush(e); } catch (IOException ex) { throw new RuntimeException(ex); } } return added; }
@Override public boolean offer(T e) { boolean startNewQueue = this.currentQueue == null || this.currentQueue.isFlushed(); if (startNewQueue) { currentIndex++; if (currentIndex < queues.size()) { currentQueue = queues.get(currentIndex); } else { currentQueue = createSegmentQueue(currentIndex, thresholdBytes); queues.add(currentQueue); } } return this.currentQueue.offer(e); }
@Override public boolean offer(T e) { boolean startNewQueue = this.currentQueue == null || this.currentQueue.isFlushed(); if (startNewQueue) { currentIndex++; if (currentIndex < queues.size()) { currentQueue = queues.get(currentIndex); } else { currentQueue = createSegmentQueue(currentIndex, thresholdBytes); queues.add(currentQueue); } } return this.currentQueue.offer(e); }
@Override public Iterator<T> iterator() { if (isClosed) return null; if (!flushBuffer) return getInMemoryQueue().iterator(); SegmentQueueFileIterator iterator = new SegmentQueueFileIterator(thisIterator); iterators.add(iterator); return iterator; }
public void close() { for (MappedByteBufferSegmentQueue<T> queue : queues) { queue.close(); } queues.clear(); }