annotate src/fdl/FDLindaServ.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 fca6eec8016f
children 81abceebc869
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
1
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
2 package fdl;
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
3
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
4 import java.io.IOException;
4
2023d9b31af9 fix parameter
fuchita
parents: 3
diff changeset
5 import java.net.InetAddress;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
6 import java.net.InetSocketAddress;
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
7 import java.nio.channels.ClosedChannelException;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
8 import java.nio.channels.SelectionKey;
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
9 import java.nio.channels.ServerSocketChannel;
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
10 import java.nio.channels.spi.AbstractSelector;
3
ae7e0e92c651 *** empty log message ***
fuchita
parents: 0
diff changeset
11 import java.nio.channels.spi.SelectorProvider;
22
56e015e8f5dc Testing TestLindaServer
kono
parents: 21
diff changeset
12 import java.util.Iterator;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
13
25
330fa49bc4fd *** empty log message ***
kono
parents: 24
diff changeset
14 /**
330fa49bc4fd *** empty log message ***
kono
parents: 24
diff changeset
15 * @author kono
330fa49bc4fd *** empty log message ***
kono
parents: 24
diff changeset
16 *
330fa49bc4fd *** empty log message ***
kono
parents: 24
diff changeset
17 */
17
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
18 public class FDLindaServ {
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
19 static final int MAX_REQ = 1;
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
20 static final int FAIL = (-1);
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
21 static final int DEF_PORT = 10000;
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
22 public int port = DEF_PORT;
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
23 private AbstractSelector selector;
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
24 private ServerSocketChannel ssChannel;
20
a0fd653d1121 Debug Client and Meta Engine for logging.
kono
parents: 19
diff changeset
25 public TupleSpace tupleSpace;
26
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
26 public MetaEngine me;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
27
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
28 public static void main(final String[] args) {
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
29 final String usages = "usage: FDLindaServ [-p port]";
4
2023d9b31af9 fix parameter
fuchita
parents: 3
diff changeset
30
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
31 int port = DEF_PORT;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
32 //引数判定
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
33 try {
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
34 for (int i=0; i<args.length; ++i) {
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
35 if("-p".equals(args[i])) {
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
36 port = Integer.parseInt(args[++i]);
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
37 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
38 }
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
39 } catch (NumberFormatException e) {
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
40 System.err.println(usages);
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
41 return;
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
42 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
43 try {
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
44 FDLindaServ serv;
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
45 serv = new FDLindaServ(port);
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
46 serv.mainLoop();
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
47 } catch (IOException e) {
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
48 System.err.println("Server Communiation Problem.");
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
49 }
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
50 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
51
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
52 private void mainLoop() {
20
a0fd653d1121 Debug Client and Meta Engine for logging.
kono
parents: 19
diff changeset
53 MetaLinda ml = new MetaLinda(tupleSpace, this);
26
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
54 // me = new NullMetaEngine(ml);
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
55 me = new MetaLogEngine(ml);
d7d70edc9c7c META_STOP worked.
kono
parents: 25
diff changeset
56 me.mainLoop();
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
57 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
58
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
59 public FDLindaServ(int port) throws IOException {
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
60 this.port = port;
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
61 //セレクタを生成
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
62 selector = SelectorProvider.provider().openSelector();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
63 //ソケット・チャネルを生成・設定
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
64 ssChannel = SelectorProvider.provider().openServerSocketChannel();
22
56e015e8f5dc Testing TestLindaServer
kono
parents: 21
diff changeset
65 // getAllByName で、すべて取って、その上のすべてでselectする必要がある。
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
66 InetSocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), port);
22
56e015e8f5dc Testing TestLindaServer
kono
parents: 21
diff changeset
67 ssChannel.socket().setReuseAddress(true);
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
68 ssChannel.socket().bind(address);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
69 ssChannel.configureBlocking(false);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
70 System.out.println("Server: litening at "+ssChannel);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
71 //セレクタにチャンネルを登録
20
a0fd653d1121 Debug Client and Meta Engine for logging.
kono
parents: 19
diff changeset
72 tupleSpace = new TupleSpace();
35
fe338d497c72 FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents: 30
diff changeset
73 ssChannel.register(selector, SelectionKey.OP_ACCEPT, new AcceptHandler(ssChannel,tupleSpace));
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
74
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
75
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
76 }
3
ae7e0e92c651 *** empty log message ***
fuchita
parents: 0
diff changeset
77
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
78 public void checkTuple() {
22
56e015e8f5dc Testing TestLindaServer
kono
parents: 21
diff changeset
79 checkTuple(0);
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
80 }
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
81
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
82 public void checkTuple(long timeout) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
83 // セレクタによる監視
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
84 try {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
85 if (selector.select(timeout)>0) {
30
fca6eec8016f *** empty log message ***
kono
parents: 26
diff changeset
86 // this does not work because #it.remove() is not called.
fca6eec8016f *** empty log message ***
kono
parents: 26
diff changeset
87 // for(SelectionKey s:selector.selectedKeys()) {
fca6eec8016f *** empty log message ***
kono
parents: 26
diff changeset
88 // TupleHandler handler = (TupleHandler)s.attachment();
fca6eec8016f *** empty log message ***
kono
parents: 26
diff changeset
89 // handler.handle(s);
fca6eec8016f *** empty log message ***
kono
parents: 26
diff changeset
90 // }
22
56e015e8f5dc Testing TestLindaServer
kono
parents: 21
diff changeset
91 for (Iterator<SelectionKey> it = selector.selectedKeys().iterator();it.hasNext(); ) {
56e015e8f5dc Testing TestLindaServer
kono
parents: 21
diff changeset
92 SelectionKey s = it.next();
56e015e8f5dc Testing TestLindaServer
kono
parents: 21
diff changeset
93 it.remove();
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
94 TupleHandler handler = (TupleHandler)s.attachment();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
95 handler.handle(s);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
96 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
97 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
98 } catch (ClosedChannelException e) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
99 // we have to do something...
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
100 } catch (IOException e) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
101 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
102 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
103 }