1 18 package org.apache.activemq.transport.udp; 19 20 import java.nio.ByteBuffer ; 21 import java.util.ArrayList ; 22 import java.util.List ; 23 24 30 public class DefaultBufferPool extends SimpleBufferPool implements ByteBufferPool { 31 32 private List buffers = new ArrayList (); 33 private Object lock = new Object (); 34 35 public DefaultBufferPool() { 36 super(true); 37 } 38 39 public DefaultBufferPool(boolean useDirect) { 40 super(useDirect); 41 } 42 43 public synchronized ByteBuffer borrowBuffer() { 44 synchronized (lock) { 45 int size = buffers.size(); 46 if (size > 0) { 47 return (ByteBuffer ) buffers.remove(size - 1); 48 } 49 } 50 return createBuffer(); 51 } 52 53 public void returnBuffer(ByteBuffer buffer) { 54 synchronized (lock) { 55 buffers.add(buffer); 56 } 57 } 58 59 public void start() throws Exception { 60 } 61 62 public void stop() throws Exception { 63 synchronized (lock) { 64 68 buffers.clear(); 69 } 70 } 71 72 } 73 | Popular Tags |