# HG changeset patch # User kazz # Date 1280072423 -32400 # Node ID 8cec713e5abf1e445f4e2f331978eba5dc48f344 # Parent 065450f32960045761ceb28ab40d14e36378b5ac add update() api diff -r 065450f32960 -r 8cec713e5abf src/fdl/IOHandler.java --- a/src/fdl/IOHandler.java Mon Jul 19 18:45:47 2010 +0900 +++ b/src/fdl/IOHandler.java Mon Jul 26 00:40:23 2010 +0900 @@ -67,7 +67,9 @@ } else if (mode == PSX.PSX_WAIT_RD) { tupleSpace.Wait_Rd(key, command, mode); } else if(mode == PSX.PSX_OUT) { - tupleSpace.Out(key, command, data); + tupleSpace.Out(key, command, data); + } else if (mode == PSX.PSX_UPDATE){ + tupleSpace.Update(key, command, data); } else { tupleSpace.hook.closeHook(key); fds.log(Level.SEVERE,"Incorrect tuple operation"); diff -r 065450f32960 -r 8cec713e5abf src/fdl/TupleSpace.java --- a/src/fdl/TupleSpace.java Mon Jul 19 18:45:47 2010 +0900 +++ b/src/fdl/TupleSpace.java Mon Jul 26 00:40:23 2010 +0900 @@ -57,13 +57,18 @@ } protected void Out(SelectionKey key,ByteBuffer command, ByteBuffer data) { - Tuple tuple; - int id; - int datasize; char idc = (char)command.getShort(PSX.LINDA_ID_OFFSET); command.rewind(); - id = (int)idc; + int id = (int)idc; + + Out1(key, command, data, id); + } + + private void Out1(SelectionKey key, ByteBuffer command, ByteBuffer data, + int id) { + Tuple tuple; + int datasize; datasize = command.getInt(PSX.LINDA_DATA_LENGTH_OFFSET); command.rewind(); @@ -77,7 +82,7 @@ PSX.setAnserCommand(command, tuple_space[id].getSeq()); PSX.send(tuple_space[id].ch, command, data); - removeTuple(id); + tuple_space[id] = tuple_space[id].next; tuple = null; } if(tuple_space[id] != null && tuple_space[id].mode == PSX.PSX_IN) { @@ -87,7 +92,7 @@ if (debug) fds.log(Level.INFO,"send size "+datasize+" : mode = "+(char)'a'); } PSX.send(tuple_space[id].ch, command, data); - removeTuple(id); + tuple_space[id] = tuple_space[id].next; tuple = null; // Incoming Out tuple is consumed here, and wating IN tuple is also removed. } else if ((tuple_space[id] == null)|| (tuple_space[id].getMode() == PSX.PSX_OUT)) { @@ -113,13 +118,26 @@ } } - private void removeTuple(int id) { - Tuple tuple; - //後処理 - tuple = tuple_space[id]; - tuple_space[id] = tuple.next; + protected void Update(SelectionKey key, ByteBuffer command, ByteBuffer data) { + char idc = (char)command.getShort(PSX.LINDA_ID_OFFSET); + command.rewind(); + int id = (int)idc; + + Tuple tuple = tuple_space[id]; + if (tuple != null) { + while (tuple.next != null) + tuple = tuple.next; + tuple.id = id; + tuple.setCommand(PSX.PSX_ANSWER, command.getInt(PSX.LINDA_SEQ_OFFSET)); + } else { + tuple = new Tuple(); + tuple.setCommand(PSX.PSX_ANSWER, id, command.getInt(PSX.LINDA_SEQ_OFFSET), ByteBuffer.allocate(0)); + } + tuple_space[id] = null; + Out1(key, command, data, id); + PSX.send(key, tuple.getCommand(), tuple.getData()); } - + protected void Wait_Rd(SelectionKey key, ByteBuffer command, int mode) { Tuple tuple; int id; @@ -293,5 +311,4 @@ return data; } - }