Mercurial > hg > Database > Alice
view src/main/java/alice/daemon/AcceptThread.java @ 542:bd245df5cba3 dispose
add AliceDeamon on paramater
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 03 Aug 2015 19:00:06 +0900 |
parents | 0832af83583f |
children | f3f7e256ee03 |
line wrap: on
line source
package alice.daemon; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import org.apache.log4j.Logger; import alice.datasegment.DataSegment; public class AcceptThread extends Thread { private final AliceDaemon alice; private ServerSocket ss; private Logger log = Logger.getLogger(AcceptThread.class); public int counter = 0; public AcceptThread(ServerSocket ss, String name, AliceDaemon aliceDaemon) { super(name); this.ss = ss; this.alice = aliceDaemon; } @Override public void run() { while (true) { try { Socket socket = ss.accept(); socket.setTcpNoDelay(true); log.info("Accept " + socket.getInetAddress().getHostName() + ":" + socket.getPort()); Connection connection = new Connection(socket, alice); String key = "accept" + counter; IncomingTcpConnection in = new IncomingTcpConnection(connection, alice.dataSegment.get("local"), key); in.setName(connection.getInfoString()+"-IncomingTcp"); in.start(); alice.dataSegment.setAccept(key, in); OutboundTcpConnection out = new OutboundTcpConnection(connection); out.setName(connection.getInfoString()+"-OutboundTcp"); out.start(); counter++; } catch (IOException e) { e.printStackTrace(); } } } }