Mercurial > hg > FederatedLinda
view src/fdl/AcceptHandler.java @ 71:0352536c33fa
(example: writer) get linda server addr from commandline arg.
author | kazz@e065701.local |
---|---|
date | Fri, 23 Oct 2009 14:11:07 +0900 |
parents | 046feb56a196 |
children | 5336bafaaf48 |
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); fds.log(Level.INFO,"Server: accepted "+channel.socket()); tupleSpace.newUser(); // 入出力用のハンドラを生成し,アタッチする // 監視する操作は読み込みのみ channel.register(key.selector(), SelectionKey.OP_READ, new IOHandler(fds, tupleSpace,channel)); } }