annotate src/fdl/CommDebugHook.java @ 34:e7c5958fd285

*** empty log message ***
author kono
date Sun, 24 Aug 2008 17:36:14 +0900
parents 56e015e8f5dc
children fe338d497c72
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 public void checkHook(SelectionKey key, int id, int seq, char mode) {
34
e7c5958fd285 *** empty log message ***
kono
parents: 22
diff changeset
17 if (key==null || id<PSX.PRIVILEGED_ID_START) return;
e7c5958fd285 *** empty log message ***
kono
parents: 22
diff changeset
18 logs.add(log(key, id, seq, mode, null));
19
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 public void inHook(SelectionKey key, int id, int seq, char mode) {
34
e7c5958fd285 *** empty log message ***
kono
parents: 22
diff changeset
23 if (key==null || id<PSX.PRIVILEGED_ID_START) return;
e7c5958fd285 *** empty log message ***
kono
parents: 22
diff changeset
24 logs.add(log(key, id, seq, mode, null));
19
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 public void outHook(SelectionKey key, int id, int seq, char mode, ByteBuffer data) {
34
e7c5958fd285 *** empty log message ***
kono
parents: 22
diff changeset
29 if (key==null || id<PSX.PRIVILEGED_ID_START) return;
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
30 String sendtext = PSX.getdataString(data);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
31 logs.add(log(key, id, seq, mode, sendtext));
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
32 }
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 public void waitReadHook(SelectionKey key, int id, int seq, char mode) {
34
e7c5958fd285 *** empty log message ***
kono
parents: 22
diff changeset
36 if (key==null || id<PSX.PRIVILEGED_ID_START) return;
e7c5958fd285 *** empty log message ***
kono
parents: 22
diff changeset
37 logs.add(log(key, id, seq, mode, null));
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
38 }
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 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
41 //通信ログ Hostname:port 'mode' =number 形式でインクリメント
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
42 int cnt = 0;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
43 if (sendtext==null) sendtext="none";
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
44
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
45 IOHandler io = (IOHandler) key.attachment();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
46 String ComKey = io.localString + "--" + io.remoteString + " " + mode;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
47
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
48 io.cnt++;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
49 long time = System.currentTimeMillis();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
50 return (time+" "+ComKey+"="+cnt+" id="+id+" seq="+seq+" data="+sendtext);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
51 }
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 private String closeLog(SelectionKey key) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
54 String close_Channel = key.channel().toString();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
55 String[] split = close_Channel.split("/");
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
56 String local[] = split[1].split(" ");
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
57 String remote[] = split[2].split("]");
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
58
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
59 String localAddress = local[0];
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
60 String remoteAddress = remote[0];
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
61
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
62 return "CloseInfo >"+localAddress+"--"+remoteAddress;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
63 }
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 public ByteBuffer getLog() {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
66 String log = logs.poll();
20
a0fd653d1121 Debug Client and Meta Engine for logging.
kono
parents: 19
diff changeset
67 if (log==null) return null;
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
68 return PSX.string2ByteBuffer(log);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
69 }
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 }