Mercurial > hg > FederatedLinda
annotate 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 |
rev | line source |
---|---|
0 | 1 |
2 package fdl; | |
3 import java.io.IOException; | |
4 import java.nio.channels.ClosedChannelException; | |
5 import java.nio.channels.SelectionKey; | |
6 import java.nio.channels.ServerSocketChannel; | |
7 import java.nio.channels.SocketChannel; | |
40 | 8 import java.util.logging.Level; |
0 | 9 |
17 | 10 public class AcceptHandler implements TupleHandler { |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
11 |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
12 public TupleSpace tupleSpace; |
35
fe338d497c72
FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents:
22
diff
changeset
|
13 public ServerSocketChannel ss; |
40 | 14 private FDLindaServ fds; |
0 | 15 |
40 | 16 public AcceptHandler(FDLindaServ fds,ServerSocketChannel ss, TupleSpace tupleSpace) { |
0 | 17 // 読みこんだデータを格納するためのリストの初期化 |
35
fe338d497c72
FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents:
22
diff
changeset
|
18 this.tupleSpace = tupleSpace; |
fe338d497c72
FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents:
22
diff
changeset
|
19 this.ss = ss; |
40 | 20 this.fds = fds; |
0 | 21 } |
22 | |
23 public void handle(SelectionKey key) | |
24 throws ClosedChannelException, IOException { | |
25 ServerSocketChannel serverChannel | |
40 | 26 = (ServerSocketChannel)key.channel(); |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
27 |
35
fe338d497c72
FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents:
22
diff
changeset
|
28 if (ss!=serverChannel) { |
40 | 29 fds.log(Level.SEVERE,"Wrong server socket channel."); |
35
fe338d497c72
FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents:
22
diff
changeset
|
30 } |
0 | 31 // アクセプト処理 |
32 SocketChannel channel = serverChannel.accept(); | |
33 channel.configureBlocking(false); | |
90 | 34 //channel.socket().setTcpNoDelay(true); |
40 | 35 fds.log(Level.INFO,"Server: accepted "+channel.socket()); |
3 | 36 |
77 | 37 // TCP N Delay を ServerSocketChannel のオプションに指定する |
38 // setTcpNoDelay(boolean on) | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
39 tupleSpace.newUser(); |
0 | 40 |
41 // 入出力用のハンドラを生成し,アタッチする | |
42 // 監視する操作は読み込みのみ | |
43 channel.register(key.selector(), | |
44 SelectionKey.OP_READ, | |
40 | 45 new IOHandler(fds, tupleSpace,channel)); |
3 | 46 } |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
47 |
0 | 48 } |