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
ModifierConstructorDescriptionprotected
TCPConnection
(TCPNetwork network, String peer, SocketChannel channel) -
Method Summary
Modifier and TypeMethodDescriptionGet the associatedSocketChannel
.protected void
Perform housekeeping.void
serviceIO
(SelectionKey key) Handle ready I/O.protected void
Update 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:ChannelConnection
Update selected keys.The implementation in
ChannelConnection
selects for read if the input queue is not full, and for write if the output queue is non-empty.- Overrides:
updateSelection
in classChannelConnection
-
serviceIO
Description copied from interface:SelectorSupport.IOHandler
Handle ready I/O.- Specified by:
serviceIO
in interfaceSelectorSupport.IOHandler
- Overrides:
serviceIO
in classChannelConnection
- Parameters:
key
- selection key- Throws:
IOException
- if an I/O error occurs; this will result inclose()
being invoked
-
performHousekeeping
Description copied from class:ChannelConnection
Perform housekeeping. The implementation inChannelConnection
checks the max idle time.- Overrides:
performHousekeeping
in classChannelConnection
- Throws:
IOException
- if an I/O error occurs (this connection will be closed)
-