public SynchRef drainTo(Collection<SynchRecord<E>> collection, int maxElements, boolean unblock)
    {
        if (collection == null)
        {
            throw new IllegalArgumentException("The 'collection' parameter may not be null.");
        }

        if (collection == this)
        {
            throw new IllegalArgumentException("The 'collection' parameter may not be this object.");
        }

        // final Queue<E> items = this.buffer;
        ReentrantLock lock = this.lock;
        lock.lock();

        try
        {
            int n = 0;

            for (int max = ((maxElements >= count) || (maxElements < 0)) ? count : maxElements; n < max; n++)
            {
                // Extract the next record from the queue, don't signal the not full condition yet and release
                // producers depending on whether the caller wants to or not.
                collection.add(extract(false, unblock));
            }

            if (n > 0)
            {
                // count -= n;
                notFull.signalAll();
            }

            return new SynchRefImpl(n, collection);
        }
        finally
        {
            lock.unlock();
        }
    }
public SynchRef drainTo(Collection<SynchRecord<E>> collection, int maxElements, boolean unblock)
    {
        if (collection == null)
        {
            throw new IllegalArgumentException("The 'collection' parameter may not be null.");
        }

        if (collection == this)
        {
            throw new IllegalArgumentException("The 'collection' parameter may not be this object.");
        }

        
        ReentrantLock lock = this.lock;
        lock.lock();

        try
        {
            int n = 0;

            for (int max = ((maxElements >= count) || (maxElements < 0)) ? count : maxElements; n < max; n++)
            {
                
                
                collection.add(extract(false, unblock));
            }

            if (n > 0)
            {
                
                notFull.signalAll();
            }

            return new SynchRefImpl(n, collection);
        }
        finally
        {
            lock.unlock();
        }
    }
public SynchRef drainTo ( Collection < SynchRecord < E > > collection , int maxElements , boolean unblock ) { if ( collection == null ) { throw new IllegalArgumentException ( "The 'collection' parameter may not be null." ) ; } if ( collection == this ) { throw new IllegalArgumentException ( "The 'collection' parameter may not be this object." ) ; } // final Queue<E> items = this.buffer; ReentrantLock lock = this . lock ; lock . lock ( ) ; try { int n = 0 ; for ( int max = ( ( maxElements >= count ) || ( maxElements < 0 ) ) ? count : maxElements ; n < max ; n ++ ) { // Extract the next record from the queue, don't signal the not full condition yet and release // producers depending on whether the caller wants to or not. collection . add ( extract ( false , unblock ) ) ; } if ( n > 0 ) { // count -= n; notFull . signalAll ( ) ; } return new SynchRefImpl ( n , collection ) ; } finally { lock . unlock ( ) ; } }
Takes up to maxElements available data items from the queue or blocks until some become available. The returned
items are wrapped in a {@link SynchRecord} which provides an interface to requeue them or send errors to their
producers, where the producers are still blocked.

@param  collection  The collection to drain the data items into.
@param  maxElements The maximum number of elements to drain.
@param  unblock     If set to <tt>true</tt> the producers for the taken items will be immediately unblocked.

@return A count of the number of elements that were drained from the queue.

@throws IllegalArgumentException If collection is this queue or null.
Takes up to maxElements available data items from the queue or blocks until some become available . The returned items are wrapped in a { @link SynchRecord } which provides an interface to requeue them or send errors to their producers where the producers are still blocked .