annotate src/fdl/CommDebugHook.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
children a0fd653d1121
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
1 package fdl;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
2
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
3 import java.nio.ByteBuffer;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
4 import java.nio.channels.SelectionKey;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
5 import java.util.LinkedList;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
6
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
7 public class CommDebugHook implements IOHandlerHook {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
8
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
9 public LinkedList<String> logs = new LinkedList<String>();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
10
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
11 public void closeHook(SelectionKey key) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
12 if (key!=null) logs.add(closeLog(key));
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
13 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
14
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
15
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
16 @Override
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
17 public void checkHook(SelectionKey key, int id, int seq, char mode) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
18 if (key!=null) logs.add(log(key, id, seq, mode, null));
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
19 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
20
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
21
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
22 @Override
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
23 public void inHook(SelectionKey key, int id, int seq, char mode) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
24 if (key!=null) logs.add(log(key, id, seq, mode, null));
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
25 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
26
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
27
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
28 @Override
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
29 public void outHook(SelectionKey key, int id, int seq, char mode, ByteBuffer data) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
30 if (key==null) return;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
31 String sendtext = PSX.getdataString(data);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
32 logs.add(log(key, id, seq, mode, sendtext));
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
33 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
34
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
35
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
36 @Override
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
37 public void waitReadHook(SelectionKey key, int id, int seq, char mode) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
38 if (key!=null) logs.add(log(key, id, seq, mode, null));
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
39 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
40
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
41 public String log(SelectionKey key,int id, int seq,char mode, String sendtext) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
42 //通信ログ Hostname:port 'mode' =number 形式でインクリメント
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
43 int cnt = 0;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
44 if (sendtext==null) sendtext="none";
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
45
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
46 IOHandler io = (IOHandler) key.attachment();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
47 String ComKey = io.localString + "--" + io.remoteString + " " + mode;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
48
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
49 io.cnt++;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
50 long time = System.currentTimeMillis();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
51 return (time+" "+ComKey+"="+cnt+" id="+id+" seq="+seq+" data="+sendtext);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
52 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
53
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
54 private String closeLog(SelectionKey key) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
55 String close_Channel = key.channel().toString();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
56 String[] split = close_Channel.split("/");
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
57 String local[] = split[1].split(" ");
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
58 String remote[] = split[2].split("]");
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
59
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
60 String localAddress = local[0];
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
61 String remoteAddress = remote[0];
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
62
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
63 return "CloseInfo >"+localAddress+"--"+remoteAddress;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
64 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
65
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
66 public ByteBuffer getLog() {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
67 String log = logs.poll();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
68 if (log==null) return ByteBuffer.allocate(0);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
69 return PSX.string2ByteBuffer(log);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
70 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
71
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
72 }