org.apache.mina.util
Class BaseThreadPool

java.lang.Object
  extended by org.apache.mina.util.BaseThreadPool
All Implemented Interfaces:
ThreadPool
Direct Known Subclasses:
IoThreadPoolFilter, ProtocolThreadPoolFilter

public abstract class BaseThreadPool
extends Object
implements ThreadPool

A base implementation of Thread-pooling filters. This filter forwards events to its thread pool. This is an implementation of Leader/Followers thread pool by Douglas C. Schmidt et al.

Version:
$Rev: 332218 $, $Date: 2005-11-10 12:52:42 +0900 $
Author:
The Apache Directory Project (dev@directory.apache.org)

Nested Class Summary
protected static class BaseThreadPool.SessionBuffer
           
 
Field Summary
static int DEFAULT_KEEP_ALIVE_TIME
          Default keep-alive time of thread pool (1 min).
static int DEFAULT_MAXIMUM_POOL_SIZE
          Default maximum size of thread pool (2G).
 
Constructor Summary
BaseThreadPool(String threadNamePrefix)
          Creates a new instance with default thread pool settings.
 
Method Summary
protected  BaseThreadPool.SessionBuffer fetchSessionBuffer(Queue unfetchedSessionBuffers)
          Implement this method to fetch (or pop) a BaseThreadPool.SessionBuffer from the given unfetchedSessionBuffers.
protected  void fireEvent(Object nextFilter, Session session, EventType type, Object data)
           
 int getKeepAliveTime()
          Returns the keep-alive time until the thread suicides after it became idle (milliseconds unit).
 int getMaximumPoolSize()
          Returns the maximum size of the thread pool.
 int getPoolSize()
          Returns the number of threads in the thread pool.
 String getThreadNamePrefix()
           
protected abstract  void processEvent(Object nextFilter, Session session, EventType type, Object data)
          Implement this method to forward events to nextFilter.
 void setKeepAliveTime(int keepAliveTime)
          Sets the keep-alive time until the thread suicides after it became idle (milliseconds unit).
 void setMaximumPoolSize(int maximumPoolSize)
          Sets the maximum size of the thread pool.
 void start()
          Starts thread pool threads and starts forwarding events to them.
 void stop()
          Stops all thread pool threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAXIMUM_POOL_SIZE

public static final int DEFAULT_MAXIMUM_POOL_SIZE
Default maximum size of thread pool (2G).

See Also:
Constant Field Values

DEFAULT_KEEP_ALIVE_TIME

public static final int DEFAULT_KEEP_ALIVE_TIME
Default keep-alive time of thread pool (1 min).

See Also:
Constant Field Values
Constructor Detail

BaseThreadPool

public BaseThreadPool(String threadNamePrefix)
Creates a new instance with default thread pool settings. You'll have to invoke start() method to start threads actually.

Parameters:
threadNamePrefix - the prefix of the thread names this pool will create.
Method Detail

getThreadNamePrefix

public String getThreadNamePrefix()

getPoolSize

public int getPoolSize()
Description copied from interface: ThreadPool
Returns the number of threads in the thread pool.

Specified by:
getPoolSize in interface ThreadPool

getMaximumPoolSize

public int getMaximumPoolSize()
Description copied from interface: ThreadPool
Returns the maximum size of the thread pool.

Specified by:
getMaximumPoolSize in interface ThreadPool

getKeepAliveTime

public int getKeepAliveTime()
Description copied from interface: ThreadPool
Returns the keep-alive time until the thread suicides after it became idle (milliseconds unit).

Specified by:
getKeepAliveTime in interface ThreadPool

setMaximumPoolSize

public void setMaximumPoolSize(int maximumPoolSize)
Description copied from interface: ThreadPool
Sets the maximum size of the thread pool.

Specified by:
setMaximumPoolSize in interface ThreadPool

setKeepAliveTime

public void setKeepAliveTime(int keepAliveTime)
Description copied from interface: ThreadPool
Sets the keep-alive time until the thread suicides after it became idle (milliseconds unit).

Specified by:
setKeepAliveTime in interface ThreadPool

start

public void start()
Description copied from interface: ThreadPool
Starts thread pool threads and starts forwarding events to them.

Specified by:
start in interface ThreadPool

stop

public void stop()
Description copied from interface: ThreadPool
Stops all thread pool threads.

Specified by:
stop in interface ThreadPool

fireEvent

protected void fireEvent(Object nextFilter,
                         Session session,
                         EventType type,
                         Object data)

processEvent

protected abstract void processEvent(Object nextFilter,
                                     Session session,
                                     EventType type,
                                     Object data)
Implement this method to forward events to nextFilter.


fetchSessionBuffer

protected BaseThreadPool.SessionBuffer fetchSessionBuffer(Queue unfetchedSessionBuffers)
Implement this method to fetch (or pop) a BaseThreadPool.SessionBuffer from the given unfetchedSessionBuffers. The default implementation simply pops the buffer from it. You could prioritize the fetch order.

Returns:
A non-null BaseThreadPool.SessionBuffer


Copyright © 2004-2005 . All Rights Reserved.