org.apache.mina.handler

Class StreamIoHandler

Implemented Interfaces:
IoHandler

public abstract class StreamIoHandler
extends IoHandlerAdapter

A IoHandler that adapts asynchronous MINA events to stream I/O.

Please extend this class and implement processStreamIo(IoSession,InputStream,OutputStream) to execute your stream I/O logic; please note that you must forward the process request to other thread or thread pool.

Constructor Summary

StreamIoHandler()

Method Summary

void
exceptionCaught(IoSession session, Throwable cause)
Forwards caught exceptions to input stream.
int
getReadTimeout()
Returns read timeout in seconds.
int
getWriteTimeout()
Returns write timeout in seconds.
void
messageReceived(IoSession session, Object buf)
Forwards read data to input stream.
protected abstract void
processStreamIo(IoSession session, InputStream in, OutputStream out)
Implement this method to execute your stream I/O logic; please note that you must forward the process request to other thread or thread pool.
void
sessionClosed(IoSession session)
Closes streams
void
sessionIdle(IoSession session, IdleStatus status)
Handles read timeout.
void
sessionOpened(IoSession session)
Initializes streams and timeout settings.
void
setReadTimeout(int readTimeout)
Sets read timeout in seconds.
void
setWriteTimeout(int writeTimeout)
Sets write timeout in seconds.

Methods inherited from class org.apache.mina.common.IoHandlerAdapter

exceptionCaught, messageReceived, messageSent, sessionClosed, sessionCreated, sessionIdle, sessionOpened

Constructor Details

StreamIoHandler

protected StreamIoHandler()

Method Details

exceptionCaught

public void exceptionCaught(IoSession session,
                            Throwable cause)
Forwards caught exceptions to input stream.
Specified by:
exceptionCaught in interface IoHandler
Overrides:
exceptionCaught in interface IoHandlerAdapter

getReadTimeout

public int getReadTimeout()
Returns read timeout in seconds. The default value is 0 (disabled).

getWriteTimeout

public int getWriteTimeout()
Returns write timeout in seconds. The default value is 0 (disabled).

messageReceived

public void messageReceived(IoSession session,
                            Object buf)
Forwards read data to input stream.
Specified by:
messageReceived in interface IoHandler
Overrides:
messageReceived in interface IoHandlerAdapter

processStreamIo

protected abstract void processStreamIo(IoSession session,
                                        InputStream in,
                                        OutputStream out)
Implement this method to execute your stream I/O logic; please note that you must forward the process request to other thread or thread pool.

sessionClosed

public void sessionClosed(IoSession session)
            throws Exception
Closes streams
Specified by:
sessionClosed in interface IoHandler
Overrides:
sessionClosed in interface IoHandlerAdapter

sessionIdle

public void sessionIdle(IoSession session,
                        IdleStatus status)
Handles read timeout.
Specified by:
sessionIdle in interface IoHandler
Overrides:
sessionIdle in interface IoHandlerAdapter

sessionOpened

public void sessionOpened(IoSession session)
Initializes streams and timeout settings.
Specified by:
sessionOpened in interface IoHandler
Overrides:
sessionOpened in interface IoHandlerAdapter

setReadTimeout

public void setReadTimeout(int readTimeout)
Sets read timeout in seconds. The default value is 0 (disabled).

setWriteTimeout

public void setWriteTimeout(int writeTimeout)
Sets write timeout in seconds. The default value is 0 (disabled).