public interface IOThreadingModel
TcpIpConnection
.
The default implementation of this is the NonBlockingIOThreadingModel
that relies on selectors. But also different implementations can be added like spinning, thread per connection etc.
Apart from providing a hook to add new functionality, it also simplifies the TcpIpConnection
and
TcpIpConnectionManager
since concerns are separated:
separated:
SocketReader
: responsible for reading data from the socket(channel)SocketWriter
: responsible for writing data to the socket(channel)TcpIpConnection
is pretty dumb; it doesn't know anything about threading models; it just owns
a SocketReader
and SocketWriter
. This keeps the TcpIpConnection very clean and flexible.
The idea is that different SocketReader and SocketWriter implementations can be made. We already have specific
one for non blocking (selector based) IO and for spinning io. These SocketReader/SocketWriter instances only
focus on getting data to and from the socket; they do not concern themselves about interpreting the data. This
is a concern of the ReadHandler
and the WriteHandler
instance each SocketReader/SocketWriter
has. So a SocketReader/SocketWriter-class is independent of the type of communication that runs on top of it.Modifier and Type | Method and Description |
---|---|
boolean |
isBlocking()
Tells whether or not every I/O operation on SocketChannel should block until it completes.
|
SocketReader |
newSocketReader(TcpIpConnection connection)
Creates a new SocketReader for the given connection.
|
SocketWriter |
newSocketWriter(TcpIpConnection connection)
Creates a new SocketWriter for the given connection.
|
void |
onConnectionAdded(TcpIpConnection connection)
Is called when a connection is added.
|
void |
onConnectionRemoved(TcpIpConnection connection)
Is called when a connection is removed.
|
void |
shutdown()
Shuts down the IOThreadingModel.
|
void |
start()
Starts the IOThreadingModel.
|
boolean isBlocking()
java.nio.channels.SelectableChannel#configureBlocking(boolean)}
SocketWriter newSocketWriter(TcpIpConnection connection)
connection
- the TcpIpConnection to create the SocketWriter for.SocketReader newSocketReader(TcpIpConnection connection)
connection
- the TcpIpConnection to create the SocketReader for.void onConnectionAdded(TcpIpConnection connection)
connection
- the connection added.void onConnectionRemoved(TcpIpConnection connection)
connection
- the connection removed.void start()
TcpIpConnectionManager
when it starts.TcpIpConnectionManager.start()
void shutdown()
TcpIpConnectionManager
when it shuts down.TcpIpConnectionManager.shutdown()
Copyright © 2016 Hazelcast, Inc.. All Rights Reserved.