annotate src/fdl/CommDebugHook.java @ 71:0352536c33fa

(example: writer) get linda server addr from commandline arg.
author kazz@e065701.local
date Fri, 23 Oct 2009 14:11:07 +0900
parents 2a366abc3f1f
children
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>();
37
2a366abc3f1f *** empty log message ***
kono
parents: 35
diff changeset
10 // String conversion is too expensive, should use ByteBuffer directory or
2a366abc3f1f *** empty log message ***
kono
parents: 35
diff changeset
11 // create log object for the purpose.
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
12
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
13 public void closeHook(SelectionKey key) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
14 if (key!=null) logs.add(closeLog(key));
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
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
17
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
18 public void checkHook(SelectionKey key, int id, int seq, char mode) {
35
fe338d497c72 FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents: 34
diff changeset
19 if (isPrivilege(key, id)) return;
34
e7c5958fd285 *** empty log message ***
kono
parents: 22
diff changeset
20 logs.add(log(key, id, seq, mode, null));
19
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
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
23
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
24 public void inHook(SelectionKey key, int id, int seq, char mode) {
35
fe338d497c72 FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents: 34
diff changeset
25 if (isPrivilege(key, id)) return;
34
e7c5958fd285 *** empty log message ***
kono
parents: 22
diff changeset
26 logs.add(log(key, id, seq, mode, null));
19
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
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
29
35
fe338d497c72 FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents: 34
diff changeset
30 private boolean isPrivilege(SelectionKey key, int id) {
fe338d497c72 FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents: 34
diff changeset
31 return key==null || id>=PSX.PRIVILEGED_ID_START;
fe338d497c72 FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents: 34
diff changeset
32 }
fe338d497c72 FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents: 34
diff changeset
33
fe338d497c72 FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents: 34
diff changeset
34
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
35 public void outHook(SelectionKey key, int id, int seq, char mode, ByteBuffer data) {
35
fe338d497c72 FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents: 34
diff changeset
36 if (isPrivilege(key, id)) return;
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
37 String sendtext = PSX.getdataString(data);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
38 logs.add(log(key, id, seq, mode, sendtext));
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
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
42 public void waitReadHook(SelectionKey key, int id, int seq, char mode) {
35
fe338d497c72 FederatedLinda was static singleton. It does not work on Thread based test.
kono
parents: 34
diff changeset
43 if (isPrivilege(key, id)) return;
34
e7c5958fd285 *** empty log message ***
kono
parents: 22
diff changeset
44 logs.add(log(key, id, seq, mode, null));
19
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
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
47 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
48 //通信ログ Hostname:port 'mode' =number 形式でインクリメント
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
49 int cnt = 0;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
50 if (sendtext==null) sendtext="none";
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 IOHandler io = (IOHandler) key.attachment();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
53 String ComKey = io.localString + "--" + io.remoteString + " " + mode;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
54
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
55 io.cnt++;
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
56 long time = System.currentTimeMillis();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
57 return (time+" "+ComKey+"="+cnt+" id="+id+" seq="+seq+" data="+sendtext);
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
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
60 private String closeLog(SelectionKey key) {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
61 String close_Channel = key.channel().toString();
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
62 String[] split = close_Channel.split("/");
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
63 String local[] = split[1].split(" ");
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
64 String remote[] = split[2].split("]");
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 String localAddress = local[0];
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
67 String remoteAddress = remote[0];
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
68
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
69 return "CloseInfo >"+localAddress+"--"+remoteAddress;
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 public ByteBuffer getLog() {
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
73 String log = logs.poll();
20
a0fd653d1121 Debug Client and Meta Engine for logging.
kono
parents: 19
diff changeset
74 if (log==null) return null;
19
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
75 return PSX.string2ByteBuffer(log);
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
76 }
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
77
0243987383b7 Meta Protocol Engine and sample implementation of event logger.
kono
parents:
diff changeset
78 }