Class StreamIoHandler

java.lang.Object
org.apache.mina.core.service.IoHandlerAdapter
org.apache.mina.handler.stream.StreamIoHandler
All 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.

  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • KEY_IN

      private static final AttributeKey KEY_IN
    • KEY_OUT

      private static final AttributeKey KEY_OUT
    • readTimeout

      private int readTimeout
    • writeTimeout

      private int writeTimeout
  • Constructor Details

    • StreamIoHandler

      protected StreamIoHandler()
  • Method Details

    • 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.
      Parameters:
      session - The current session
      in - The input stream
      out - The output stream
    • getReadTimeout

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

      public void setReadTimeout(int readTimeout)
      Sets read timeout in seconds. The default value is 0 (disabled).
      Parameters:
      readTimeout - The Read timeout
    • getWriteTimeout

      public int getWriteTimeout()
      Returns:
      write 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).
      Parameters:
      writeTimeout - The Write timeout
    • sessionOpened

      public void sessionOpened(IoSession session)
      Initializes streams and timeout settings.
      Specified by:
      sessionOpened in interface IoHandler
      Overrides:
      sessionOpened in class IoHandlerAdapter
      Parameters:
      session - The session being opened
    • sessionClosed

      public void sessionClosed(IoSession session) throws Exception
      Closes streams
      Specified by:
      sessionClosed in interface IoHandler
      Overrides:
      sessionClosed in class IoHandlerAdapter
      Parameters:
      session - The session being closed
      Throws:
      Exception - If we get an exception while processing the close event
    • messageReceived

      public void messageReceived(IoSession session, Object buf)
      Forwards read data to input stream.
      Specified by:
      messageReceived in interface IoHandler
      Overrides:
      messageReceived in class IoHandlerAdapter
      Parameters:
      session - The session that is receiving a message
      buf - The received message
    • exceptionCaught

      public void exceptionCaught(IoSession session, Throwable cause)
      Forwards caught exceptions to input stream.
      Specified by:
      exceptionCaught in interface IoHandler
      Overrides:
      exceptionCaught in class IoHandlerAdapter
      Parameters:
      session - The session for which we have got an exception
      cause - The exception that has been caught
    • sessionIdle

      public void sessionIdle(IoSession session, IdleStatus status)
      Handles read timeout.
      Specified by:
      sessionIdle in interface IoHandler
      Overrides:
      sessionIdle in class IoHandlerAdapter
      Parameters:
      session - The idling session
      status - The session's status