diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2180570..1e4cf30 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -11,8 +11,11 @@ - + + + + @@ -40,78 +43,40 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - + + + + + + + + - - + + - - - - - + + - - + + - + @@ -120,76 +85,84 @@ - - + + - - - - - - - - - - - - + + + + - - + + - - + + + + + + - - + + - - + + + + + - - + + - + - - + + - + - - + - - + + - + + + + + + + + + + + @@ -2790,7 +2763,6 @@ @@ -2874,7 +2847,6 @@ - @@ -3108,20 +3080,32 @@ + - + + - + + - + + - @@ -3135,7 +3119,7 @@ + + + @@ -3211,8 +3236,6 @@ - - @@ -3263,7 +3286,7 @@ - + @@ -3290,7 +3313,7 @@ - + - + - + - + + + + - - - - - + + @@ -3726,7 +3749,7 @@ - + @@ -3737,13 +3760,12 @@ - + - @@ -3756,6 +3778,7 @@ + @@ -3828,7 +3851,7 @@ file://$PROJECT_DIR$/shelly/src/main/java/xiaofei/library/shelly/Domino.java - 278 + 261 @@ -3838,10 +3861,28 @@ - + - + + + + + + + + + + + + + + + + + + + @@ -3894,18 +3935,10 @@ - - - - - - - - @@ -3930,14 +3963,6 @@ - - - - - - - - @@ -3952,29 +3977,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -3982,14 +3984,6 @@ - - - - - - - - @@ -4008,134 +4002,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -4221,16 +4091,6 @@ - - - - - - - - - - @@ -4293,94 +4153,166 @@ - + + + + + + + + + + + - - + + - - - - - - - - - - - - - + - + + + + + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/app.iml b/app/app.iml index aae810f..69af623 100644 --- a/app/app.iml +++ b/app/app.iml @@ -64,14 +64,6 @@ - - - - - - - - @@ -80,6 +72,14 @@ + + + + + + + + diff --git a/shelly/shelly.iml b/shelly/shelly.iml index 7e826f2..d627276 100644 --- a/shelly/shelly.iml +++ b/shelly/shelly.iml @@ -65,14 +65,6 @@ - - - - - - - - @@ -81,6 +73,14 @@ + + + + + + + + @@ -104,8 +104,8 @@ - + diff --git a/shelly/src/main/java/xiaofei/library/shelly/TaskDomino.java b/shelly/src/main/java/xiaofei/library/shelly/TaskDomino.java index 477dd12..44b3839 100644 --- a/shelly/src/main/java/xiaofei/library/shelly/TaskDomino.java +++ b/shelly/src/main/java/xiaofei/library/shelly/TaskDomino.java @@ -338,12 +338,32 @@ private Domino> toDomino() { return new Domino>(getLabel(), getPlayer()); } - public Domino endTask() { + public Domino endTask() { + return endTask(new Function1>, List>() { + @Override + public List call(List> input) { + List result = new ArrayList(); + for (Triple triple : input) { + if (triple.first) { + result.add(triple.second); + } + } + return result; + } + }); + } + + public Domino endTaskEmpty() { return toDomino().clear(); } - public Domino endTask(Function1>, S> reducer) { - return toDomino().reduce(reducer); + public Domino endTask(Function1>, List> reducer) { + return toDomino().reduce(reducer).flatMap(new Function1, List>() { + @Override + public List call(List input) { + return input; + } + }); } @Override diff --git a/shelly/src/test/java/xiaofei/library/shelly/Test06.java b/shelly/src/test/java/xiaofei/library/shelly/Test06.java index 23ba444..b05ec9e 100644 --- a/shelly/src/test/java/xiaofei/library/shelly/Test06.java +++ b/shelly/src/test/java/xiaofei/library/shelly/Test06.java @@ -139,7 +139,7 @@ public void call() { System.out.println("13: " + Thread.currentThread().getName()); } }) - .endTask() + .endTaskEmpty() .target(new Action1() { @Override public void call(String input) { @@ -156,6 +156,129 @@ public void call() { Shelly.playDomino(1, "A", "BD", "CG"); } + @Test + public void testTask2() { + class A { + public void f(Character s) { + System.out.println("A f: " + Thread.currentThread().getName() + " " + s); + } + public void g(int s) { + System.out.println("A g: " + Thread.currentThread().getName() + " " + s); + } + } + Shelly.register(new A()); + Shelly.createDomino(3) + .beginTask(new Task() { + @Override + protected void onExecute(String input) { + System.out.println("1: " + Thread.currentThread().getName() + " " + input); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("2: " + Thread.currentThread().getName() + " " + input); + if (input.length() == 1) { + notifySuccess(input.charAt(0)); + } else { + notifyFailure(input.charAt(0) - 'A'); + } + } + }) + .onSuccess(Shelly.createDomino() + .background() + .target(new Action1() { + @Override + public void call(Character input) { + System.out.println("3: " + Thread.currentThread().getName() + " " + input); + } + })) + .newThread() + .onSuccess(new Action0() { + @Override + public void call() { + System.out.println("4: " + Thread.currentThread().getName()); + } + }) + .onSuccess(new Action1() { + @Override + public void call(Character input) { + System.out.println("5: " + Thread.currentThread().getName() + " " + input); + } + }) + .background() + .onSuccess(A.class, new TargetAction0() { + @Override + public void call(A a) { + System.out.println("6: " + Thread.currentThread().getName()); + a.f('T'); + } + }) + .backgroundQueue() + .onFailure(Shelly.createDomino() + .newThread() + .target(new Action1() { + @Override + public void call(Integer input) { + System.out.println("7: " + Thread.currentThread().getName() + " " + input); + } + })) + .onFailure(new Action1() { + @Override + public void call(Integer input) { + System.out.println("8: " + Thread.currentThread().getName() + " " + input); + } + }) + .onFailure(new Action0() { + @Override + public void call() { + System.out.println("9: " + Thread.currentThread().getName()); + } + }) + .onSuccess(A.class, new TargetAction1() { + @Override + public void call(A a, Character input) { + System.out.println("10: " + Thread.currentThread().getName() + " " + input); + a.f(input); + } + }) + .onFailure(A.class, new TargetAction0() { + @Override + public void call(A a) { + System.out.println("11: " + Thread.currentThread().getName()); + a.g(1000); + } + }) + .onFailure(A.class, new TargetAction1() { + @Override + public void call(A a, Integer input) { + System.out.println("12: " + Thread.currentThread().getName() + " " + input); + a.g(input); + } + }) + .finallyDo(new Action0() { + @Override + public void call() { + System.out.println("13: " + Thread.currentThread().getName()); + } + }) + .endTask() + .target(new Action1() { + @Override + public void call(Character input) { + System.out.println("14: " + Thread.currentThread().getName() + " " + input); + } + }) + .target(new Action0() { + @Override + public void call() { + System.out.println("15: " + Thread.currentThread().getName()); + } + }) + .commit(); + Shelly.playDomino(3, "A", "BD", "CG"); + } + @Test public void testThrottle() { Shelly.createDomino(2)