Hi there,
I am reading the socket communication part of the ignite source code. And I
have a question regards to the socket server.
Inside the ServerImpl.java, there is a private class called TcpServer which
will start a socket on selected port.
If portRange is used, which means Tcp Socket should listened on several ports,
like [ 47500, 47501,...47509] .
But According the codes, it seems that only one port is opened for listening?
And I guess this is why lots of socket closed exception occurs.
Please see the source code with red font for the highlights
private class TcpServer extends IgniteSpiThread {
/** Socket TCP server listens to. */
private ServerSocket srvrSock;
/** Port to listen. */
private int port;
/**
* Constructor.
*
* @throws IgniteSpiException In case of error.
*/
TcpServer() throws IgniteSpiException {
super(spi.ignite().name(), "tcp-disco-srvr", log);
setPriority(spi.threadPri);
int lastPort = spi.locPortRange == 0 ? spi.locPort : spi.locPort +
spi.locPortRange - 1;
for (port = spi.locPort; port <= lastPort; port++) {
try {
if (spi.isSslEnabled())
srvrSock =
spi.sslSrvSockFactory.createServerSocket(port, 0, spi.locHost);
else
srvrSock = new ServerSocket(port, 0, spi.locHost);
if (log.isInfoEnabled())
log.info("Successfully bound to TCP port [port=" + port
+ ", localHost=" + spi.locHost + ']');
return; // if lastPort is defined as the portRange+ locPort,
// why "return" is used in here?
// shouldn't keep running until for loop finish?
}
catch (IOException e) {
if (log.isDebugEnabled())
log.debug("Failed to bind to local port (will try next
port within range) " +
"[port=" + port + ", localHost=" + spi.locHost +
']');
onException("Failed to bind to local port. " +
"[port=" + port + ", localHost=" + spi.locHost + ']',
e);
}
}
Best Regards,
Kevin