1 /** 2 * 3 */ 4 package org.mortbay.jetty.nio; 5 6 import org.mortbay.io.Buffer; 7 import org.mortbay.io.nio.NIOBuffer; 8 import org.mortbay.jetty.AbstractConnector; 9 10 /* ------------------------------------------------------------ */ 11 /** 12 * @author gregw 13 * 14 */ 15 public abstract class AbstractNIOConnector extends AbstractConnector implements NIOConnector 16 { 17 private boolean _useDirectBuffers=true; 18 19 /* ------------------------------------------------------------------------------- */ 20 public boolean getUseDirectBuffers() 21 { 22 return _useDirectBuffers; 23 } 24 25 /* ------------------------------------------------------------------------------- */ 26 /** 27 * @param direct If True (the default), the connector can use NIO direct buffers. 28 * Some JVMs have memory management issues (bugs) with direct buffers. 29 */ 30 public void setUseDirectBuffers(boolean direct) 31 { 32 _useDirectBuffers=direct; 33 } 34 35 /* ------------------------------------------------------------------------------- */ 36 protected Buffer newBuffer(int size) 37 { 38 // TODO 39 // Header buffers always byte array buffers (efficiency of random access) 40 // There are lots of things to consider here... DIRECT buffers are faster to 41 // send but more expensive to build and access! so we have choices to make... 42 // + headers are constructed bit by bit and parsed bit by bit, so INDiRECT looks 43 // good for them. 44 // + but will a gather write of an INDIRECT header with a DIRECT body be any good? 45 // this needs to be benchmarked. 46 // + Will it be possible to get a DIRECT header buffer just for the gather writes of 47 // content from file mapped buffers? 48 // + Are gather writes worth the effort? Maybe they will work well with two INDIRECT 49 // buffers being copied into a single kernel buffer? 50 // 51 Buffer buf = null; 52 if (size==getHeaderBufferSize()) 53 buf= new NIOBuffer(size, NIOBuffer.INDIRECT); 54 else 55 buf = new NIOBuffer(size, _useDirectBuffers?NIOBuffer.DIRECT:NIOBuffer.INDIRECT); 56 return buf; 57 } 58 59 60 }