annotate src/fdl/FDLindaServ.java @ 19:0243987383b7

Meta Protocol Engine and sample implementation of event logger. ComDebug_Client needs fixes.
author kono
date Tue, 19 Aug 2008 05:33:32 +0900
parents 609b288f47f9
children a0fd653d1121
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;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
12
17
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
13 public class FDLindaServ {
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
14 static final int MAX_REQ = 1;
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
15 static final int FAIL = (-1);
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
16 static final int DEF_PORT = 10000;
4
2023d9b31af9 fix parameter
fuchita
parents: 3
diff changeset
17 //public static final int TIMEOUT = 5*1000;
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
18 public int port = DEF_PORT;
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
19 private AbstractSelector selector;
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
20 private ServerSocketChannel ssChannel;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
21
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
22 public static void main(final String[] args) {
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
23 final String usages = "usage: FDLindaServ [-p port]";
4
2023d9b31af9 fix parameter
fuchita
parents: 3
diff changeset
24 //バイトオーダー確認
2023d9b31af9 fix parameter
fuchita
parents: 3
diff changeset
25 //System.out.println(ByteOrder.nativeOrder().toString());
2023d9b31af9 fix parameter
fuchita
parents: 3
diff changeset
26
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
27 int port = DEF_PORT;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
28 //引数判定
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
29 try {
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
30 for (int i=0; i<args.length; ++i) {
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
31 if("-p".equals(args[i])) {
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
32 port = Integer.parseInt(args[++i]);
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
33 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
34 }
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
35 } catch (NumberFormatException e) {
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
36 System.err.println(usages);
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
37 return;
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
38 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
39 try {
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
40 FDLindaServ serv;
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
41 serv = new FDLindaServ(port);
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
42 serv.mainLoop();
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
43 } catch (IOException e) {
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
44 System.err.println("Server Communiation Problem.");
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
45 }
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
46 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
47
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
48 private void mainLoop() {
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
49 while(true) {
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
50 checkTuple();
15
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 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
53
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
54 public FDLindaServ(int port) throws IOException {
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
55 this.port = port;
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
56 //セレクタを生成
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
57 selector = SelectorProvider.provider().openSelector();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
58 //ソケット・チャネルを生成・設定
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
59 ssChannel = SelectorProvider.provider().openServerSocketChannel();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
60 InetSocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), port);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
61 ssChannel.socket().bind(address);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
62 ssChannel.configureBlocking(false);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
63 //ssChannel.socket().setReuseAddress(true);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
64 System.out.println("Server: litening at "+ssChannel);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
65 //セレクタにチャンネルを登録
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
66 TupleSpace tupleSpace = new TupleSpace();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
67 ssChannel.register(selector, SelectionKey.OP_ACCEPT, new AcceptHandler(tupleSpace));
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
68
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
69
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
70 }
3
ae7e0e92c651 *** empty log message ***
fuchita
parents: 0
diff changeset
71
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
72 public void checkTuple() {
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
73 // セレクタによる監視
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
74 try {
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
75 if (selector.select()>0) {
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
76 for(SelectionKey s:selector.selectedKeys()) {
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
77 TupleHandler handler = (TupleHandler)s.attachment();
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
78 handler.handle(s);
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
79 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
80 }
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
81 } catch (ClosedChannelException e) {
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
82 // we have to do something...
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
83 } catch (IOException e) {
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 4
diff changeset
84 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
85 }
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
86
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
87 public void checkTuple(long timeout) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
88 // セレクタによる監視
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
89 try {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
90 if (selector.select(timeout)>0) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
91 for(SelectionKey s:selector.selectedKeys()) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
92 TupleHandler handler = (TupleHandler)s.attachment();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
93 handler.handle(s);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
94 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
95 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
96 } catch (ClosedChannelException e) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
97 // we have to do something...
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
98 } catch (IOException e) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
99 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents: 17
diff changeset
100 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
101 }