1 18 package org.apache.activemq.transport.udp; 19 20 import java.nio.ByteBuffer ; 21 22 28 public class SimpleBufferPool implements ByteBufferPool { 29 30 private int defaultSize; 31 private boolean useDirect; 32 33 public SimpleBufferPool() { 34 this(false); 35 } 36 37 public SimpleBufferPool(boolean useDirect) { 38 this.useDirect = useDirect; 39 } 40 41 public synchronized ByteBuffer borrowBuffer() { 42 return createBuffer(); 43 } 44 45 public void returnBuffer(ByteBuffer buffer) { 46 } 47 48 public void setDefaultSize(int defaultSize) { 49 this.defaultSize = defaultSize; 50 } 51 52 public boolean isUseDirect() { 53 return useDirect; 54 } 55 56 59 public void setUseDirect(boolean useDirect) { 60 this.useDirect = useDirect; 61 } 62 63 public void start() throws Exception { 64 } 65 66 public void stop() throws Exception { 67 } 68 69 protected ByteBuffer createBuffer() { 70 if (useDirect) { 71 return ByteBuffer.allocateDirect(defaultSize); 72 } 73 else { 74 return ByteBuffer.allocate(defaultSize); 75 } 76 } 77 78 } 79 | Popular Tags |