Mercurial > hg > FederatedLinda
changeset 5:4391c9fac885
fix parameter
author | fuchita |
---|---|
date | Sat, 16 Feb 2008 13:06:47 +0900 |
parents | 2023d9b31af9 |
children | fbe09047ab4a |
files | src/fdl/ComDebug.java src/fdl/ComDebug_Client.java src/fdl/IOHandler.java src/fdl/IOParam.java |
diffstat | 4 files changed, 141 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- a/src/fdl/ComDebug.java Tue Feb 12 09:15:25 2008 +0900 +++ b/src/fdl/ComDebug.java Sat Feb 16 13:06:47 2008 +0900 @@ -89,7 +89,7 @@ } } - public static String Com_inc(SelectionKey key, Hashtable<String, Integer> comlist, int mode) { + public static String Com_inc(SelectionKey key, Hashtable<String, Integer> comlist,int mode, int id, int seq, String sendtext) { //通信ログ Hostname:port 'mode' =number 形式でインクリメント int cnt = 0; SocketChannel ch = (SocketChannel) key.channel(); @@ -103,8 +103,8 @@ } cnt++; comlist.put(ComKey, cnt); - long seq = System.currentTimeMillis(); - return (seq+" "+ComKey+"="+cnt); + long time = System.currentTimeMillis(); + return (time+" "+ComKey+"="+cnt+" id="+id+" seq="+seq+" data="+sendtext); } public static void addChannel(SelectionKey key, LinkedList<SocketChannel> reportCh_list) {
--- a/src/fdl/ComDebug_Client.java Tue Feb 12 09:15:25 2008 +0900 +++ b/src/fdl/ComDebug_Client.java Sat Feb 16 13:06:47 2008 +0900 @@ -4,6 +4,7 @@ import java.io.IOException; //import java.nio.ByteBuffer; //import java.nio.CharBuffer; +import java.nio.CharBuffer; public class ComDebug_Client implements PSXQueueInterface{ @@ -21,18 +22,22 @@ //引数判定 try { + if (args.length < 2) { + System.err.println(usages); + } + for (int i=0; i<args.length; ++i) { if("-h".equals(args[i])) { host = (String)(args[++i]); System.err.println("host = "+host); } else { - System.err.println(usages); + //System.err.println(usages); } if("-p".equals(args[i])) { port = Integer.parseInt(args[++i]); System.err.println("port = "+port); } else { - System.err.println(usages); + //System.err.println(usages); } } } catch (NumberFormatException e) {
--- a/src/fdl/IOHandler.java Tue Feb 12 09:15:25 2008 +0900 +++ b/src/fdl/IOHandler.java Sat Feb 16 13:06:47 2008 +0900 @@ -112,7 +112,10 @@ int mode = command.get(LINDA_MODE_OFFSET); char idc = (char)command.getShort(LINDA_ID_OFFSET); int id = (int)idc; + int seq = command.getInt(LINDA_SEQ_OFFSET); command.rewind(); + String sendtext = "none"; + com_debug = new ComDebug(); Hashtable<String, Integer> com_Loggingtable = ComDebug.Com_Hashtable; @@ -125,14 +128,14 @@ ClosewishComDebug(key, command, reportCh_list); } else if(mode == PSX_CHECK) { - Check(key, command); + sendtext = Check(key, command); } else if(mode == PSX_IN || mode == PSX_RD){ - In_Rd(key, command, mode); + sendtext = In_Rd(key, command, mode); } else if (mode == PSX_WAIT_RD) { Wait_Rd(key, command, mode); } else if(mode == PSX_OUT) { - Out(command, data); + sendtext = Out(command, data); } else { System.out.println("Uncorrect buffer"); System.exit(1); @@ -143,10 +146,8 @@ ComDebug.addChannel(key, reportCh_list); } //DEBUG用カウンタ - String debug_rep = ComDebug.Com_inc(key, com_Loggingtable, mode); - //System.out.println("Com_Debug:"); - //System.out.println(com_Loggingtable.toString()); - //DEBUG用レポート + String debug_rep = ComDebug.Com_inc(key, com_Loggingtable, mode, id, seq, sendtext); + //DEBUG用レポート ComDebug.Report(reportCh_list, command, debug_rep); if (key.interestOps()
--- a/src/fdl/IOParam.java Tue Feb 12 09:15:25 2008 +0900 +++ b/src/fdl/IOParam.java Sat Feb 16 13:06:47 2008 +0900 @@ -2,9 +2,13 @@ import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.CharBuffer; import java.nio.channels.ClosedChannelException; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; +import java.nio.charset.CharacterCodingException; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; public class IOParam implements TupleHandler, PSXQueueInterface{ static final boolean debug = true; @@ -21,13 +25,14 @@ // TODO Auto-generated constructor stub } - protected void Out(ByteBuffer command, ByteBuffer data) throws IOException { + protected String Out(ByteBuffer command, ByteBuffer data) throws IOException { Tuple tmpTuple; int id; int datasize; char idc = (char)command.getShort(LINDA_ID_OFFSET); command.rewind(); id = (int)idc; + String sendtext = "none"; datasize = command.getInt(LINDA_DATA_LENGTH_OFFSET); command.rewind(); @@ -47,7 +52,10 @@ //ByteBuffer sendcommand = tmpTuple.getCommand(); //ByteBuffer senddata = tmpTuple.getData(); send(tuple_space[id].ch, command, data); - + + sendtext = getdataString(data); + + //後処理 tmpTuple = tuple_space[id]; tuple_space[id] = tmpTuple.next; @@ -66,6 +74,8 @@ //ByteBuffer sendcommand = tmpTuple.getCommand(); //ByteBuffer senddata = tmpTuple.getData(); send(tuple_space[id].ch, command, data); + + sendtext = getdataString(data); //後処理 tmpTuple = tuple_space[id]; @@ -99,6 +109,7 @@ data.clear(); System.exit(1); } + return sendtext; } protected void Wait_Rd(SelectionKey key, ByteBuffer command, int mode) { @@ -127,96 +138,104 @@ } } - protected void In_Rd(SelectionKey key, ByteBuffer command, int mode) + protected String In_Rd(SelectionKey key, ByteBuffer command, int mode) throws IOException { - Tuple tmpTuple; - int id; - //id = command.getInt(LINDA_ID_OFFSET); - //int mode = command.getInt(LINDA_MODE_OFFSET); - Tuple temp = null; - - char idc = (char)command.getShort(LINDA_ID_OFFSET); - command.rewind(); - id = (int)idc; - - System.out.println("*** "+(char)mode+" command : id = "+ id +" ***\n"); - - tmpTuple = tuple_space[id]; + Tuple tmpTuple; + int id; + //id = command.getInt(LINDA_ID_OFFSET); + //int mode = command.getInt(LINDA_MODE_OFFSET); + Tuple temp = null; + + char idc = (char)command.getShort(LINDA_ID_OFFSET); + command.rewind(); + id = (int)idc; + + String sendtext = "none"; + + System.out.println("*** "+(char)mode+" command : id = "+ id +" ***\n"); + + tmpTuple = tuple_space[id]; - //wを無視 - while(tmpTuple != null && tmpTuple.next != null && (tmpTuple.mode == 'w')){ - temp = tmpTuple; - tmpTuple = tmpTuple.next; - } + //wを無視 + while(tmpTuple != null && tmpTuple.next != null && (tmpTuple.mode == 'w')){ + temp = tmpTuple; + tmpTuple = tmpTuple.next; + } + + if (tmpTuple != null && (tmpTuple.mode == 'o')){ + //tmpTuple = new Tuple((SocketChannel)key.channel()); + int seq = command.getInt(LINDA_SEQ_OFFSET); + command.rewind(); + tmpTuple.setCommand('a', seq); + + if(debug){ + int sendsize = tmpTuple.getdataLength()+LINDA_HEADER_SIZE; + System.out.println("send size "+sendsize+" : mode = "+(char)tmpTuple.getMode()); + } - if (tmpTuple != null && (tmpTuple.mode == 'o')){ - //tmpTuple = new Tuple((SocketChannel)key.channel()); - int seq = command.getInt(LINDA_SEQ_OFFSET); - command.rewind(); - tmpTuple.setCommand('a', seq); - - if(debug){ - int sendsize = tmpTuple.getdataLength()+LINDA_HEADER_SIZE; - System.out.println("send size "+sendsize+" : mode = "+(char)tmpTuple.getMode()); - } + //send + ByteBuffer sendcommand = tmpTuple.getCommand(); + ByteBuffer senddata = tmpTuple.getData(); + send(key,sendcommand, senddata); + + sendtext = getdataString(senddata); + - //send - ByteBuffer sendcommand = tmpTuple.getCommand(); - ByteBuffer senddata = tmpTuple.getData(); - send(key,sendcommand, senddata); - - //INの場合はremoveする - if(mode == PSX_IN) { - if(tmpTuple.data != null){ - //ByteBuffer buff = ByteBuffer.allocate(0); - //tmpTuple.setData(buff); - tmpTuple.data = null; - } - if(temp != null){ - temp.next = tmpTuple.next; - } - else { - tuple_space[id] = tmpTuple.next; - } - tmpTuple = null; - } - } else { - if(tmpTuple == null) { - //ServerSocketChannel sc = (ServerSocketChannel)key.channel(); - tmpTuple = tuple_space[id] = new Tuple((SocketChannel)key.channel()); - tmpTuple.next = null; - }else { - while(tmpTuple.next !=null) tmpTuple =tmpTuple.next; - tmpTuple.next= new Tuple((SocketChannel)key.channel()); - tmpTuple = tmpTuple.next; - tmpTuple.next = null; - } - - tmpTuple.setMode(mode); - int seq2 = command.getInt(LINDA_SEQ_OFFSET); - command.rewind(); - tmpTuple.setSeq(seq2); - tmpTuple.ch = (SocketChannel) key.channel(); - tmpTuple.setDataLength(0); - ByteBuffer buff = ByteBuffer.allocate(0); - buff.rewind(); - tmpTuple.setData(buff); - - if(debug){ - System.out.println("data inserted insert seq = "+seq2 +", id = "+id); - } + //INの場合はremoveする + if(mode == PSX_IN) { + if(tmpTuple.data != null){ + //ByteBuffer buff = ByteBuffer.allocate(0); + //tmpTuple.setData(buff); + tmpTuple.data = null; + } + if(temp != null){ + temp.next = tmpTuple.next; + } + else { + tuple_space[id] = tmpTuple.next; } - - //} else if (command.getInt(LINDA_MODE_OFFSET) == PSX_WAIT_RD) { + tmpTuple = null; + } + } else { + if(tmpTuple == null) { + //ServerSocketChannel sc = (ServerSocketChannel)key.channel(); + tmpTuple = tuple_space[id] = new Tuple((SocketChannel)key.channel()); + tmpTuple.next = null; + }else { + while(tmpTuple.next !=null) tmpTuple =tmpTuple.next; + tmpTuple.next= new Tuple((SocketChannel)key.channel()); + tmpTuple = tmpTuple.next; + tmpTuple.next = null; } + + tmpTuple.setMode(mode); + int seq2 = command.getInt(LINDA_SEQ_OFFSET); + command.rewind(); + tmpTuple.setSeq(seq2); + tmpTuple.ch = (SocketChannel) key.channel(); + tmpTuple.setDataLength(0); + ByteBuffer buff = ByteBuffer.allocate(0); + buff.rewind(); + tmpTuple.setData(buff); + + if(debug){ + System.out.println("data inserted insert seq = "+seq2 +", id = "+id); + } + } + + //} else if (command.getInt(LINDA_MODE_OFFSET) == PSX_WAIT_RD) { + return sendtext; + } - protected void Check(SelectionKey key, ByteBuffer command) throws IOException { + protected String Check(SelectionKey key, ByteBuffer command) throws IOException { ByteBuffer data; Tuple tmpTuple; int id; char idc = (char)command.getShort(LINDA_ID_OFFSET); command.rewind(); id = (int)idc; + String sendtext = "none"; + tmpTuple = tuple_space[id]; while(tmpTuple != null && tmpTuple.next != null && (tmpTuple.mode == 'w')){ tmpTuple = tmpTuple.next; @@ -233,6 +252,10 @@ data = ByteBuffer.allocate(0); } send(key, command, data); + + sendtext = getdataString(data); + + return sendtext; } public void send(SocketChannel ch, ByteBuffer command, ByteBuffer data) @@ -302,6 +325,27 @@ } } + private String getdataString(ByteBuffer data) { + String sendtext; + data.rewind(); + //set sendtext + //CharBuffer chardata = data.asCharBuffer(); + + //Decode UTF-8 to System Encoding(UTF-16) + Charset charset = Charset.forName("UTF-8"); + CharsetDecoder decoder = charset.newDecoder(); + CharBuffer cb = null; + try { + cb = decoder.decode(data); + } catch (CharacterCodingException e) { + e.printStackTrace(); + } + cb.rewind(); + + sendtext = cb.toString(); + return sendtext; + } + public void handle(SelectionKey key) throws ClosedChannelException, IOException {