Mercurial > hg > FederatedLinda
annotate 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 |
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); | |
40 | 34 fds.log(Level.INFO,"Server: accepted "+channel.socket()); |
3 | 35 |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
36 tupleSpace.newUser(); |
0 | 37 |
38 // 入出力用のハンドラを生成し,アタッチする | |
39 // 監視する操作は読み込みのみ | |
40 channel.register(key.selector(), | |
41 SelectionKey.OP_READ, | |
40 | 42 new IOHandler(fds, tupleSpace,channel)); |
3 | 43 } |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
17
diff
changeset
|
44 |
0 | 45 } |