1 14 15 package org.quickserver.util.pool; 16 17 import java.nio.ByteBuffer ; 18 import org.apache.commons.pool.BasePoolableObjectFactory; 19 20 25 public class ByteBufferObjectFactory extends BasePoolableObjectFactory { 26 int bufferSize = -1; 27 boolean useDirectByteBuffer = true; 28 29 public ByteBufferObjectFactory(int bufferSize, boolean useDirectByteBuffer) { 30 this.bufferSize = bufferSize; 31 this.useDirectByteBuffer = useDirectByteBuffer; 32 } 33 34 public Object makeObject() { 36 if(useDirectByteBuffer) 37 return ByteBuffer.allocateDirect(bufferSize); 38 else 39 return ByteBuffer.allocate(bufferSize); 40 } 41 42 public void passivateObject(Object obj) { 44 ByteBuffer ch = (ByteBuffer )obj; 45 ch.clear(); 46 } 47 48 public void activateObject(Object obj) { 50 } 51 52 public void destroyObject(Object obj) { 54 if(obj==null) return; 55 passivateObject(obj); 56 obj = null; 57 } 58 59 public boolean validateObject(Object obj) { 61 if(obj==null) 62 return false; 63 else 64 return true; 65 } 66 } 67 | Popular Tags |