Class StreamIoHandler
java.lang.Object
org.apache.mina.core.service.IoHandlerAdapter
org.apache.mina.handler.stream.StreamIoHandler
- All Implemented Interfaces:
IoHandler
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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final AttributeKeyprivate static final AttributeKeyprivate static final org.slf4j.Loggerprivate intprivate int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidexceptionCaught(IoSession session, Throwable cause) Forwards caught exceptions to input stream.intintvoidmessageReceived(IoSession session, Object buf) Forwards read data to input stream.protected abstract voidprocessStreamIo(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.voidsessionClosed(IoSession session) Closes streamsvoidsessionIdle(IoSession session, IdleStatus status) Handles read timeout.voidsessionOpened(IoSession session) Initializes streams and timeout settings.voidsetReadTimeout(int readTimeout) Sets read timeout in seconds.voidsetWriteTimeout(int writeTimeout) Sets write timeout in seconds.Methods inherited from class IoHandlerAdapter
event, inputClosed, messageSent, sessionCreated
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
KEY_IN
-
KEY_OUT
-
readTimeout
private int readTimeout -
writeTimeout
private int writeTimeout
-
-
Constructor Details
-
StreamIoHandler
protected StreamIoHandler()
-
-
Method Details
-
processStreamIo
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 sessionin- The input streamout- 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 is0(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 is0(disabled).- Parameters:
writeTimeout- The Write timeout
-
sessionOpened
Initializes streams and timeout settings.- Specified by:
sessionOpenedin interfaceIoHandler- Overrides:
sessionOpenedin classIoHandlerAdapter- Parameters:
session- The session being opened
-
sessionClosed
Closes streams- Specified by:
sessionClosedin interfaceIoHandler- Overrides:
sessionClosedin classIoHandlerAdapter- Parameters:
session- The session being closed- Throws:
Exception- If we get an exception while processing the close event
-
messageReceived
Forwards read data to input stream.- Specified by:
messageReceivedin interfaceIoHandler- Overrides:
messageReceivedin classIoHandlerAdapter- Parameters:
session- The session that is receiving a messagebuf- The received message
-
exceptionCaught
Forwards caught exceptions to input stream.- Specified by:
exceptionCaughtin interfaceIoHandler- Overrides:
exceptionCaughtin classIoHandlerAdapter- Parameters:
session- The session for which we have got an exceptioncause- The exception that has been caught
-
sessionIdle
Handles read timeout.- Specified by:
sessionIdlein interfaceIoHandler- Overrides:
sessionIdlein classIoHandlerAdapter- Parameters:
session- The idling sessionstatus- The session's status
-