Mercurial > hg > FederatedLinda
comparison src/fdl/IOHandler.java @ 35:fe338d497c72 meta-comdebug-wokred
FederatedLinda was static singleton. It does not work on Thread based test.
author | kono |
---|---|
date | Sun, 24 Aug 2008 19:07:28 +0900 |
parents | 64071f8e2e0d |
children | 81abceebc869 |
comparison
equal
deleted
inserted
replaced
34:e7c5958fd285 | 35:fe338d497c72 |
---|---|
8 import java.nio.channels.SocketChannel; | 8 import java.nio.channels.SocketChannel; |
9 | 9 |
10 public class IOHandler implements TupleHandler { | 10 public class IOHandler implements TupleHandler { |
11 static final boolean debug = true; | 11 static final boolean debug = true; |
12 public TupleSpace tupleSpace; | 12 public TupleSpace tupleSpace; |
13 public SocketChannel ch; | |
13 | 14 |
14 String remoteString; | 15 String remoteString; |
15 String localString; | 16 String localString; |
16 public int cnt = 0; | 17 public int cnt = 0; |
17 | 18 |
18 public IOHandler(TupleSpace tupleSpace,SocketChannel ch) { | 19 public IOHandler(TupleSpace tupleSpace,SocketChannel ch) { |
19 this.tupleSpace = tupleSpace; | 20 this.tupleSpace = tupleSpace; |
20 | 21 |
21 remoteString = PSX.getRemoteHostAndPort(ch); | 22 remoteString = PSX.getRemoteHostAndPort(ch); |
22 localString = PSX.getLocalHostAndPort(ch); | 23 localString = PSX.getLocalHostAndPort(ch); |
24 this.ch = ch; | |
23 } | 25 } |
24 | 26 |
25 public void handle(SelectionKey key) { | 27 public void handle(SelectionKey key) { |
26 // 書き込み可であれば,読み込みを行う | 28 // 書き込み可であれば,読み込みを行う |
27 if (key.isReadable()) { | 29 if (key.isReadable()) { |
38 } | 40 } |
39 | 41 |
40 void read(SelectionKey key) | 42 void read(SelectionKey key) |
41 throws ClosedChannelException, IOException { | 43 throws ClosedChannelException, IOException { |
42 SocketChannel channel = (SocketChannel)key.channel(); | 44 SocketChannel channel = (SocketChannel)key.channel(); |
45 if (ch!=channel) { | |
46 System.err.println("Wrong socket on IOHandler"); | |
47 } | |
43 | 48 |
44 // 読み込み用のバッファの生成 | 49 // 読み込み用のバッファの生成 |
45 ByteBuffer command = ByteBuffer.allocate(PSX.LINDA_HEADER_SIZE); | 50 ByteBuffer command = ByteBuffer.allocate(PSX.LINDA_HEADER_SIZE); |
46 command.order(ByteOrder.BIG_ENDIAN); | 51 command.order(ByteOrder.BIG_ENDIAN); |
47 | 52 |