* @see net.spy.memcached.MemcachedNode#fillWriteBuffer(boolean)
*/
public final void fillWriteBuffer(boolean shouldOptimize) {
if(toWrite == 0 && readQ.remainingCapacity() > 0) {
getWbuf().clear();
Operation o=getCurrentWriteOp();
while(o != null && toWrite < getWbuf().capacity()) {
assert o.getState() == OperationState.WRITING;
// This isn't the most optimal way to do this, but it hints
// at a larger design problem that may need to be taken care
// if in the bowels of the client.
// In practice, readQ should be small, however.
if(!readQ.contains(o)) {
readQ.add(o);
}
ByteBuffer obuf=o.getBuffer();
assert obuf != null : "Didn't get a write buffer from " + o;
int bytesToCopy=Math.min(getWbuf().remaining(),
obuf.remaining());
byte b[]=new byte[bytesToCopy];
obuf.get(b);
getWbuf().put(b);
getLogger().debug("After copying stuff from %s: %s",
o, getWbuf());
if(!o.getBuffer().hasRemaining()) {
o.writeComplete();
transitionWriteItem();
preparePending();
if(shouldOptimize) {
optimize();