Mercurial > hg > Database > Alice
view src/main/java/alice/daemon/AcceptThread.java @ 480:c06070403ed4 dispose
named IncomingTcp and OutboundTcp Thread
author | sugi |
---|---|
date | Fri, 05 Dec 2014 03:19:25 +0900 |
parents | 780ae843cdac |
children | 8227a2fd5a55 |
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 ServerSocket ss; private Logger log = Logger.getLogger(AcceptThread.class); public int counter = 0; public AcceptThread(ServerSocket ss, String name) { super(name); this.ss = ss; } @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); String key = "accept" + counter; IncomingTcpConnection in = new IncomingTcpConnection(connection, DataSegment.get("local"), key); in.setName("IncomingTcp"); in.start(); DataSegment.setAccept(key, in); OutboundTcpConnection out = new OutboundTcpConnection(connection); out.setName("OutboundTcp"); out.start(); counter++; } catch (IOException e) { e.printStackTrace(); } } } }