FileDocCategorySizeDatePackage
BufferPool.javaAPI DocApache Tomcat 6.0.143435Fri Jul 20 04:20:32 BST 2007org.apache.catalina.tribes.io

BufferPool

public class BufferPool extends Object
author
Filip Hanik
version
1.0

Fields Summary
protected static org.apache.juli.logging.Log
log
public static int
DEFAULT_POOL_SIZE
protected static volatile BufferPool
instance
protected BufferPoolAPI
pool
Constructors Summary
private BufferPool(BufferPoolAPI pool)


       
        this.pool = pool;
    
Methods Summary
public voidclear()

        if ( pool != null ) pool.clear();
    
public XByteBuffergetBuffer(int minSize, boolean discard)

        if ( pool != null ) return pool.getBuffer(minSize, discard);
        else return new XByteBuffer(minSize,discard);
    
public static org.apache.catalina.tribes.io.BufferPoolgetBufferPool()

        if (  (instance == null) ) {
            synchronized (BufferPool.class) {
                if ( instance == null ) {
                   BufferPoolAPI pool = null;
                   Class clazz = null;
                   try {
                       clazz = Class.forName("org.apache.catalina.tribes.io.BufferPool15Impl");
                       pool = (BufferPoolAPI)clazz.newInstance();
                   } catch ( Throwable x ) {
                       try {
                           clazz = Class.forName("org.apache.catalina.tribes.io.BufferPool14Impl");
                           pool = (BufferPoolAPI)clazz.newInstance();
                       } catch ( Throwable e ) {
                           log.warn("Unable to initilize BufferPool, not pooling XByteBuffer objects:"+x.getMessage());
                           if ( log.isDebugEnabled() ) log.debug("Unable to initilize BufferPool, not pooling XByteBuffer objects:",x);
                       }
                   }
                   pool.setMaxSize(DEFAULT_POOL_SIZE);
                   log.info("Created a buffer pool with max size:"+DEFAULT_POOL_SIZE+" bytes of type:"+(clazz!=null?clazz.getName():"null"));
                   instance = new BufferPool(pool);
                }//end if
            }//sync
        }//end if
        return instance;
    
public voidreturnBuffer(XByteBuffer buffer)

        if ( pool != null ) pool.returnBuffer(buffer);