net.sf.jbaobab.io
Class ThreadedSocketPool

java.lang.Object
  extended by net.sf.jbaobab.io.AbstractManager<ServerSocketChannel,SocketHandlerFactory>
      extended by net.sf.jbaobab.io.ThreadedSocketPool
All Implemented Interfaces:
Runnable, Manager<ServerSocketChannel,SocketHandlerFactory>, Preparer<SocketAddress,SocketHandlerFactory>, SocketPool, SocketPreparer

public class ThreadedSocketPool
extends AbstractManager<ServerSocketChannel,SocketHandlerFactory>
implements SocketPool

A SocketPool that creates SocketHandler instance on root executor (obtained with ExecutorPool.getRootExecutor()). Delegates SocketPreparer jobs to given instance on constructor. If no SocketPreparer instance is given prepare(SocketAddress, SocketHandlerFactory) will throw UnsupportedOperationException.

Author:
Oakyoon Cha
See Also:
SocketPreparer

Nested Class Summary
 class ThreadedSocketPool.SocketWorker
           
 
Nested classes/interfaces inherited from interface net.sf.jbaobab.io.SocketPreparer
SocketPreparer.NullSocketPreparer
 
Field Summary
protected  ExecutorService executor
           
protected  SocketPreparer preparer
           
protected  ChannelManager<SocketChannel> receiver
           
protected  ChannelManager<SocketChannel> sender
           
 
Fields inherited from interface net.sf.jbaobab.io.SocketPreparer
NULL
 
Constructor Summary
ThreadedSocketPool()
           
ThreadedSocketPool(ChannelManager<SocketChannel> receiver, ChannelManager<SocketChannel> sender)
           
ThreadedSocketPool(ChannelManager<SocketChannel> receiver, ChannelManager<SocketChannel> sender, SocketPreparer preparer)
           
ThreadedSocketPool(SocketPreparer preparer)
           
 
Method Summary
 boolean hold(ServerSocketChannel channel)
           
protected  void manage(SelectionKey key, SocketHandlerFactory factory)
           
 SelectionKey prepare(SocketAddress address, SocketHandlerFactory factory)
           
 SelectionKey register(ServerSocketChannel channel, SocketHandlerFactory factory)
           
 boolean release(ServerSocketChannel channel)
           
 void shutdown()
           
 void start()
           
 
Methods inherited from class net.sf.jbaobab.io.AbstractManager
cancel, interestOps, interestOps, register, run
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.jbaobab.io.Manager
cancel
 

Field Detail

receiver

protected ChannelManager<SocketChannel> receiver

sender

protected ChannelManager<SocketChannel> sender

preparer

protected SocketPreparer preparer

executor

protected ExecutorService executor
Constructor Detail

ThreadedSocketPool

public ThreadedSocketPool(ChannelManager<SocketChannel> receiver,
                          ChannelManager<SocketChannel> sender,
                          SocketPreparer preparer)
                   throws IOException
Throws:
IOException

ThreadedSocketPool

public ThreadedSocketPool(ChannelManager<SocketChannel> receiver,
                          ChannelManager<SocketChannel> sender)
                   throws IOException
Throws:
IOException

ThreadedSocketPool

public ThreadedSocketPool(SocketPreparer preparer)
                   throws IOException
Throws:
IOException

ThreadedSocketPool

public ThreadedSocketPool()
                   throws IOException
Throws:
IOException
Method Detail

register

public SelectionKey register(ServerSocketChannel channel,
                             SocketHandlerFactory factory)
Specified by:
register in interface Manager<ServerSocketChannel,SocketHandlerFactory>

hold

public boolean hold(ServerSocketChannel channel)
Specified by:
hold in interface Manager<ServerSocketChannel,SocketHandlerFactory>

release

public boolean release(ServerSocketChannel channel)
Specified by:
release in interface Manager<ServerSocketChannel,SocketHandlerFactory>

prepare

public SelectionKey prepare(SocketAddress address,
                            SocketHandlerFactory factory)
Specified by:
prepare in interface Preparer<SocketAddress,SocketHandlerFactory>

manage

protected void manage(SelectionKey key,
                      SocketHandlerFactory factory)
Specified by:
manage in class AbstractManager<ServerSocketChannel,SocketHandlerFactory>

start

public void start()
Specified by:
start in interface Manager<ServerSocketChannel,SocketHandlerFactory>
Specified by:
start in interface Preparer<SocketAddress,SocketHandlerFactory>
Overrides:
start in class AbstractManager<ServerSocketChannel,SocketHandlerFactory>

shutdown

public void shutdown()
Specified by:
shutdown in interface Manager<ServerSocketChannel,SocketHandlerFactory>
Specified by:
shutdown in interface Preparer<SocketAddress,SocketHandlerFactory>
Overrides:
shutdown in class AbstractManager<ServerSocketChannel,SocketHandlerFactory>