rabbit.httpio
Class BaseSocketHandler

java.lang.Object
  extended by rabbit.httpio.BaseSocketHandler
All Implemented Interfaces:
SocketChannelHandler
Direct Known Subclasses:
BlockSender, HttpHeaderReader

public abstract class BaseSocketHandler
extends Object
implements SocketChannelHandler

A base class for socket handlers.

Author:
Robert Olofsson

Constructor Summary
BaseSocketHandler(SocketChannel channel, BufferHandle bh, NioHandler nioHandler)
          Create a new BaseSocketHandler that will handle the traffic on the given channel
 
Method Summary
 void closed()
          Does nothing by default
protected  void closeDown()
           
protected  ByteBuffer getBuffer()
           
 BufferHandle getBufferHandle()
          Get the BufferHandle this BaseSocketHandler is using
 SocketChannel getChannel()
          Get the channel this BaseSocketHandler is using
 String getDescription()
           
protected  ByteBuffer getLargeBuffer()
           
protected  Logger getLogger()
           
 Long getTimeout()
           
protected  boolean isUsingSmallBuffer(ByteBuffer buffer)
           
protected  void releaseBuffer()
           
 void timeout()
          Does nothing by default
 boolean useSeparateThread()
          Runs on the selector thread by default
 void waitForRead(ReadHandler rh)
          Wait for more data to be readable on the channel
 void waitForWrite(WriteHandler rh)
          Wait for more data to be writable on the channel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseSocketHandler

public BaseSocketHandler(SocketChannel channel,
                         BufferHandle bh,
                         NioHandler nioHandler)
Create a new BaseSocketHandler that will handle the traffic on the given channel

Parameters:
channel - the SocketChannel to read to and write from
bh - the BufferHandle to use for the io operation
nioHandler - the NioHandler to use to wait for operations on
Method Detail

getBuffer

protected ByteBuffer getBuffer()

getLargeBuffer

protected ByteBuffer getLargeBuffer()

isUsingSmallBuffer

protected boolean isUsingSmallBuffer(ByteBuffer buffer)

releaseBuffer

protected void releaseBuffer()

closed

public void closed()
Does nothing by default

Specified by:
closed in interface SocketChannelHandler

timeout

public void timeout()
Does nothing by default

Specified by:
timeout in interface SocketChannelHandler

useSeparateThread

public boolean useSeparateThread()
Runs on the selector thread by default

Specified by:
useSeparateThread in interface SocketChannelHandler

getDescription

public String getDescription()
Specified by:
getDescription in interface SocketChannelHandler

getTimeout

public Long getTimeout()
Specified by:
getTimeout in interface SocketChannelHandler

getLogger

protected Logger getLogger()

closeDown

protected void closeDown()

getChannel

public SocketChannel getChannel()
Get the channel this BaseSocketHandler is using

Returns:
the SocketChannel being used

getBufferHandle

public BufferHandle getBufferHandle()
Get the BufferHandle this BaseSocketHandler is using

Returns:
the BufferHandle used for io operations

waitForRead

public void waitForRead(ReadHandler rh)
Wait for more data to be readable on the channel

Parameters:
rh - the handler that will be notified when more data is ready to be read

waitForWrite

public void waitForWrite(WriteHandler rh)
Wait for more data to be writable on the channel

Parameters:
rh - the handler that will be notified when more data is ready to be written