Mercurial > hg > FederatedLinda
view src/fdl/ComDebug.java @ 0:083a0b5e12cc
Apply Debug Interface version start
author | fuchita |
---|---|
date | Thu, 07 Feb 2008 14:21:30 +0900 |
parents | |
children | b49e593b2502 |
line wrap: on
line source
package fdl; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; import java.util.Hashtable; import java.util.Iterator; import java.util.LinkedList; public class ComDebug implements PSXQueueInterface{ static final boolean debug = true; public static Hashtable<String, Integer> Com_Hashtable = new Hashtable<String, Integer>(); public static LinkedList<SocketChannel> Report_Channellist = new LinkedList<SocketChannel>(); ComDebug(){ } public static void Report(LinkedList<SocketChannel> reportCh_list, ByteBuffer command, String report_txt) throws IOException { //レポートするチャンネルが0ならreturn if(reportCh_list.isEmpty()) { return; } //(ByteBuffer)dataに(String)report_txtを入れる byte[] txt = report_txt.getBytes(); ByteBuffer data = ByteBuffer.wrap(txt); data.rewind(); //commandをセット command.order(ByteOrder.BIG_ENDIAN); command.putInt(LINDA_PACKET_LENGTH_OFFSET,txt.length+LINDA_HEADER_SIZE-INT_SIZE); command.put(LINDA_MODE_OFFSET,(byte)'D'); command.putShort(LINDA_ID_OFFSET,(short) 0); command.putInt(LINDA_SEQ_OFFSET,0); command.putInt(LINDA_DATA_LENGTH_OFFSET,txt.length); command.rewind(); //送信 IOParam io = new IOParam(); Iterator <SocketChannel> it = reportCh_list.iterator(); while(it.hasNext()) { io.send(it.next(), command, data); } } public static void Com_inc(SelectionKey key, Hashtable<String, Integer> comlist, int mode) { //通信ログ Hostname:port 'mode' =number 形式でインクリメント int cnt = 0; SocketChannel ch = (SocketChannel) key.channel(); String socketString = ch.socket().getRemoteSocketAddress().toString(); String[] split = socketString.split("/"); int length = split.length; String ComKey = split[length-1]; ComKey += " "+(char)mode+ " "; if(comlist.containsKey(ComKey)){ cnt = comlist.get(ComKey); } cnt++; comlist.put(ComKey, cnt); } public static void addChannel(SelectionKey key, LinkedList<SocketChannel> reportCh_list) { SocketChannel repch = (SocketChannel) key.channel(); reportCh_list.add(repch); } }