Mercurial > hg > Database > Alice
view src/alice/daemon/AliceDaemon.java @ 175:d7816b9b72e9 working
minor change
author | e095732 |
---|---|
date | Thu, 24 Jan 2013 21:23:16 +0900 |
parents | 23d6a775a643 |
children | 52a1fa5ba38b |
line wrap: on
line source
package alice.daemon; import java.io.FileWriter; import java.io.IOException; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.nio.channels.ServerSocketChannel; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; import org.apache.log4j.WriterAppender; public class AliceDaemon { private Config conf; private AcceptThread acceptThread; private Logger log = Logger.getLogger(AliceDaemon.class); public AliceDaemon(Config conf) { this.conf = conf; setLogger(); } private void setLogger() { Logger root = Logger.getRootLogger(); if (conf.level != null) root.setLevel(conf.level); if (conf.logFile == null) return; PatternLayout layout = new PatternLayout(); layout.setConversionPattern("%d %-5p %c - %m [%t] (%F:%L)%n"); try { FileWriter writer = new FileWriter(conf.logFile); WriterAppender writerAppender = new WriterAppender(layout, writer); root.removeAllAppenders(); root.addAppender(writerAppender); } catch (IOException e) { e.printStackTrace(); } log.info("configurated"); } public void listen() { try { ServerSocketChannel ssChannel = ServerSocketChannel.open(); ServerSocket ss = ssChannel.socket(); ss.setReuseAddress(true); InetSocketAddress a = new InetSocketAddress("::", conf.localPort); System.out.println(a); //ss.bind(new InetSocketAddress(InetAddress.getLocalHost(), conf.localPort)); ss.bind(a); acceptThread = new AcceptThread(ss, "ACCEPT" + conf.localPort); acceptThread.start(); } catch (IOException e) { e.printStackTrace(); } } }