# HG changeset patch # User kono # Date 1219195085 -32400 # Node ID 35375016b2f0ba3b13bd3376e3319903976a9bfe # Parent b4fd7fb9135af80ff3ee679a721e3028b51233f3 cleanup. diff -r b4fd7fb9135a -r 35375016b2f0 src/fdl/ByteBufferReader.java --- a/src/fdl/ByteBufferReader.java Wed Aug 20 03:28:45 2008 +0900 +++ b/src/fdl/ByteBufferReader.java Wed Aug 20 10:18:05 2008 +0900 @@ -15,7 +15,6 @@ @Override public int read(char[] cbuf, int off, int len) throws IOException { - // TODO Auto-generated method stub for(int i=0;i0) { - //System.out.print("reading2..."); read -= channel.read(data); } data.rewind(); @@ -87,9 +83,7 @@ PSX.printData(command); } manager_run(key, command, data); - // I believe we don't need this - //key.interestOps(key.interestOps() | SelectionKey.OP_READ ); - assert((key.interestOps()& SelectionKey.OP_READ) !=0); + // assert((key.interestOps()& SelectionKey.OP_READ) !=0); } public void manager_run(SelectionKey key, ByteBuffer command, ByteBuffer data) throws IOException { @@ -125,42 +119,5 @@ key.cancel(); channel.close(); } - - private static String getRemoteHostAndPort(SocketChannel ch) { - String socketString = ch.socket().getRemoteSocketAddress().toString(); - String[] split = socketString.split("/"); - int length = split.length; - String hostAndPort = split[length-1]; - split = hostAndPort.split(":"); - String host = split[0]; - String port = split[1]; - int portnum = Integer.parseInt(port); - try { - InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(host), portnum); - host = address.getHostName().toString(); - return (host +":"+port); - } - catch( UnknownHostException e ){ - return hostAndPort; - } - } - - private static String getLocalHostAndPort(SocketChannel ch) { - String socketString = ch.socket().getLocalSocketAddress().toString(); - String[] split = socketString.split("/"); - int length = split.length; - String hostAndPort = split[length-1]; - split = hostAndPort.split(":"); - String host = split[0]; - String port = split[1]; - try { - InetAddress localhost = InetAddress.getLocalHost(); - host = localhost.getHostName(); - return (host +":"+port); - } - catch( UnknownHostException e ){ - return (host +":"+port); - } - } } diff -r b4fd7fb9135a -r 35375016b2f0 src/fdl/PSX.java --- a/src/fdl/PSX.java Wed Aug 20 03:28:45 2008 +0900 +++ b/src/fdl/PSX.java Wed Aug 20 10:18:05 2008 +0900 @@ -13,6 +13,9 @@ package fdl; import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.CharBuffer; @@ -27,7 +30,8 @@ /** PSX Tuple Command Protocol Format - All PSX offseted command operation should be here. + All PSX offset command operation should be here. + Some public library */ public class PSX { @@ -58,16 +62,6 @@ static final int META_MONITOR = PRIVILEGED_ID_START+1; static final int META_MONITOR_DATA = PRIVILEGED_ID_START+2; - // this method should be removed - static void setReportCommand(ByteBuffer command, String report_txt) { - command.order(ByteOrder.BIG_ENDIAN); - command.putInt(LINDA_PACKET_LENGTH_OFFSET,(report_txt).length()*2+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,(report_txt).length()*2); - command.rewind(); - } static void printCommand(ByteBuffer command, ByteBuffer data) { char id = (char)command.getShort(LINDA_ID_OFFSET); @@ -168,6 +162,43 @@ SocketChannel ch = (SocketChannel)key.channel(); send(ch,command,data); } + + static String getRemoteHostAndPort(SocketChannel ch) { + String socketString = ch.socket().getRemoteSocketAddress().toString(); + String[] split = socketString.split("/"); + int length = split.length; + String hostAndPort = split[length-1]; + split = hostAndPort.split(":"); + String host = split[0]; + String port = split[1]; + int portnum = Integer.parseInt(port); + try { + InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(host), portnum); + host = address.getHostName().toString(); + return (host +":"+port); + } + catch( UnknownHostException e ){ + return hostAndPort; + } + } + + static String getLocalHostAndPort(SocketChannel ch) { + String socketString = ch.socket().getLocalSocketAddress().toString(); + String[] split = socketString.split("/"); + int length = split.length; + String hostAndPort = split[length-1]; + split = hostAndPort.split(":"); + String host = split[0]; + String port = split[1]; + try { + InetAddress localhost = InetAddress.getLocalHost(); + host = localhost.getHostName(); + return (host +":"+port); + } + catch( UnknownHostException e ){ + return (host +":"+port); + } + } } diff -r b4fd7fb9135a -r 35375016b2f0 src/fdl/PSXLinda.java --- a/src/fdl/PSXLinda.java Wed Aug 20 03:28:45 2008 +0900 +++ b/src/fdl/PSXLinda.java Wed Aug 20 10:18:05 2008 +0900 @@ -55,11 +55,9 @@ socketChannel.configureBlocking(false); socket = socketChannel.socket(); - // socket.setReuseAddress(true); + // socket.setReuseAddress(true); Client side don't need this. socket.setTcpNoDelay(true); - // can be blocked (thread required?) - //socketChannel.connect(new InetSocketAddress(InetAddress.getLocalHost(), _port)); socketChannel.connect(new InetSocketAddress(_host, _port)); while (! socketChannel.finishConnect()) { if (debug) { diff -r b4fd7fb9135a -r 35375016b2f0 src/fdl/PSXQueue.java --- a/src/fdl/PSXQueue.java Wed Aug 20 03:28:45 2008 +0900 +++ b/src/fdl/PSXQueue.java Wed Aug 20 10:18:05 2008 +0900 @@ -12,7 +12,6 @@ package fdl; -import java.io.IOException; import java.nio.ByteBuffer; /** diff -r b4fd7fb9135a -r 35375016b2f0 src/fdl/PSXReply.java --- a/src/fdl/PSXReply.java Wed Aug 20 03:28:45 2008 +0900 +++ b/src/fdl/PSXReply.java Wed Aug 20 10:18:05 2008 +0900 @@ -17,58 +17,58 @@ import java.nio.ByteBuffer; public class PSXReply { - public ByteBuffer command; - public ByteBuffer data; - public int seq; - public PSXReply next; - public int mode; - public PSXCallback callback; - static final boolean debug = false; + public ByteBuffer command; + public ByteBuffer data; + public int seq; + public PSXReply next; + public int mode; + public PSXCallback callback; + static final boolean debug = false; - public PSXReply(int _mode,PSXCallback _callback) { - mode = _mode; - callback = _callback; - } + public PSXReply(int _mode,PSXCallback _callback) { + mode = _mode; + callback = _callback; + } - public PSXReply() { - } + public PSXReply() { + } - public void setAnswer(int _mode, ByteBuffer _command,ByteBuffer _data) { - mode = _mode; - data = _data; - command = _command; - if (debug) { - System.out.print("setAnswer mode:"); - System.out.println(mode); - System.out.print("setAnswer bool:"); - System.out.println(mode==PSX.PSX_ANSWER); - } - } + public void setAnswer(int _mode, ByteBuffer _command,ByteBuffer _data) { + mode = _mode; + data = _data; + command = _command; + if (debug) { + System.out.print("setAnswer mode:"); + System.out.println(mode); + System.out.print("setAnswer bool:"); + System.out.println(mode==PSX.PSX_ANSWER); + } + } - public int getMode() { - return command.get(PSX.LINDA_MODE_OFFSET); - } + public int getMode() { + return command.get(PSX.LINDA_MODE_OFFSET); + } - public int getId() { - return command.getShort(PSX.LINDA_ID_OFFSET); - } + public int getId() { + return command.getShort(PSX.LINDA_ID_OFFSET); + } - public int getSeq() { - return command.getInt(PSX.LINDA_SEQ_OFFSET); - } + public int getSeq() { + return command.getInt(PSX.LINDA_SEQ_OFFSET); + } - public int getLength() { - return command.getInt(PSX.LINDA_DATA_LENGTH_OFFSET); - } + public int getLength() { + return command.getInt(PSX.LINDA_DATA_LENGTH_OFFSET); + } - public ByteBuffer getData() { - data.rewind(); - return data; - } + public ByteBuffer getData() { + data.rewind(); + return data; + } - public boolean ready() { - return mode==PSX.PSX_ANSWER; - } + public boolean ready() { + return mode==PSX.PSX_ANSWER; + } } diff -r b4fd7fb9135a -r 35375016b2f0 src/fdl/Tuple.java --- a/src/fdl/Tuple.java Wed Aug 20 03:28:45 2008 +0900 +++ b/src/fdl/Tuple.java Wed Aug 20 10:18:05 2008 +0900 @@ -10,6 +10,7 @@ public int seq; public ByteBuffer command; public ByteBuffer data; + // a Tuple muse remember the answer destination public SocketChannel ch; public Tuple next; @@ -31,17 +32,11 @@ } public void setTuple(int _mode,int _id, int _seq, ByteBuffer _data) { - mode = _mode; - id = _id; - seq = _seq; - data = _data; - - if (debug) { - System.out.print("setTuple mode:"); - System.out.println(mode); - } - //setCommand(); - } + mode = _mode; + id = _id; + seq = _seq; + data = _data; + } public void setSeq(int _seq) { seq = _seq; @@ -74,15 +69,4 @@ public ByteBuffer getCommand() { return this.command; } - /*public ByteBuffer getCommand() { - command = ByteBuffer.allocate(LINDA_HEADER_SIZE); - command.order(ByteOrder.BIG_ENDIAN); - command.putInt(LINDA_PACKET_LENGTH_OFFSET, LINDA_HEADER_SIZE+datalen-INT_SIZE); - command.put(LINDA_MODE_OFFSET, (byte)mode); - command.putShort(LINDA_ID_OFFSET,(short)id); - command.putInt(LINDA_SEQ_OFFSET, seq); - command.putInt(LINDA_DATA_LENGTH_OFFSET, datalen); - command.rewind(); - return command; - }*/ } diff -r b4fd7fb9135a -r 35375016b2f0 src/fdl/TupleHandler.java --- a/src/fdl/TupleHandler.java Wed Aug 20 03:28:45 2008 +0900 +++ b/src/fdl/TupleHandler.java Wed Aug 20 10:18:05 2008 +0900 @@ -5,9 +5,7 @@ import java.nio.channels.SelectionKey; public interface TupleHandler { - static final int MAX_TUPLE = 65536; - static final int MAX_USER = 4; - static final int BUFSIZE = 65535; + static final int MAX_USER = 99; public int user = 0; public void handle(SelectionKey key) throws ClosedChannelException, IOException; diff -r b4fd7fb9135a -r 35375016b2f0 src/fdl/TupleSpace.java --- a/src/fdl/TupleSpace.java Wed Aug 20 03:28:45 2008 +0900 +++ b/src/fdl/TupleSpace.java Wed Aug 20 10:18:05 2008 +0900 @@ -7,23 +7,23 @@ public class TupleSpace { static final boolean debug = true; - static final int CAPSIZE = 4194304; public static int user = 0; public byte userchar[] = new byte[2]; public Tuple[] tuple_space; public IOHandlerHook hook = new NullIOHandlerHook(); + public static final int MAX_TUPLE_ID = 65536; public TupleSpace() { // 読みこんだデータを格納するためのリストの初期化 - tuple_space = new Tuple[TupleHandler.MAX_TUPLE]; + tuple_space = new Tuple[TupleSpace.MAX_TUPLE_ID]; } public void newUser() { Tuple tmpTuple; //初期生成 - if((tmpTuple = tuple_space[TupleHandler.MAX_TUPLE-1]) == null) { - tmpTuple = tuple_space[TupleHandler.MAX_TUPLE-1] = new Tuple(); + if((tmpTuple = tuple_space[TupleSpace.MAX_TUPLE_ID-1]) == null) { + tmpTuple = tuple_space[TupleSpace.MAX_TUPLE_ID-1] = new Tuple(); tmpTuple.next = null; } else { while(tmpTuple.next != null) tmpTuple = tmpTuple.next; @@ -43,7 +43,7 @@ tmpTuple.setData(data); //Tuple - int id = TupleHandler.MAX_TUPLE-1; + int id = TupleSpace.MAX_TUPLE_ID-1; int seq = 0; tmpTuple.setTuple('o', id, seq, data); System.out.println("Server: assign id "+user); diff -r b4fd7fb9135a -r 35375016b2f0 src/fdl/URLKicker.java --- a/src/fdl/URLKicker.java Wed Aug 20 03:28:45 2008 +0900 +++ b/src/fdl/URLKicker.java Wed Aug 20 10:18:05 2008 +0900 @@ -13,7 +13,6 @@ import java.net.*; import java.io.*; -// mport java.nio.*; /** diff -r b4fd7fb9135a -r 35375016b2f0 src/fdl/test/TestLindaServer.java --- a/src/fdl/test/TestLindaServer.java Wed Aug 20 03:28:45 2008 +0900 +++ b/src/fdl/test/TestLindaServer.java Wed Aug 20 10:18:05 2008 +0900 @@ -33,7 +33,6 @@ public static void main(String[] arg) { TestLindaServer me = new TestLindaServer(); me.test1(); - } public void test1() { @@ -41,7 +40,6 @@ Client c = new Client(); new Thread(s).start(); new Thread(c).start(); - }