public final void fillWriteBuffer(boolean shouldOptimize) {
    if (toWrite == 0 && readQ.remainingCapacity() > 0) {
      getWbuf().clear();
      Operation o=getNextWritableOp();

      while(o != null && toWrite < getWbuf().capacity()) {
        synchronized(o) {
          assert o.getState() == OperationState.WRITING;

          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();
            }

            o=getNextWritableOp();
          }
          toWrite += bytesToCopy;
        }
      }
      getWbuf().flip();
      assert toWrite <= getWbuf().capacity() : "toWrite exceeded capacity: "
          + this;
      assert toWrite == getWbuf().remaining() : "Expected " + toWrite
          + " remaining, got " + getWbuf().remaining();
    } else {
      getLogger().debug("Buffer is full, skipping");
    }
  }
public final void fillWriteBuffer ( boolean shouldOptimize ) { if ( toWrite == 0 && readQ . remainingCapacity ( ) > 0 ) { getWbuf ( ) . clear ( ) ; Operation o = getNextWritableOp ( ) ; while ( o != null && toWrite < getWbuf ( ) . capacity ( ) ) { synchronized ( o ) { assert o . getState ( ) == OperationState . WRITING ; 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 ( ) ; } o = getNextWritableOp ( ) ; } toWrite += bytesToCopy ; } } getWbuf ( ) . flip ( ) ; assert toWrite <= getWbuf ( ) . capacity ( ) : "toWrite exceeded capacity: " + this ; assert toWrite == getWbuf ( ) . remaining ( ) : "Expected " + toWrite + " remaining, got " + getWbuf ( ) . remaining ( ) ; } else { getLogger ( ) . debug ( "Buffer is full, skipping" ) ; } }
/*
(non-Javadoc)

@see net.spy.memcached.MemcachedNode#fillWriteBuffer(boolean)