Mercurial > hg > FederatedLinda
view src/fdl/AcceptHandler.java @ 110:8ae522e1a4bf
add jar (junit and protobuf)
author | kazz |
---|---|
date | Wed, 04 Aug 2010 21:41:39 +0900 |
parents | 9cdc24bae625 |
children |
line wrap: on
line source
package fdl; import java.io.IOException; import java.nio.channels.ClosedChannelException; import java.nio.channels.SelectionKey; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.util.logging.Level; public class AcceptHandler implements TupleHandler { public TupleSpace tupleSpace; public ServerSocketChannel ss; private FDLindaServ fds; public AcceptHandler(FDLindaServ fds,ServerSocketChannel ss, TupleSpace tupleSpace) { // 読みこんだデータを格納するためのリストの初期化 this.tupleSpace = tupleSpace; this.ss = ss; this.fds = fds; } public void handle(SelectionKey key) throws ClosedChannelException, IOException { ServerSocketChannel serverChannel = (ServerSocketChannel)key.channel(); if (ss!=serverChannel) { fds.log(Level.SEVERE,"Wrong server socket channel."); } // アクセプト処理 SocketChannel channel = serverChannel.accept(); channel.configureBlocking(false); //channel.socket().setTcpNoDelay(true); fds.log(Level.INFO,"Server: accepted "+channel.socket()); // TCP N Delay を ServerSocketChannel のオプションに指定する // setTcpNoDelay(boolean on) tupleSpace.newUser(); // 入出力用のハンドラを生成し,アタッチする // 監視する操作は読み込みのみ channel.register(key.selector(), SelectionKey.OP_READ, new IOHandler(fds, tupleSpace,channel)); } }