Package org.dellroad.stuff.net
Class TCPConnection
java.lang.Object
org.dellroad.stuff.net.ChannelConnection
org.dellroad.stuff.net.TCPConnection
- All Implemented Interfaces:
SelectorSupport.IOHandler
A TCP connection to be used with a
ChannelNetwork.
Locking
All access to this class must be with the associated TCPNetwork instance locked.
-
Field Summary
Fields inherited from class org.dellroad.stuff.net.ChannelConnection
inputChannel, inputSelectionKey, log, network, outputChannel, outputSelectionKey, peer -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTCPConnection(TCPNetwork network, String peer, SocketChannel channel) -
Method Summary
Modifier and TypeMethodDescriptionGet the associatedSocketChannel.protected voidPerform housekeeping.voidserviceIO(SelectionKey key) Handle ready I/O.protected voidUpdate selected keys.Methods inherited from class org.dellroad.stuff.net.ChannelConnection
close, getIdleTime, getInputChannel, getOutputChannel, getPeer, output, restartIdleTimer, toString
-
Constructor Details
-
TCPConnection
- Throws:
IOException
-
-
Method Details
-
getSocketChannel
Get the associatedSocketChannel.- Returns:
- the socket channel for this connection
-
updateSelection
protected void updateSelection()Description copied from class:ChannelConnectionUpdate selected keys.The implementation in
ChannelConnectionselects for read if the input queue is not full, and for write if the output queue is non-empty.- Overrides:
updateSelectionin classChannelConnection
-
serviceIO
Description copied from interface:SelectorSupport.IOHandlerHandle ready I/O.- Specified by:
serviceIOin interfaceSelectorSupport.IOHandler- Overrides:
serviceIOin classChannelConnection- Parameters:
key- selection key- Throws:
IOException- if an I/O error occurs; this will result inclose()being invoked
-
performHousekeeping
Description copied from class:ChannelConnectionPerform housekeeping. The implementation inChannelConnectionchecks the max idle time.- Overrides:
performHousekeepingin classChannelConnection- Throws:
IOException- if an I/O error occurs (this connection will be closed)
-