回答 1: Java の for
2017/6/24 KANJAVA PARTY 2017 !!! 8
// l = [1, 2, 3, 4, 5]
for (int i : l) {
i = i * 3;
i = i - 1;
if (i % 2 == 0) {
System.out.println(i);
}
}
// → 2 8 14
Slide 9
Slide 9 text
回答 2: Java の Stream API
2017/6/24 KANJAVA PARTY 2017 !!! 9
// l = [1, 2, 3, 4, 5]
l.stream().map(x -> x * 3)
.map(x -> x - 1)
.filter(x -> x % 2 == 0)
.forEach(System.out::println);
// → 2 8 14
Akka-Streams を使わない場合 (結果)
2017/6/24 KANJAVA PARTY 2017 !!! 52
A started processing Hello on thread main
A finished processing Hello
A started processing Streams on thread main
A finished processing Streams
A started processing World! on thread main
A finished processing World!
B started processing Hello on thread main
B finished processing Hello
B started processing Streams on thread main
B finished processing Streams
B started processing World! on thread main
B finished processing World!
C started processing Hello on thread main
C finished processing Hello
C started processing Streams on thread main
C finished processing Streams
C started processing World! on thread main
C finished processing World!
Got output Hello
Got output Streams
Got output World!
Slide 53
Slide 53 text
Akka-Streams を使わない場合 (結果)
2017/6/24 KANJAVA PARTY 2017 !!! 53
A started processing Hello on thread main
A finished processing Hello
A started processing Streams on thread main
A finished processing Streams
A started processing World! on thread main
A finished processing World!
B started processing Hello on thread main
B finished processing Hello
B started processing Streams on thread main
B finished processing Streams
B started processing World! on thread main
B finished processing World!
C started processing Hello on thread main
C finished processing Hello
C started processing Streams on thread main
C finished processing Streams
C started processing World! on thread main
C finished processing World!
Got output Hello
Got output Streams
Got output World!
A
B
C
Hello Streams World!
List("Hello", "Streams", "World!")
.map(s => processingStageNormal("A", s))
.map(s => processingStageNormal("B", s))
.map(s => processingStageNormal("C", s))
.foreach(s ⇒ println("Got output " + s))
処理がすべて終わってから
次の処理に進んでいる
Hello Streams World!
Hello
Akka-Streams の例 (結果)
2017/6/24 KANJAVA PARTY 2017 !!! 55
A started processing Hello on thread twitter-convert-akka.actor.default-dispatcher-5
A finished processing Hello
A started processing Streams on thread twitter-convert-akka.actor.default-dispatcher-5
B started processing Hello on thread twitter-convert-akka.actor.default-dispatcher-8
B finished processing Hello
A finished processing Streams
A started processing World! on thread twitter-convert-akka.actor.default-dispatcher-5
C started processing Hello on thread twitter-convert-akka.actor.default-dispatcher-6
B started processing Streams on thread twitter-convert-akka.actor.default-dispatcher-8
B finished processing Streams
A finished processing World!
C finished processing Hello
C started processing Streams on thread twitter-convert-akka.actor.default-dispatcher-6
Got output Hello
B started processing World! on thread twitter-convert-akka.actor.default-dispatcher-8
C finished processing Streams
B finished processing World!
Got output Streams
C started processing World! on thread twitter-convert-akka.actor.default-dispatcher-6
C finished processing World!
Got output World!
Slide 56
Slide 56 text
Akka-Streams の例 (結果)
2017/6/24 KANJAVA PARTY 2017 !!! 56
A started processing Hello on thread twitter-convert-akka.actor.default-dispatcher-5
A finished processing Hello
A started processing Streams on thread twitter-convert-akka.actor.default-dispatcher-5
B started processing Hello on thread twitter-convert-akka.actor.default-dispatcher-8
B finished processing Hello
A finished processing Streams
A started processing World! on thread twitter-convert-akka.actor.default-dispatcher-5
C started processing Hello on thread twitter-convert-akka.actor.default-dispatcher-6
B started processing Streams on thread twitter-convert-akka.actor.default-dispatcher-8
B finished processing Streams
A finished processing World!
C finished processing Hello
C started processing Streams on thread twitter-convert-akka.actor.default-dispatcher-6
Got output Hello
B started processing World! on thread twitter-convert-akka.actor.default-dispatcher-8
C finished processing Streams
B finished processing World!
Got output Streams
C started processing World! on thread twitter-convert-akka.actor.default-dispatcher-6
C finished processing World!
Got output World!
A
B
C
Hello
Hello
Hello
Streams World!
Streams
Streams
World!
val completion = Source(List("Hello", "Streams", "World!"))
.via(processingStage("A")).async
.via(processingStage("B")).async
.via(processingStage("C")).async
.runWith(Sink.foreach(s ⇒ println("Got output " + s)))
処理が終わったデータから
次の処理に進んでいる
Akka-Streams の例 (async 無しの結果)
2017/6/24 KANJAVA PARTY 2017 !!! 59
A started processing Hello on thread twitter-convert-akka.actor.default-dispatcher-4
A finished processing Hello
B started processing Hello on thread twitter-convert-akka.actor.default-dispatcher-4
B finished processing Hello
C started processing Hello on thread twitter-convert-akka.actor.default-dispatcher-4
C finished processing Hello
Got output Hello
A started processing Streams on thread twitter-convert-akka.actor.default-dispatcher-4
A finished processing Streams
B started processing Streams on thread twitter-convert-akka.actor.default-dispatcher-4
B finished processing Streams
C started processing Streams on thread twitter-convert-akka.actor.default-dispatcher-4
C finished processing Streams
Got output Streams
A started processing World! on thread twitter-convert-akka.actor.default-dispatcher-4
A finished processing World!
B started processing World! on thread twitter-convert-akka.actor.default-dispatcher-4
B finished processing World!
C started processing World! on thread twitter-convert-akka.actor.default-dispatcher-4
C finished processing World!
Got output World!
Slide 60
Slide 60 text
Akka-Streams の例 (async 無しの結果)
2017/6/24 KANJAVA PARTY 2017 !!! 60
A started processing Hello on thread twitter-convert-akka.actor.default-dispatcher-4
A finished processing Hello
B started processing Hello on thread twitter-convert-akka.actor.default-dispatcher-4
B finished processing Hello
C started processing Hello on thread twitter-convert-akka.actor.default-dispatcher-4
C finished processing Hello
Got output Hello
A started processing Streams on thread twitter-convert-akka.actor.default-dispatcher-4
A finished processing Streams
B started processing Streams on thread twitter-convert-akka.actor.default-dispatcher-4
B finished processing Streams
C started processing Streams on thread twitter-convert-akka.actor.default-dispatcher-4
C finished processing Streams
Got output Streams
A started processing World! on thread twitter-convert-akka.actor.default-dispatcher-4
A finished processing World!
B started processing World! on thread twitter-convert-akka.actor.default-dispatcher-4
B finished processing World!
C started processing World! on thread twitter-convert-akka.actor.default-dispatcher-4
C finished processing World!
Got output World!
A
B
C
Hello Streams
val completion = Source(List("Hello", "Streams", "World!"))
.via(processingStage("A"))
.via(processingStage("B"))
.via(processingStage("C"))
.runWith(Sink.foreach(s ⇒ println("Got output " + s)))
処理がすべて終わってから
次の処理に進んでいる
Hello Streams
Hello Streams