view src/main/java/alice/daemon/AcceptThread.java @ 419:aefbe41fcf12 dispose

change tab to space
author sugi
date Tue, 15 Jul 2014 16:00:22 +0900
parents 8f71c3e6f11d
children cf0eb5b2b4d2
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 incoming =
                        new IncomingTcpConnection(connection, DataSegment.get("local"), key);
                incoming.start();
                DataSegment.setAccept(key, incoming);
                new OutboundTcpConnection(connection).start();
                counter++;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}