public void offer(FetchRequest e) {
        final Lock lock = this.lock;
        lock.lock();
        try {
            /**
             * A request is not referenced by this queue,so we don't want to add
             * it.
             */
            if (e.getRefQueue() != null && e.getRefQueue() != this) {
                return;
            }
            // Reference to request.
            e.setRefQueue(this);
            this.queue.offer(e);
            Collections.sort(this.queue);
            // Leader is changed.
            if (this.queue.peek() == e) {
                this.leader = null;
                this.available.signal();
            }
        }
        finally {
            lock.unlock();
        }
    }
Thread designated to wait for the element at the head of the queue. This
variant of the Leader-Follower pattern
(http://www.cs.wustl.edu/~schmidt/POSA/POSA2/) serves to minimize
unnecessary timed waiting. When a thread becomes the leader, it waits
only for the next delay to elapse, but other threads await indefinitely.
The leader thread must signal some other thread before returning from
take() or poll(...), unless some other thread becomes leader in the
interim. Whenever the head of the queue is replaced with an element with
an earlier expiration time, the leader field is invalidated by being
reset to null, and some waiting thread, but not necessarily the current
leader, is signalled. So waiting threads must be prepared to acquire and
lose leadership while waiting.
metamorphosis-client/src/main/java/com/taobao/metamorphosis/client/consumer/FetchRequestQueue.java