org.red5.server
Class DebugPooledByteBufferAllocator

java.lang.Object
  extended by org.red5.server.DebugPooledByteBufferAllocator
All Implemented Interfaces:
org.apache.mina.common.ByteBufferAllocator

public class DebugPooledByteBufferAllocator
extends Object
implements org.apache.mina.common.ByteBufferAllocator

A ByteBufferAllocator which pools allocated buffers.

All buffers are allocated with the size of power of 2 (e.g. 16, 32, 64, ...) This means that you cannot simply assume that the actual capacity of the buffer and the capacity you requested are same.

This allocator releases the buffers which have not been in use for a certain period. You can adjust the period by calling setTimeout(int). The default timeout is 1 minute (60 seconds). To release these buffers periodically, a daemon thread is started when a new instance of the allocator is created. You can stop the thread by calling dispose().

Author:
The Apache Directory Project (mina-dev@directory.apache.org)

Field Summary
protected static ThreadLocal local
           
protected static org.slf4j.Logger log
          Logger
protected  boolean saveStacks
          Save a stack trace for every buffer allocated? Warning: This slows down the Red5 a lot!
protected  HashMap<org.red5.server.DebugPooledByteBufferAllocator.UnexpandableByteBuffer,StackTraceElement[]> stacks
          Contains stack traces where buffers were allocated.
 
Constructor Summary
DebugPooledByteBufferAllocator()
          Creates a new instance with the default timeout.
DebugPooledByteBufferAllocator(boolean saveStacks)
           
DebugPooledByteBufferAllocator(int timeout)
          Creates a new instance with the specified timeout.
DebugPooledByteBufferAllocator(int timeout, boolean saveStacks)
           
 
Method Summary
 org.apache.mina.common.ByteBuffer allocate(int capacity, boolean direct)
           
 void dispose()
          Stops the thread which releases unused buffers and make this allocator unusable from now on.
static String getCodeSection()
           
 int getTimeout()
          Returns the timeout value of this allocator in seconds.
 long getTimeoutMillis()
          Returns the timeout value of this allocator in milliseconds.
 void printStacks()
           
 void resetStacks()
           
static void setCodeSection(String section)
           
 void setTimeout(int timeout)
          Sets the timeout value of this allocator in seconds.
 org.apache.mina.common.ByteBuffer wrap(ByteBuffer nioBuffer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.slf4j.Logger log
Logger


local

protected static ThreadLocal local

stacks

protected HashMap<org.red5.server.DebugPooledByteBufferAllocator.UnexpandableByteBuffer,StackTraceElement[]> stacks
Contains stack traces where buffers were allocated.


saveStacks

protected boolean saveStacks
Save a stack trace for every buffer allocated? Warning: This slows down the Red5 a lot!

Constructor Detail

DebugPooledByteBufferAllocator

public DebugPooledByteBufferAllocator()
Creates a new instance with the default timeout.


DebugPooledByteBufferAllocator

public DebugPooledByteBufferAllocator(boolean saveStacks)
Parameters:
saveStacks -

DebugPooledByteBufferAllocator

public DebugPooledByteBufferAllocator(int timeout)
Creates a new instance with the specified timeout.

Parameters:
timeout -

DebugPooledByteBufferAllocator

public DebugPooledByteBufferAllocator(int timeout,
                                      boolean saveStacks)
Parameters:
timeout -
saveStacks -
Method Detail

setCodeSection

public static void setCodeSection(String section)
Parameters:
section -

getCodeSection

public static String getCodeSection()
Returns:

dispose

public void dispose()
Stops the thread which releases unused buffers and make this allocator unusable from now on.

Specified by:
dispose in interface org.apache.mina.common.ByteBufferAllocator

getTimeout

public int getTimeout()
Returns the timeout value of this allocator in seconds.

Returns:

getTimeoutMillis

public long getTimeoutMillis()
Returns the timeout value of this allocator in milliseconds.

Returns:

setTimeout

public void setTimeout(int timeout)
Sets the timeout value of this allocator in seconds.

Parameters:
timeout - 0 or negative value to disable timeout.

allocate

public org.apache.mina.common.ByteBuffer allocate(int capacity,
                                                  boolean direct)
Specified by:
allocate in interface org.apache.mina.common.ByteBufferAllocator
Parameters:
capacity -
direct -
Returns:

resetStacks

public void resetStacks()

printStacks

public void printStacks()

wrap

public org.apache.mina.common.ByteBuffer wrap(ByteBuffer nioBuffer)
Specified by:
wrap in interface org.apache.mina.common.ByteBufferAllocator
Parameters:
nioBuffer -
Returns:


Copyright © 2006-2007 the Red5 project.