I write some scala code, which is used for shuffle.
The code is just like the following, but the serverSocket closed unexpected, the serverSocket will start(I observed using netsta), but after a while, it will be closed.
private val conManagerThread = new Thread("connection-manager-thread") {
override def run() = ConnectionManager.this.run()
}
conManagerThread.setDaemon(true)
conManagerThread.start()
def run() {
val serverSocket = new ServerSocket(port, 0, InetAddress.getByName(Utils.localHostName))
try{
//while(!conManagerThread.isInterrupted) {
while(true) {
try {
logInfo("start listening client ")
val clientSocket = serverSocket.accept()
logInfo("accept a client")
serverPool.execute(new ServerConnection(clientSocket, id, onReceiveCallback)) //TODO: the conId maybe a remote id, so we should get it from the msg
}
catch {
case e: Exception => logError("Error in serverSocket accept", e)
logError("Error in serverSocket accept")
}
}
}
catch {
case e: Exception => logError("Error in serverPool execute", e)
logError("Error in serverPool execute")
}
finally{
logInfo("=====\nserver closed\n=========")
}
and the ServerConnection is like following:
class ServerConnection(client : Socket, conId: ConnectionManagerId,
onReceiveCallback: (BufferMessage, ConnectionManagerId) => Option[Message])
extends Runnable with Logging{
def run(){
//some other code
}
}