Mercurial > hg > Members > nobuyasu > Alice > DPPAlice
changeset 18:f0a2e2d2094e
add PutLeftForkCodeSegment, PutRightCodeSegment
author | one |
---|---|
date | Sun, 09 Dec 2012 23:00:34 +0900 |
parents | 92cde6277018 |
children | dbc5c8e8e9c2 |
files | src/alice/test/dpp/codesegment/EatCodeSegment.java src/alice/test/dpp/codesegment/PutLeftForkCodeSegment.java src/alice/test/dpp/codesegment/PutRightForkCodeSegment.java src/alice/test/dpp/codesegment/TakeLeftForkCodeSegment.java src/alice/test/dpp/codesegment/TakeRightForkCodeSegment.java src/alice/test/dpp/codesegment/ThinkCodeSegment.java src/alice/test/dpp/model/Philosophy.java |
diffstat | 7 files changed, 67 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/test/dpp/codesegment/EatCodeSegment.java Sun Dec 09 22:37:44 2012 +0900 +++ b/src/alice/test/dpp/codesegment/EatCodeSegment.java Sun Dec 09 23:00:34 2012 +0900 @@ -17,8 +17,8 @@ public void run() { Philosophy phil = arg1.asClass(Philosophy.class); System.out.println(phil.getName() + " is eating."); - phil.setState(Philosophy.State.PUTFORK); - new PutForkCodeSegment(phil.getName(), phil.getRightFork(), phil.getLeftFork()); + phil.setState(Philosophy.State.PUTRIGHTFORK); + new PutRightForkCodeSegment(phil.getName(), phil.getRightFork()); ods.update("local", phil.getName(), phil); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/dpp/codesegment/PutLeftForkCodeSegment.java Sun Dec 09 23:00:34 2012 +0900 @@ -0,0 +1,30 @@ +package alice.test.dpp.codesegment; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import alice.test.dpp.model.Fork; +import alice.test.dpp.model.Philosophy; + +public class PutLeftForkCodeSegment extends CodeSegment { + + Receiver arg1 = ids.create(CommandType.TAKE); + Receiver arg2 = ids.create(CommandType.TAKE); + + public PutLeftForkCodeSegment(String pName, String fork) { + arg1.setKey(pName); + arg2.setKey(fork); + } + + @Override + public void run() { + Philosophy phil = arg1.asClass(Philosophy.class); + Fork fork = arg2.asClass(Fork.class); + System.out.println(phil.getName() +" put left fork."); + fork.onTheTable(phil.getName()); + phil.setState(Philosophy.State.THINK); + new ThinkCodeSegment(phil.getName()); + ods.update("local", phil.getName(), phil); + ods.update("local", fork.getForkName(), fork); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/dpp/codesegment/PutRightForkCodeSegment.java Sun Dec 09 23:00:34 2012 +0900 @@ -0,0 +1,30 @@ +package alice.test.dpp.codesegment; +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import alice.test.dpp.model.Fork; +import alice.test.dpp.model.Philosophy; + + +public class PutRightForkCodeSegment extends CodeSegment { + + Receiver arg1 = ids.create(CommandType.TAKE); + Receiver arg2 = ids.create(CommandType.TAKE); + + public PutRightForkCodeSegment(String pName, String fork) { + arg1.setKey(pName); + arg2.setKey(fork); + } + + @Override + public void run() { + Philosophy phil = arg1.asClass(Philosophy.class); + Fork fork = arg2.asClass(Fork.class); + System.out.println(phil.getName() +" put right fork."); + fork.onTheTable(phil.getName()); + phil.setState(Philosophy.State.PUTLEFTFORK); + new PutLeftForkCodeSegment(phil.getName(), phil.getLeftFork()); + ods.update("local", phil.getName(), phil); + ods.update("local", fork.getForkName(), fork); + } +}
--- a/src/alice/test/dpp/codesegment/TakeLeftForkCodeSegment.java Sun Dec 09 22:37:44 2012 +0900 +++ b/src/alice/test/dpp/codesegment/TakeLeftForkCodeSegment.java Sun Dec 09 23:00:34 2012 +0900 @@ -20,6 +20,7 @@ public void run() { Philosophy phil = arg1.asClass(Philosophy.class); Fork fork = arg2.asClass(Fork.class); + System.out.println(phil.getName() + " take left fork."); if (fork.getFork(phil.getName())) { phil.setState(Philosophy.State.EAT); new EatCodeSegment(phil.getName());
--- a/src/alice/test/dpp/codesegment/TakeRightForkCodeSegment.java Sun Dec 09 22:37:44 2012 +0900 +++ b/src/alice/test/dpp/codesegment/TakeRightForkCodeSegment.java Sun Dec 09 23:00:34 2012 +0900 @@ -21,7 +21,7 @@ Philosophy phil = arg1.asClass(Philosophy.class); Fork fork = arg2.asClass(Fork.class); if (fork.getFork(phil.getName())) { - phil.setState(Philosophy.State.TAKERIGHTFORK); + phil.setState(Philosophy.State.TAKELEFTFORK); new TakeLeftForkCodeSegment(phil.getName(), phil.getLeftFork()); } else { new TakeRightForkCodeSegment(phil.getName(), phil.getRightFork()); @@ -29,6 +29,4 @@ ods.update("local", phil.getName(), phil); ods.update("local", fork.getForkName(), fork); } - - }
--- a/src/alice/test/dpp/codesegment/ThinkCodeSegment.java Sun Dec 09 22:37:44 2012 +0900 +++ b/src/alice/test/dpp/codesegment/ThinkCodeSegment.java Sun Dec 09 23:00:34 2012 +0900 @@ -17,7 +17,6 @@ public void run() { Philosophy phil = arg1.asClass(Philosophy.class); System.out.println(phil.getName() + " is thinking"); -// phil.setState(Philosophy.State.TAKEFORK); // dead lock phil.setState(Philosophy.State.TAKERIGHTFORK); new TakeRightForkCodeSegment(phil.getName(), phil.getRightFork()); ods.update("local", phil.getName(), phil);