/** * Removes and returns the packet ({@code T}) at the head of this queue, if * the queue is non-empty. If the queue is closed or empty, returns null * without blocking. * @return the packet at the head of this queue, or null if the queue is * empty. */ public T poll() { if (closed) return null; if (asyncQueueHandler != null) { // If the queue was configured with a handler, it is running its // own reading thread, and reading from it via this interface would // not provide consistent results. throw new IllegalStateException( "Trying to read from a queue with a configured handler."); } synchronized (queue) { T pkt = queue.poll(); if (pkt != null && queueStatistics != null) { queueStatistics.remove(System.currentTimeMillis()); } return pkt; } }
queueStatistics.remove(System.currentTimeMillis());
/** * Adds pkt to this socket. If the queue is full, drops a packet. Does * not block. */ public void addBuffer(Buffer buf) { synchronized (queue) { // Drop the first rather than the current packet, so that // receivers can notice the loss earlier. if (queue.size() == QUEUE_SIZE) { logger.info("Dropping a packet because the queue is full."); if (queueStatistics != null) { queueStatistics.remove(System.currentTimeMillis()); } queue.poll(); } queue.offer(buf); if (queueStatistics != null) { queueStatistics.add(System.currentTimeMillis()); } queue.notify(); } }
if (queueStatistics != null) queueStatistics.remove(System.currentTimeMillis());
queueStatistics.remove(System.currentTimeMillis());
if (writeQStats != null) writeQStats.remove(System.currentTimeMillis());
if (readQStats != null) readQStats.remove(System.currentTimeMillis());
if (writeQStats != null) writeQStats.remove(System.currentTimeMillis());
queueStats.remove(System.currentTimeMillis());
queueStats.remove(now);
if (readQStats != null) readQStats.remove(now);