# HG changeset patch # User sugi # Date 1403438800 -32400 # Node ID ca92da166f1a5cc7b185c3f23a43de23222c99e9 # Parent f64e53200228754f6ea124f4609f7f79de00707d check All fish object in own scene om CheckAllFishInfoExist code segment diff -r f64e53200228 -r ca92da166f1a src/main/java/alice/test/topology/aquarium/fx/AddObject.java --- a/src/main/java/alice/test/topology/aquarium/fx/AddObject.java Wed Jun 18 15:33:14 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/AddObject.java Sun Jun 22 21:06:40 2014 +0900 @@ -9,8 +9,8 @@ public class AddObject extends CodeSegment { // add Object on javaFx Scene - private Receiver info = ids.create(CommandType.PEEK); - private Receiver info1 = ids.create(CommandType.TAKE); + private Receiver info = ids.create(CommandType.PEEK); // objectList + private Receiver info1 = ids.create(CommandType.TAKE); // fish Object made from CreateObject CS private boolean executed = false; public AddObject(){ diff -r f64e53200228 -r ca92da166f1a src/main/java/alice/test/topology/aquarium/fx/CheckAllFishInfoExist.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/fx/CheckAllFishInfoExist.java Sun Jun 22 21:06:40 2014 +0900 @@ -0,0 +1,59 @@ +package alice.test.topology.aquarium.fx; + +import java.io.IOException; + +import javafx.scene.Group; +import javafx.scene.Node; + +import org.msgpack.MessagePack; +import org.msgpack.type.ArrayValue; +import org.msgpack.type.Value; + +import alice.codesegment.CodeSegment; +import alice.codesegment.SingletonMessage; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class CheckAllFishInfoExist extends CodeSegment { + // this CS check all fish object exist in scene + + private Receiver info = ids.create(CommandType.TAKE); // fishInfoList + private Receiver info1 = ids.create(CommandType.PEEK); + + public CheckAllFishInfoExist(){ + info.setKey("receiveRegisteredList"); + info1.setKey("root"); + } + + @Override + public void run() { + try { + new SendDataOthers(info, info.key); + ods.put("registeredList", info.getVal()); + ArrayValue fishInfoList = info.asClass(Value.class).asArrayValue(); + MessagePack msg = SingletonMessage.getInstance(); + Group root = info1.asClass(Group.class); + for (Value v : fishInfoList){ + boolean exist = false; + FishInfo info = msg.convert(v, FishInfo.class); + if (info.name == null) { + for (Node n : root.getChildren()) { + if (info.name.equals(n.getId())) { + exist = true; + break; + } + } + + if (!exist) { + ods.put("fishData", info); + } + } + } + + } catch (IOException e) { + e.printStackTrace(); + } + this.recycle(); + } + +} diff -r f64e53200228 -r ca92da166f1a src/main/java/alice/test/topology/aquarium/fx/CheckMyName.java --- a/src/main/java/alice/test/topology/aquarium/fx/CheckMyName.java Wed Jun 18 15:33:14 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/CheckMyName.java Sun Jun 22 21:06:40 2014 +0900 @@ -31,12 +31,14 @@ // node1 median : 10 // node2 median : 20 - if (num == 0){ // root node + if (num == 0){ + // only root node create fishInfoList registered all fishInfo + // fishInfoList send children for checking all Fish object in own scene new RegisterList(); ods.put("registeredList", new ArrayList()); - } else { - new ReceiveRegisterList(); - } + } + + new CheckAllFishInfoExist(); FishInfo fishInfo = new FishInfo(median,0,0); fishInfo.setName(name); diff -r f64e53200228 -r ca92da166f1a src/main/java/alice/test/topology/aquarium/fx/CreateObject.java --- a/src/main/java/alice/test/topology/aquarium/fx/CreateObject.java Wed Jun 18 15:33:14 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/CreateObject.java Sun Jun 22 21:06:40 2014 +0900 @@ -17,8 +17,8 @@ public class CreateObject extends CodeSegment{ - private Receiver info = ids.create(CommandType.TAKE); - private Receiver info1 = ids.create(CommandType.PEEK); + private Receiver info = ids.create(CommandType.TAKE); // fishInfo + private Receiver info1 = ids.create(CommandType.PEEK); // node name public CreateObject(){ info.setKey("fishData"); diff -r f64e53200228 -r ca92da166f1a src/main/java/alice/test/topology/aquarium/fx/ReceiveRegisterList.java --- a/src/main/java/alice/test/topology/aquarium/fx/ReceiveRegisterList.java Wed Jun 18 15:33:14 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -package alice.test.topology.aquarium.fx; - -import org.msgpack.type.Value; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -public class ReceiveRegisterList extends CodeSegment { - private Receiver info = ids.create(CommandType.PEEK); - - public ReceiveRegisterList(){ - info.setKey("registeredList"); - } - - @Override - public void run() { - Value fishInfoList = info.asClass(Value.class); - System.out.println(fishInfoList.asArrayValue()); - for (Value v : fishInfoList.asArrayValue()){ - System.out.println(v); - } - - this.recycle(); - } - -} diff -r f64e53200228 -r ca92da166f1a src/main/java/alice/test/topology/aquarium/fx/RegisterList.java --- a/src/main/java/alice/test/topology/aquarium/fx/RegisterList.java Wed Jun 18 15:33:14 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/RegisterList.java Sun Jun 22 21:06:40 2014 +0900 @@ -9,7 +9,7 @@ public class RegisterList extends CodeSegment{ private Receiver info = ids.create(CommandType.TAKE); // created fish object info - private Receiver info1 = ids.create(CommandType.PEEK); // created fish List + private Receiver info1 = ids.create(CommandType.TAKE); // created fish List public RegisterList(){ info.setKey("register"); @@ -25,7 +25,7 @@ list.add(fishInfo); ods.update(info1.key, list); - new SendDataOthers(info1, "registeredList"); + new SendDataOthers(info1, "receiveRegisteredList"); new RegisterList(); }