if(log.isTraceEnabled()) { StringBuffer sb=new StringBuffer("received msgs="); sb.append(received_msgs.size()).append(", max_xmit_buf_size=").append(max_xmit_buf_size); log.trace(sb.toString()); }
    public Message remove() {        Message retval=null;        Long    key;        boolean bounded_buffer_enabled=max_xmit_buf_size > 0;        try {            lock.writeLock().acquire();            try {                while(received_msgs.size() > 0) {                    if(log.isTraceEnabled()) {                        StringBuffer sb=new StringBuffer("received msgs=");                        sb.append(received_msgs.size()).append(", max_xmit_buf_size=").append(max_xmit_buf_size);                        log.trace(sb.toString());                    }                    key=(Long)received_msgs.firstKey();                    retval=(Message)received_msgs.get(key);                    if(retval != null) { // message exists and is ready for delivery                        received_msgs.remove(key);       // move from received_msgs to ...                        if(discard_delivered_msgs == false) {                            delivered_msgs.put(key, retval); // delivered_msgs                        }                        head++;  // is removed from retransmitter somewhere else (when missing message is received)                        return retval;                    }                    else { // message has not yet been received (gap in the message sequence stream)                        if(bounded_buffer_enabled && received_msgs.size() > max_xmit_buf_size) {                            received_msgs.remove(key);       // move from received_msgs to ...                            head++;                            retransmitter.remove(key.longValue());                        }                        else {                            break;                        }                    }                }                return retval;            }            finally {                lock.writeLock().release();            }        }        catch(InterruptedException e) {            log.error("failed acquiring write lock", e);            return null;        }    }