Mercurial > hg > Database > Alice
changeset 397:ca92da166f1a multicast
check All fish object in own scene om CheckAllFishInfoExist code segment
author | sugi |
---|---|
date | Sun, 22 Jun 2014 21:06:40 +0900 |
parents | f64e53200228 |
children | e2bfd4fec741 |
files | src/main/java/alice/test/topology/aquarium/fx/AddObject.java src/main/java/alice/test/topology/aquarium/fx/CheckAllFishInfoExist.java src/main/java/alice/test/topology/aquarium/fx/CheckMyName.java src/main/java/alice/test/topology/aquarium/fx/CreateObject.java src/main/java/alice/test/topology/aquarium/fx/ReceiveRegisterList.java src/main/java/alice/test/topology/aquarium/fx/RegisterList.java |
diffstat | 6 files changed, 71 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- 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(){
--- /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(); + } + +}
--- 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<FishInfo>()); - } else { - new ReceiveRegisterList(); - } + } + + new CheckAllFishInfoExist(); FishInfo fishInfo = new FishInfo(median,0,0); fishInfo.setName(name);
--- 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");
--- 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(); - } - -}
--- 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(); }