Mercurial > hg > FederatedLinda
annotate src/fdl/PSX.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 | 2cbd98257d61 |
children | 56e015e8f5dc |
rev | line source |
---|---|
17 | 1 |
2 /* | |
3 * @(#)PSXQueueInterface.java 1.1 06/04/01 | |
4 * | |
5 * Copyright 2006 Shinji KONO | |
6 * | |
7 | |
8 PSX Lidna | |
9 Trasport layer of PSX Linda library | |
10 | |
11 */ | |
12 | |
13 package fdl; | |
14 | |
15 import java.nio.ByteBuffer; | |
16 import java.nio.ByteOrder; | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
17 import java.nio.CharBuffer; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
18 import java.nio.charset.CharacterCodingException; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
19 import java.nio.charset.Charset; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
20 import java.nio.charset.CharsetDecoder; |
17 | 21 |
22 | |
23 | |
24 /** | |
18 | 25 PSX Tuple Command Protocol Format |
17 | 26 |
18 | 27 All PSX offseted command operation should be here. |
17 | 28 */ |
29 | |
30 public class PSX { | |
31 static final int PSX_IN = 'i'; | |
32 static final int PSX_OUT = 'o'; | |
33 static final int PSX_UPDATE = 'u'; | |
34 static final int PSX_RD = 'r'; | |
35 static final int PSX_CHECK = 'c'; | |
36 static final int PSX_REPLY = '?'; | |
37 static final int PSX_WAIT_RD = 'w'; | |
38 static final int PSX_ANSWER = 'a'; | |
39 static final int PSX_HTTP_ANSWER = 'P'; // Put | |
40 static final int PSX_HTTP_REQUEST = 'G'; // Get | |
41 static final int PSX_COM_DEBUG = 'D'; //Communication DEBUG | |
42 | |
43 static final int LINDA_PACKET_LENGTH_OFFSET =0; | |
44 static final int LINDA_MODE_OFFSET =0+4; | |
45 static final int LINDA_ID_OFFSET =1+4; | |
46 static final int LINDA_SEQ_OFFSET =3+4; | |
47 static final int LINDA_DATA_LENGTH_OFFSET =7+4; | |
48 static final int LINDA_HEADER_SIZE =12+4; | |
49 static final int INT_SIZE =4; | |
50 static final int SHORT_SIZE =2; | |
51 | |
52 static final int PRIVILEGED_ID_START = 32768; | |
53 static final int PRIVILEGED_ID_END = 36864; | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
54 static final int META_STOP = PRIVILEGED_ID_START; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
55 static final int META_MONITOR = PRIVILEGED_ID_START+1; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
56 static final int META_MONITOR_DATA = PRIVILEGED_ID_START+2; |
17 | 57 |
58 // this method should be removed | |
59 static void setReportCommand(ByteBuffer command, String report_txt) { | |
60 command.order(ByteOrder.BIG_ENDIAN); | |
61 command.putInt(LINDA_PACKET_LENGTH_OFFSET,(report_txt).length()*2+LINDA_HEADER_SIZE-INT_SIZE); | |
62 command.put(LINDA_MODE_OFFSET,(byte)'D'); | |
63 command.putShort(LINDA_ID_OFFSET,(short) 0); | |
64 command.putInt(LINDA_SEQ_OFFSET,0); | |
65 command.putInt(LINDA_DATA_LENGTH_OFFSET,(report_txt).length()*2); | |
66 command.rewind(); | |
67 } | |
68 | |
69 static void printCommand(ByteBuffer command, ByteBuffer data) { | |
70 char id = (char)command.getShort(LINDA_ID_OFFSET); | |
71 System.out.println("LENGTH:"+command.getInt(LINDA_PACKET_LENGTH_OFFSET)+" "+ | |
72 "MODE:"+(char)command.get(LINDA_MODE_OFFSET)+" "+ | |
73 "ID:"+(int)id+" "+ | |
74 "SEQ:"+command.getInt(LINDA_SEQ_OFFSET)+" "+ | |
75 "DATA LENGTH:"+command.getInt(LINDA_DATA_LENGTH_OFFSET)+" "); | |
76 System.out.println("DATA:"+data); | |
77 command.rewind(); | |
78 } | |
79 | |
80 static void printData(ByteBuffer command) { | |
81 /*** print data ***/ | |
82 char id = (char)command.getShort(LINDA_ID_OFFSET); | |
83 System.out.println("LENGTH:"+command.getInt(LINDA_PACKET_LENGTH_OFFSET)+" "+ | |
84 "MODE:"+(char)command.get(LINDA_MODE_OFFSET)+" "+ | |
85 "ID:"+(int)id+" "+ | |
86 "SEQ:"+command.getInt(LINDA_SEQ_OFFSET)+" "); | |
87 command.rewind(); | |
88 } | |
89 | |
90 | |
91 static void setCommand(ByteBuffer command, int _mode, int _id, int _seq, int _datalen) { | |
92 command = ByteBuffer.allocate(LINDA_HEADER_SIZE); | |
93 command.order(ByteOrder.BIG_ENDIAN); | |
94 | |
95 command.putInt(LINDA_PACKET_LENGTH_OFFSET, | |
96 _datalen+LINDA_HEADER_SIZE-INT_SIZE); | |
97 command.put(LINDA_MODE_OFFSET,(byte)_mode); | |
98 command.putShort(LINDA_ID_OFFSET,(short)_id); | |
99 command.putInt(LINDA_SEQ_OFFSET,_seq); | |
100 command.putInt(LINDA_DATA_LENGTH_OFFSET,_datalen); | |
101 command.rewind(); | |
102 } | |
103 | |
104 static void setAnserCommand(ByteBuffer command, int seq) { | |
105 command.put(LINDA_MODE_OFFSET, (byte)'a'); | |
106 command.rewind(); | |
107 command.putInt(LINDA_SEQ_OFFSET, seq); | |
108 command.rewind(); | |
109 } | |
19
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
110 |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
111 public static ByteBuffer string2ByteBuffer(String log) { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
112 ByteBuffer blog = ByteBuffer.allocate(log.length()*2); // this is incorrect... |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
113 for(int i=0;i<log.length();i++) { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
114 blog.putChar(log.charAt(i)); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
115 } |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
116 blog.flip(); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
117 return blog; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
118 } |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
119 |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
120 public static String getdataString(ByteBuffer data) { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
121 String sendtext; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
122 data.rewind(); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
123 //Decode UTF-8 to System Encoding(UTF-16) |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
124 Charset charset = Charset.forName("UTF-8"); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
125 CharsetDecoder decoder = charset.newDecoder(); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
126 CharBuffer cb = null; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
127 try { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
128 cb = decoder.decode(data); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
129 } catch (CharacterCodingException e) { |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
130 e.printStackTrace(); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
131 } |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
132 cb.rewind(); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
133 |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
134 sendtext = cb.toString(); |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
135 return sendtext; |
0243987383b7
Meta Protocol Engine and sample implementation of event logger.
kono
parents:
18
diff
changeset
|
136 } |
17 | 137 |
138 | |
139 } | |
140 | |
141 /* end */ |