SlideShare a Scribd company logo
1 of 91
Download to read offline
Konrad 'ktoso' Malawski
GeeCON 2014 @ Kraków, PL
Konrad `@ktosopl` Malawski
Fresh from the Oven -
akka
Konrad 'ktoso' Malawski
GeeCON 2014 @ Kraków, PL
Konrad `@ktosopl` Malawski
Fresh from the Oven -
akka gets Typed
Konrad `ktoso` Malawski
Akka Team,
Reactive Streams TCK
Konrad `@ktosopl` Malawski
akka.io
typesafe.com
geecon.org
Java.pl / KrakowScala.pl
sckrk.com / meetup.com/Paper-Cup @ London
GDGKrakow.pl
lambdakrk.pl
Nice to meet you!
Who are you guys?
Disclaimer
Modules discussed in this talk are
pre-experimental or not even released yet.
Also known as
“don’t use in production”,
“please give us feedback”,
“docs are work in progress”
etc.
Everything shown is experimental!
The cake is a lie!
Agenda
• What Akka is at it’s heart
• Old Typed Actors + some background
• Akka Typed
• Akka Streams / Reactive Streams
• Wrapping up
experimental
experimental
not released yet
Akka Actors
Akka Actors
“untyped”
The Actor Model
The Actor Model as defined by Hewitt, Bishop and Steiger in 1973 is a computational
model that expresses exactly what it means for computation to be distributed.
Actors can only communicate by exchanging messages.
Upon reception of a message an Actor can do the following three fundamental actions:
• send a finite number of messages to Actors it knows
• create a finite number of new Actors
• designate the behavior to be applied to the next message
Why Untyped?
Inspired by Erlang, that’s untyped as well.
Modelling “become” is non obvious:
“what about races in sending msgs which change state?”
Networking is untyped - sorry.
Pattern matching makes extracting types simple.
Several failed attempts (incl. in Erlang)
(Yes, we know session types).
Akka Typed
Akka Typed
NOT the Old Typed Actors module
Akka Typed
NOT the Old Typed Actors module
Old Typed Actors
Were never intended to be a core abstraction.
Just a “bridge from Java-land to Actor-land”.
A note on Distributed Computing by Jim Waldo et al.
Old Typed Actors
Were never intended to be a core abstraction.
Just a “bridge from Java-land to Actor-land”.
trait Squarer {
def squareDontCare(i: Int): Unit //fire-forget
def square(i: Int): Future[Int] //non-blocking send-request-reply
def squareNowPlease(i: Int): Option[Int] //blocking send-request-reply
def squareNow(i: Int): Int //blocking send-request-reply
@throws(classOf[Exception]) //declare it or you will get an UndeclaredThrowableException
def squareTry(i: Int): Int //blocking send-request-reply with possible exception
}
A note on Distributed Computing by Jim Waldo et al.
Old Typed Actors
Were never intended to be a core abstraction.
Just a “bridge from Java-land to Actor-land”.
trait Squarer {
def squareDontCare(i: Int): Unit //fire-forget
def square(i: Int): Future[Int] //non-blocking send-request-reply
def squareNowPlease(i: Int): Option[Int] //blocking send-request-reply
def squareNow(i: Int): Int //blocking send-request-reply
@throws(classOf[Exception]) //declare it or you will get an UndeclaredThrowableException
def squareTry(i: Int): Int //blocking send-request-reply with possible exception
}
NOT what you’re looking for
A note on Distributed Computing by Jim Waldo et al.
The old “Typed Actors”
trait Squarer {
def squareDontCare(i: Int): Unit //fire-forget
def square(i: Int): Future[Int] //non-blocking send-request-reply
def squareNowPlease(i: Int): Option[Int] //blocking send-request-reply
def squareNow(i: Int): Int //blocking send-request-reply
@throws(classOf[Exception]) //declare it or you will get an UndeclaredThrowableException
def squareTry(i: Int): Int //blocking send-request-reply with possible exception
}
NOT what you’re looking for
- 10x slower than plain Actors (because reflection)
- way too easy to expose blocking APIs (oh no!)
- interface cannot express become
- too much magic
http://stackoverflow.com/questions/28516273/akka-typed-actors-in-java
Akka Typed
Akka Typed is primarily the work of Dr Roland Kuhn
Akka Typed: What’s different?
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
class Greeter extends Actor {
def receive = {
case msg: Greet 

println(s"Hello ${msg.whom}!")
sender() ! Greeted(msg.whom)
}
}
val system: ActorSystem =
ActorSystem(“akka-actor-system“)


val greeter = 

system.actorOf(Props[Greeter])
system ! Greet("kapi", system.deadLetters)
Akka Actor
Akka Typed: What’s different?
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
val greeter = Total[Greet] { msg


println(s"Hello ${msg.whom}!")
msg.replyTo ! Greeted(msg.whom)


Same
}
val system: ActorSystem[Greet] =
ActorSystem(“typed", Props(totalGreeter))
system ! Greet("kapi", system.deadLetters)
class Greeter extends Actor {
def receive = {
case msg: Greet 

println(s"Hello ${msg.whom}!")
sender() ! Greeted(msg.whom)
}
}
val system: ActorSystem =
ActorSystem(“akka-actor-system“)


val greeter = 

system.actorOf(Props[Greeter])
system ! Greet("kapi", system.deadLetters)
Akka Actor Akka Typed
Akka Typed: What’s different?
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
val greeter = Total[Greet] { msg


println(s"Hello ${msg.whom}!")
msg.replyTo ! Greeted(msg.whom)


Same
}
val system: ActorSystem[Greet] =
ActorSystem(“typed", Props(totalGreeter))
system ! Greet("kapi", system.deadLetters)
class Greeter extends Actor {
def receive = {
case msg: Greet 

println(s"Hello ${msg.whom}!")
sender() ! Greeted(msg.whom)
}
}
val system: ActorSystem =
ActorSystem(“akka-actor-system“)


val greeter = 

system.actorOf(Props[Greeter])
system ! Greet("kapi", system.deadLetters)
Akka Actor Akka Typed
The main concept is Behaviour[T]
Explicit protocols for the win!
Akka Typed: What’s different?
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
val greeter = Total[Greet] { msg


println(s"Hello ${msg.whom}!")
msg.replyTo ! Greeted(msg.whom)


Same
}
val system: ActorSystem[Greet] =
ActorSystem(“typed", Props(totalGreeter))
system ! Greet("kapi", system.deadLetters)
class Greeter extends Actor {
def receive = {
case msg: Greet 

println(s"Hello ${msg.whom}!")
sender() ! Greeted(msg.whom)
}
}
val system: ActorSystem =
ActorSystem(“akka-actor-system“)


val greeter = 

system.actorOf(Props[Greeter])
system ! Greet("kapi", system.deadLetters)
Akka Actor Akka Typed
Since Behaviour[Greet] is typed,
msg is-a Greet.
Akka Typed: What’s different?
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
val greeter = Total[Greet] { msg


println(s"Hello ${msg.whom}!")
msg.replyTo ! Greeted(msg.whom)


Same
}
val system: ActorSystem[Greet] =
ActorSystem(“typed", Props(totalGreeter))
system ! Greet("kapi", system.deadLetters)
class Greeter extends Actor {
def receive = {
case msg: Greet 

println(s"Hello ${msg.whom}!")
sender() ! Greeted(msg.whom)
}
}
val system: ActorSystem =
ActorSystem(“akka-actor-system“)


val greeter = 

system.actorOf(Props[Greeter])
system ! Greet("kapi", system.deadLetters)
Akka Actor Akka Typed
The Behaviour[T]is the receive.
Akka Typed: What’s different?
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
val greeter = Total[Greet] { msg


println(s"Hello ${msg.whom}!")
msg.replyTo ! Greeted(msg.whom)


Same
}
val system: ActorSystem[Greet] =
ActorSystem(“typed", Props(totalGreeter))
system ! Greet("kapi", system.deadLetters)
class Greeter extends Actor {
def receive = {
case msg: Greet 

println(s"Hello ${msg.whom}!")
sender() ! Greeted(msg.whom)
}
}
val system: ActorSystem =
ActorSystem(“akka-actor-system“)


val greeter = 

system.actorOf(Props[Greeter])
system ! Greet("kapi", system.deadLetters)
Akka Actor Akka Typed
sender() is no more.
Explicit protocols for the win!
Akka Typed: What’s different?
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
val greeter = Total[Greet] { msg


println(s"Hello ${msg.whom}!")
msg.replyTo ! Greeted(msg.whom)


Same
}
val system: ActorSystem[Greet] =
ActorSystem(“typed", Props(totalGreeter))
system ! Greet("kapi", system.deadLetters)
class Greeter extends Actor {
def receive = {
case msg: Greet 

println(s"Hello ${msg.whom}!")
sender() ! Greeted(msg.whom)
}
}
val system: ActorSystem =
ActorSystem(“akka-actor-system“)


val greeter = 

system.actorOf(Props[Greeter])
system ! Greet("kapi", system.deadLetters)
Akka Actor Akka Typed
sender() is no more.
Explicit protocols for the win!
final case class Greet(whom: String, replyTo: ActorRef[Greeted])
Akka Typed: What’s different?
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
val greeter = Total[Greet] { msg


println(s"Hello ${msg.whom}!")
msg.replyTo ! Greeted(msg.whom)


Same
}
val system: ActorSystem[Greet] =
ActorSystem(“typed", Props(totalGreeter))
system ! Greet("kapi", system.deadLetters)
class Greeter extends Actor {
def receive = {
case msg: Greet 

println(s"Hello ${msg.whom}!")
sender() ! Greeted(msg.whom)
}
}
val system: ActorSystem =
ActorSystem(“akka-actor-system“)


val greeter = 

system.actorOf(Props[Greeter])
system ! Greet("kapi", system.deadLetters)
Akka Actor Akka Typed
ActorRef[T] is now typed!
Akka Typed: What’s different?
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
val greeter = Total[Greet] { msg


println(s"Hello ${msg.whom}!")
msg.replyTo ! Greeted(msg.whom)


Same
}
val system: ActorSystem[Greet] =
ActorSystem(“typed", Props(totalGreeter))
system ! Greet("kapi", system.deadLetters)
class Greeter extends Actor {
def receive = {
case msg: Greet 

println(s"Hello ${msg.whom}!")
sender() ! Greeted(msg.whom)
}
}
val system: ActorSystem =
ActorSystem(“akka-actor-system“)


val greeter = 

system.actorOf(Props[Greeter])
system ! Greet("kapi", system.deadLetters)
Akka Actor Akka Typed
become()is required.
And replaced by returning the “next” Behaviour[T]
// context.become(receive)
Akka Typed: What’s different?
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
val greeter = Total[Greet] { msg


println(s"Hello ${msg.whom}!")
msg.replyTo ! Greeted(msg.whom)


Same
}
val system: ActorSystem[Greet] =
ActorSystem(“typed", Props(totalGreeter))
system ! Greet("kapi", system.deadLetters)
class Greeter extends Actor {
def receive = {
case msg: Greet 

println(s"Hello ${msg.whom}!")
sender() ! Greeted(msg.whom)
}
}
val system: ActorSystem =
ActorSystem(“akka-actor-system“)


val greeter = 

system.actorOf(Props[Greeter])
system ! Greet("kapi", system.deadLetters)
Akka Actor Akka Typed
become()is required.
And replaced by returning the “next” Behaviour[T]
On a conceptual level at least,
we provide Static[T]if you don’t need become.
// context.become(receive)
Akka Typed: What’s different?
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
val greeter = Total[Greet] { msg


println(s"Hello ${msg.whom}!")
msg.replyTo ! Greeted(msg.whom)


Same
}
val system: ActorSystem[Greet] =
ActorSystem(“typed", Props(totalGreeter))
system ! Greet("kapi", system.deadLetters)
class Greeter extends Actor {
def receive = {
case msg: Greet 

println(s"Hello ${msg.whom}!")
sender() ! Greeted(msg.whom)
}
}
val system: ActorSystem =
ActorSystem(“akka-actor-system“)


val greeter = 

system.actorOf(Props[Greeter])
system ! Greet("kapi", system.deadLetters)
Akka Actor Akka Typed
become()is required.
And replaced by returning the “next” Behaviour[T]
Special behaviors:
Same / Unhandled / Empty / Stopped / Ignore
// context.become(receive)
Akka Typed: What’s different?
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
val greeter = Total[Greet] { msg


println(s"Hello ${msg.whom}!")
msg.replyTo ! Greeted(msg.whom)


Same
}
val system: ActorSystem[Greet] =
ActorSystem(“typed", Props(totalGreeter))
system ! Greet("kapi", system.deadLetters)
class Greeter extends Actor {
def receive = {
case msg: Greet 

println(s"Hello ${msg.whom}!")
sender() ! Greeted(msg.whom)
}
}
val system: ActorSystem =
ActorSystem(“akka-actor-system“)


val greeter = 

system.actorOf(Props[Greeter])
system ! Greet("kapi", system.deadLetters)
Akka Actor Akka Typed
“Root actor” is not user-defined for ActorSystem[T]
Encourages thinking about supervision.
Akka Typed: Behaviors
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
Static[T] - if become not needed
Total[T] - behavior is total function
Partial[T] - behavior is partial function
Full[T] - when interested in system signals
FullTotal[T] or ActorContext
Akka Typed: Behaviors
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
object HelloWorld {
final case class Greet(whom: String, replyTo: ActorRef[Greeted])
final case class Greeted(whom: String)
val greeter = Static[Greet] { msg 

println(s"Hello ${msg.whom}!")
msg.replyTo ! Greeted(msg.whom)
}
}
Static[T] - if become not needed
Total[T] - behavior is total function
Partial[T] - behavior is partial function
Full[T] - when interested in system signals
FullTotal[T] or ActorContext
Akka Typed: Behaviors
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
Static[T] - if become not needed
Total[T] - behavior is total function
Partial[T] - behavior is partial function
Full[T] - when interested in system signals
FullTotal[T] or ActorContext
val master = Full[WorkProtocol] {
case Msg(ctx, w: Work)
ctx.spawn(Props(worker), s"worker-${w.id}") ! w


// ...
}
Akka Typed: Behavior Combinators
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
Combine behaviors:
final case class And[T](left: Behavior[T], right: Behavior[T])
extends Behavior[T] { /* … */ }
final case class Or[T](left: Behavior[T], right: Behavior[T])
extends Behavior[T] { /* … */ }
Smarter “left orElse right”
Akka Typed: narrow / widen
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
def narrow[U <: T]: Behavior[U]
def widen[U >: T](matcher: PartialFunction[U, T]): Behavior[U]
Narrowing a Behavior is always safe
Widening requires help in form of a matcher:
Akka Typed
http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html
More types!
Root Actor is user-defined
sender() is gone
Lifecycle hooks are now system messages
Awesome possibilities to combine Behaviours
Early work-in-progress preview in 2.4.x
(Currently emulated on top of Akka-Actor)
Akka Typed
Reactive Streams
Reactive Streams
Akka Streams
Reactive Streams
http://www.reactive-streams.org/
Reactive Streams
Reactive Streams - Who?
http://reactive-streams.org
Kaazing Corp.
RxJava @ Netflix,
Reactor @ Pivotal (SpringSource),
Vert.x @ Red Hat,
Twitter,
Akka Streams, Slick @ Typesafe,
Spray @ Spray.io,
Oracle,
OpenJDK (?) – Doug Lea - SUNY Oswego
…
What is back-pressure?
Back-pressure?
Back-pressure? WAT!
Back-pressure? WAT!
What if the buffer overflows?
Back-pressure? Push + Drop + Resend (a)
Use bounded buffer,
drop messages + require re-sending
Back-pressure? Push + Drop + Resend (a)
Kernel does this!
Routers do this!
(TCP)
Use bounded buffer,
drop messages + require re-sending
Back-pressure? Unbounded queues != solution (b)
Increase buffer size…
Well, while you have memory available!
Back-pressure? Unbounded queues != solution (b)
Back-pressure?
Reactive-Streams
=
“Dynamic Push/Pull”
Just push – not safe when Slow Subscriber
Just pull – too slow when Fast Subscriber
Back-pressure? RS: Dynamic Push/Pull
Solution:
Dynamic adjustment
Back-pressure? RS: Dynamic Push/Pull
Just push – not safe when Slow Subscriber
Just pull – too slow when Fast Subscriber
Back-pressure? RS: Dynamic Push/Pull
Slow Subscriber sees it’s buffer can take 3 elements.
Publisher will never blow up it’s buffer.
Back-pressure? RS: Dynamic Push/Pull
Fast Publisher will send at-most 3 elements.
This is pull-based-backpressure.
Back-pressure? RS: Dynamic Push/Pull
Fast Subscriber can issue more Request(n),
before more data arrives!
Back-pressure? RS: Dynamic Push/Pull
Fast Subscriber can issue more Request(n),
before more data arrives.
Publisher can accumulate demand.
Back-pressure? RS: Accumulate demand
Publisher accumulates total demand per subscriber.
Back-pressure? RS: Accumulate demand
Total demand of elements is safe to publish.
Subscriber’s buffer will not overflow.
Back-pressure? RS: Requesting “a lot”
Fast Subscriber can issue arbitrary large requests,
including “gimme all you got” (Long.MaxValue)
Back-pressure? RS: Dynamic Push/Pull
MAX
speed
Back-pressure? RS: Dynamic Push/Pull
Easy
MAX
speed
Back-pressure
File upload demo with Akka HTTP
Akka Streams – Linear Flow
Akka Streams – Linear Flow
Akka Streams – Linear Flow
Akka Streams – Linear Flow
Akka Streams – Linear Flow
Flow[Double].map(_.toInt). [...]
No Source attached yet.
“Pipe ready to work with Doubles”.
Akka Streams – Linear Flow
implicit val sys = ActorSystem("scalar-sys")
implicit val mat = ActorFlowMaterializer()
Source(1 to 3).runWith(Sink.foreach(println))
Akka Streams – Linear Flow
implicit val sys = ActorSystem("scalar-sys")
implicit val mat = ActorFlowMaterializer()
Source(1 to 3).runWith(Sink.foreach(println))
// sugar for runWith
Source(1 to 3).foreach(println)
Akka Streams – Linear Flow
implicit val sys = ActorSystem("scalar-sys")
implicit val mat = ActorFlowMaterializer()
Source(1 to 3).runWith(Sink.foreach(println))
// sugar for runWith
Source(1 to 3).foreach(println)
Sink.fold
Sink.head
Sink.ignore
Sink.publisher
Sink.cancelled
// your own Sink
…
Akka Streams <-> Actors – Advanced
val subscriber = ActorSubscriber(
system.actorOf(Props[SubStreamParent], ”parent”)
)
Source(1 to 100)
.map(_.toString)
.filter(_.length == 2)
.drop(2)
.conflate(seed => seed)((acc, i) => acc + i)
.groupBy(_.last)
.runWith(subscriber)
All the usual ops available for Linear Flows.
Akka Streams <-> Actors – Advanced
val subscriber = ActorSubscriber(
system.actorOf(Props[SubStreamParent], ”parent”)
)
Source(1 to 100)
.map(_.toString)
.filter(_.length == 2)
.drop(2)
.conflate(seed => seed)((acc, i) => acc + i)
.groupBy(_.last)
.runWith(subscriber)
Aggregating values until downstream demand comes.
Akka Streams <-> Actors – Advanced
val subscriber = ActorSubscriber(
system.actorOf(Props[SubStreamParent], ”parent”)
)
Source(1 to 100)
.map(_.toString)
.filter(_.length == 2)
.drop(2)
.conflate(seed => seed)((acc, i) => acc + i)
.groupBy(_.last)
.runWith(subscriber)
Creates a stream of streams:
Source[Source[String]]
Akka Streams: Graphs
val p: Publisher[String] =
FlowGraph.closed(out) { implicit b o
val merge = b.add(new StrictRoundRobin[String])

in1 ~> merge.in(0)
in2 ~> merge.in(1)


merge.out ~> o.inlet
}.run()
val in1 = Source(List("a", "b", "c", "d"))
val in2 = Source(List("e", "f"))
val out = Sink.publisher[String]
Akka Streams: Graphs
val p: Publisher[String] =
FlowGraph.closed(out) { implicit b o
val merge = b.add(new StrictRoundRobin[String])

in1 ~> merge.in(0)
in2 ~> merge.in(1)


merge.out ~> o.inlet
}.run()
val in1 = Source(List("a", "b", "c", "d"))
val in2 = Source(List("e", "f"))
val out = Sink.publisher[String]
Sink[String, Publisher[String]]
imports Graphs
Akka Streams: Graphs
val p: Publisher[String] =
FlowGraph.closed(out) { implicit b o
val merge = b.add(new StrictRoundRobin[String])

in1 ~> merge.in(0)
in2 ~> merge.in(1)


merge.out ~> o.inlet
}.run()
val in1 = Source(List("a", "b", "c", "d"))
val in2 = Source(List("e", "f"))
val out = Sink.publisher[String]
Sink[String, Publisher[String]]
materializes a Publisher[String]
Akka Streams: Partial Graphs
FlowGraph.partial() { implicit b
import FlowGraph.Implicits._
val priorityMerge = b.add(MergePreferred[In](1))
val balance = b.add(Balance[In](workerCount))
val resultsMerge = b.add(Merge[Out](workerCount))
// After merging priority and ordinary jobs, we feed them to the balancer
priorityMerge ~> balance
// Wire up each of the outputs of the balancer to a worker flow
// then merge them back
for (i <- 0 until workerCount)
balance.out(i) ~> worker ~> resultsMerge.in(i)
// We now expose the input ports of the priorityMerge and the output
// of the resultsMerge as our PriorityWorkerPool ports
// -- all neatly wrapped in our domain specific Shape
PriorityWorkerPoolShape(
jobsIn = priorityMerge.in(0),
priorityJobsIn = priorityMerge.preferred,
resultsOut = resultsMerge.out)
}
Akka Streams: Partial Graphs
FlowGraph.partial() { implicit b
import FlowGraph.Implicits._
val priorityMerge = b.add(MergePreferred[In](1))
val balance = b.add(Balance[In](workerCount))
val resultsMerge = b.add(Merge[Out](workerCount))
// After merging priority and ordinary jobs, we feed them to the balancer
priorityMerge ~> balance
// Wire up each of the outputs of the balancer to a worker flow
// then merge them back
for (i <- 0 until workerCount)
balance.out(i) ~> worker ~> resultsMerge.in(i)
// We now expose the input ports of the priorityMerge and the output
// of the resultsMerge as our PriorityWorkerPool ports
// -- all neatly wrapped in our domain specific Shape
PriorityWorkerPoolShape(
jobsIn = priorityMerge.in(0),
priorityJobsIn = priorityMerge.preferred,
resultsOut = resultsMerge.out)
}
Akka Streams: Partial Graphs
FlowGraph.partial() { implicit b
import FlowGraph.Implicits._
val priorityMerge = b.add(MergePreferred[In](1))
val balance = b.add(Balance[In](workerCount))
val resultsMerge = b.add(Merge[Out](workerCount))
// After merging priority and ordinary jobs, we feed them to the balancer
priorityMerge ~> balance
// Wire up each of the outputs of the balancer to a worker flow
// then merge them back
for (i <- 0 until workerCount)
balance.out(i) ~> worker ~> resultsMerge.in(i)
// We now expose the input ports of the priorityMerge and the output
// of the resultsMerge as our PriorityWorkerPool ports
// -- all neatly wrapped in our domain specific Shape
PriorityWorkerPoolShape(
jobsIn = priorityMerge.in(0),
priorityJobsIn = priorityMerge.preferred,
resultsOut = resultsMerge.out)
}
case class PriorityWorkerPoolShape[In, Out](
jobsIn: Inlet[In],
priorityJobsIn: Inlet[In],
resultsOut: Outlet[Out]) extends Shape { // …
Akka Streams: Partial Graphs
val worker1 = Flow[String].map("step 1 " + _)
val worker2 = Flow[String].map("step 2 " + _)
FlowGraph.closed() { implicit b =>
import FlowGraph.Implicits._
val priorityPool1 = b.add(PriorityWorkerPool(worker1, 4))
val priorityPool2 = b.add(PriorityWorkerPool(worker2, 2))
Source(1 to 100).map("job: " + _) ~> priorityPool1.jobsIn
Source(1 to 100).map("priority job: " + _) ~> priorityPool1.priorityJobsIn
priorityPool1.resultsOut ~> priorityPool2.jobsIn
Source(1 to 100).map("one-step, priority " + _) ~> priorityPool2.priorityJobsIn
priorityPool2.resultsOut ~> Sink.foreach(println)
}.run()
Akka Streams: Partial Graphs
val worker1 = Flow[String].map("step 1 " + _)
val worker2 = Flow[String].map("step 2 " + _)
FlowGraph.closed() { implicit b =>
import FlowGraph.Implicits._
val priorityPool1 = b.add(PriorityWorkerPool(worker1, 4))
val priorityPool2 = b.add(PriorityWorkerPool(worker2, 2))
Source(1 to 100).map("job: " + _) ~> priorityPool1.jobsIn
Source(1 to 100).map("priority job: " + _) ~> priorityPool1.priorityJobsIn
priorityPool1.resultsOut ~> priorityPool2.jobsIn
Source(1 to 100).map("one-step, priority " + _) ~> priorityPool2.priorityJobsIn
priorityPool2.resultsOut ~> Sink.foreach(println)
}.run()
Real life example: Akka Http OutgoingConnection
requestIn +----------+
+-----------------------------------------------+--->| Termi- | requestRendering
| | nation +---------------------> |
+-------------------------------------->| Merge | |
| Termination Backchannel | +----------+ | TCP-
| | | level
| | Method | client
| +------------+ | Bypass | flow
responseOut | responsePrep | Response |<---+ |
<------------+----------------| Parsing | |
| Merge |<------------------------------------------ V
+------------+
akka.http.engine.client.OutgoingConnectionBlueprint.scala#L47
Reactive Streams
Bigger than Scala-ecosystem - JDK-wide (and wider).
Inter-operable back-pressure protocol.
Future work: reactive-streams-io, reactive-streams-js
Akka Streams - one of the leading Reactive Streams impls.
Complex in-memory stream processing.
Akka Http - Akka Streams based, the “Spray 2.0”
Wrapping up
Wrapping up
The future is typed!
More typesafety / perf / features coming in future releases.
It’s not “just typesafety”,
it’s profoundly better ways to model things.
Static stream processing graph layouts =
more constraints => better ways to optimise.
Timing
ALL DATES ARE SUBJECT TO CHANGE.
It’s done “when it’s done.”
Timing
Reactive Streams - 1.0-RC5 yesterday, 1.0 in “weeks”
Akka Streams – 1.0-RC1 in around 2 weeks
Akka Http – 1.0-M6 in around 2 weeks
Akka Typed – merged as draft + experimental in Akka 2.4.x
Akka Persistence – new “read side” will use Akka Streams
ALL DATES ARE SUBJECT TO CHANGE.
It’s done “when it’s done.”
ktoso @ typesafe.com
twitter: ktosopl
github: ktoso
team blog: letitcrash.com
home: akka.io
Thanks! / Questions?
©Typesafe 2015 – All Rights Reserved

More Related Content

What's hot

State of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to comeState of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to comeKonrad Malawski
 
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsJohan Andrén
 
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYCBuilding a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYCKonrad Malawski
 
HBase RowKey design for Akka Persistence
HBase RowKey design for Akka PersistenceHBase RowKey design for Akka Persistence
HBase RowKey design for Akka PersistenceKonrad Malawski
 
Streaming all the things with akka streams
Streaming all the things with akka streams   Streaming all the things with akka streams
Streaming all the things with akka streams Johan Andrén
 
Reactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayReactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayRoland Kuhn
 
Distributed Consensus A.K.A. "What do we eat for lunch?"
Distributed Consensus A.K.A. "What do we eat for lunch?"Distributed Consensus A.K.A. "What do we eat for lunch?"
Distributed Consensus A.K.A. "What do we eat for lunch?"Konrad Malawski
 
Building reactive distributed systems with Akka
Building reactive distributed systems with Akka Building reactive distributed systems with Akka
Building reactive distributed systems with Akka Johan Andrén
 
End to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to SocketEnd to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to SocketKonrad Malawski
 
Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016Konrad Malawski
 
Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!Konrad Malawski
 
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in'tScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in'tKonrad Malawski
 
Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Johan Andrén
 
Akka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldAkka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldKonrad Malawski
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneKonrad Malawski
 
Not Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsNot Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsKonrad Malawski
 
Journey into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka StreamsJourney into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka StreamsKevin Webber
 
A dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioA dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioGioia Ballin
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaKonrad Malawski
 
DDDing Tools = Akka Persistence
DDDing Tools = Akka PersistenceDDDing Tools = Akka Persistence
DDDing Tools = Akka PersistenceKonrad Malawski
 

What's hot (20)

State of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to comeState of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to come
 
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka Streams
 
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYCBuilding a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
 
HBase RowKey design for Akka Persistence
HBase RowKey design for Akka PersistenceHBase RowKey design for Akka Persistence
HBase RowKey design for Akka Persistence
 
Streaming all the things with akka streams
Streaming all the things with akka streams   Streaming all the things with akka streams
Streaming all the things with akka streams
 
Reactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayReactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive Way
 
Distributed Consensus A.K.A. "What do we eat for lunch?"
Distributed Consensus A.K.A. "What do we eat for lunch?"Distributed Consensus A.K.A. "What do we eat for lunch?"
Distributed Consensus A.K.A. "What do we eat for lunch?"
 
Building reactive distributed systems with Akka
Building reactive distributed systems with Akka Building reactive distributed systems with Akka
Building reactive distributed systems with Akka
 
End to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to SocketEnd to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to Socket
 
Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016
 
Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!
 
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in'tScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
 
Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Reactive stream processing using Akka streams
Reactive stream processing using Akka streams
 
Akka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldAkka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming World
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOne
 
Not Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsNot Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabs
 
Journey into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka StreamsJourney into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka Streams
 
A dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioA dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenario
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and Akka
 
DDDing Tools = Akka Persistence
DDDing Tools = Akka PersistenceDDDing Tools = Akka Persistence
DDDing Tools = Akka Persistence
 

Viewers also liked

100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRKKonrad Malawski
 
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...Konrad Malawski
 
Krakow communities @ 2016
Krakow communities @ 2016Krakow communities @ 2016
Krakow communities @ 2016Konrad Malawski
 
Android my Scala @ JFokus 2013
Android my Scala @ JFokus 2013Android my Scala @ JFokus 2013
Android my Scala @ JFokus 2013Konrad Malawski
 
How Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemHow Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemKonrad Malawski
 
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesAkka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesKonrad Malawski
 
Functor, Apply, Applicative And Monad
Functor, Apply, Applicative And MonadFunctor, Apply, Applicative And Monad
Functor, Apply, Applicative And MonadOliver Daff
 
The dark side of Akka and the remedy
The dark side of Akka and the remedyThe dark side of Akka and the remedy
The dark side of Akka and the remedykrivachy
 
Akka Futures and Akka Remoting
Akka Futures  and Akka RemotingAkka Futures  and Akka Remoting
Akka Futures and Akka RemotingKnoldus Inc.
 
The dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetupThe dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetupkrivachy
 
Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)Kfir Bloch
 
Scala Implicits - Not to be feared
Scala Implicits - Not to be fearedScala Implicits - Not to be feared
Scala Implicits - Not to be fearedDerek Wyatt
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsKonrad Malawski
 
Open soucerers - jak zacząć swoją przygodę z open source
Open soucerers - jak zacząć swoją przygodę z open sourceOpen soucerers - jak zacząć swoją przygodę z open source
Open soucerers - jak zacząć swoją przygodę z open sourceKonrad Malawski
 

Viewers also liked (14)

100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
 
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
 
Krakow communities @ 2016
Krakow communities @ 2016Krakow communities @ 2016
Krakow communities @ 2016
 
Android my Scala @ JFokus 2013
Android my Scala @ JFokus 2013Android my Scala @ JFokus 2013
Android my Scala @ JFokus 2013
 
How Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemHow Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM Ecosystem
 
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesAkka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutes
 
Functor, Apply, Applicative And Monad
Functor, Apply, Applicative And MonadFunctor, Apply, Applicative And Monad
Functor, Apply, Applicative And Monad
 
The dark side of Akka and the remedy
The dark side of Akka and the remedyThe dark side of Akka and the remedy
The dark side of Akka and the remedy
 
Akka Futures and Akka Remoting
Akka Futures  and Akka RemotingAkka Futures  and Akka Remoting
Akka Futures and Akka Remoting
 
The dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetupThe dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetup
 
Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)
 
Scala Implicits - Not to be feared
Scala Implicits - Not to be fearedScala Implicits - Not to be feared
Scala Implicits - Not to be feared
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
 
Open soucerers - jak zacząć swoją przygodę z open source
Open soucerers - jak zacząć swoją przygodę z open sourceOpen soucerers - jak zacząć swoją przygodę z open source
Open soucerers - jak zacząć swoją przygodę z open source
 

Similar to Konrad 'ktoso' Malawski GeeCON 2014 @ Kraków, PL Fresh from the Oven - akka gets Typed

A gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor modelA gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor modelMykhailo Kotsur
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)Pavlo Baron
 
Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)tarcieri
 
Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#Riccardo Terrell
 
Intro to scala
Intro to scalaIntro to scala
Intro to scalaJoe Zulli
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?Sarah Mount
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanJimin Hsieh
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVMVaclav Pech
 
Akka and the Zen of Reactive System Design
Akka and the Zen of Reactive System DesignAkka and the Zen of Reactive System Design
Akka and the Zen of Reactive System DesignLightbend
 
scala reloaded
scala reloadedscala reloaded
scala reloadedMac Liaw
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the ASTJarrod Overson
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.jsWebsecurify
 
Scala / Technology evolution
Scala  / Technology evolutionScala  / Technology evolution
Scala / Technology evolutionRuslan Shevchenko
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring frameworkSunghyouk Bae
 
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018 Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018 Codemotion
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 

Similar to Konrad 'ktoso' Malawski GeeCON 2014 @ Kraków, PL Fresh from the Oven - akka gets Typed (20)

A gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor modelA gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor model
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)
 
Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf Taiwan
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Akka and the Zen of Reactive System Design
Akka and the Zen of Reactive System DesignAkka and the Zen of Reactive System Design
Akka and the Zen of Reactive System Design
 
Fantom and Tales
Fantom and TalesFantom and Tales
Fantom and Tales
 
scala reloaded
scala reloadedscala reloaded
scala reloaded
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
 
Scala / Technology evolution
Scala  / Technology evolutionScala  / Technology evolution
Scala / Technology evolution
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring framework
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Akka introtalk HyScala DEC 2016
Akka introtalk HyScala DEC 2016Akka introtalk HyScala DEC 2016
Akka introtalk HyScala DEC 2016
 
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018 Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 

Recently uploaded

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 

Konrad 'ktoso' Malawski GeeCON 2014 @ Kraków, PL Fresh from the Oven - akka gets Typed

  • 1. Konrad 'ktoso' Malawski GeeCON 2014 @ Kraków, PL Konrad `@ktosopl` Malawski Fresh from the Oven - akka
  • 2. Konrad 'ktoso' Malawski GeeCON 2014 @ Kraków, PL Konrad `@ktosopl` Malawski Fresh from the Oven - akka gets Typed
  • 3. Konrad `ktoso` Malawski Akka Team, Reactive Streams TCK
  • 4. Konrad `@ktosopl` Malawski akka.io typesafe.com geecon.org Java.pl / KrakowScala.pl sckrk.com / meetup.com/Paper-Cup @ London GDGKrakow.pl lambdakrk.pl
  • 5. Nice to meet you! Who are you guys?
  • 6. Disclaimer Modules discussed in this talk are pre-experimental or not even released yet. Also known as “don’t use in production”, “please give us feedback”, “docs are work in progress” etc. Everything shown is experimental! The cake is a lie!
  • 7. Agenda • What Akka is at it’s heart • Old Typed Actors + some background • Akka Typed • Akka Streams / Reactive Streams • Wrapping up experimental experimental not released yet
  • 10. The Actor Model The Actor Model as defined by Hewitt, Bishop and Steiger in 1973 is a computational model that expresses exactly what it means for computation to be distributed. Actors can only communicate by exchanging messages. Upon reception of a message an Actor can do the following three fundamental actions: • send a finite number of messages to Actors it knows • create a finite number of new Actors • designate the behavior to be applied to the next message
  • 11. Why Untyped? Inspired by Erlang, that’s untyped as well. Modelling “become” is non obvious: “what about races in sending msgs which change state?” Networking is untyped - sorry. Pattern matching makes extracting types simple. Several failed attempts (incl. in Erlang) (Yes, we know session types).
  • 13. Akka Typed NOT the Old Typed Actors module
  • 14. Akka Typed NOT the Old Typed Actors module
  • 15. Old Typed Actors Were never intended to be a core abstraction. Just a “bridge from Java-land to Actor-land”. A note on Distributed Computing by Jim Waldo et al.
  • 16. Old Typed Actors Were never intended to be a core abstraction. Just a “bridge from Java-land to Actor-land”. trait Squarer { def squareDontCare(i: Int): Unit //fire-forget def square(i: Int): Future[Int] //non-blocking send-request-reply def squareNowPlease(i: Int): Option[Int] //blocking send-request-reply def squareNow(i: Int): Int //blocking send-request-reply @throws(classOf[Exception]) //declare it or you will get an UndeclaredThrowableException def squareTry(i: Int): Int //blocking send-request-reply with possible exception } A note on Distributed Computing by Jim Waldo et al.
  • 17. Old Typed Actors Were never intended to be a core abstraction. Just a “bridge from Java-land to Actor-land”. trait Squarer { def squareDontCare(i: Int): Unit //fire-forget def square(i: Int): Future[Int] //non-blocking send-request-reply def squareNowPlease(i: Int): Option[Int] //blocking send-request-reply def squareNow(i: Int): Int //blocking send-request-reply @throws(classOf[Exception]) //declare it or you will get an UndeclaredThrowableException def squareTry(i: Int): Int //blocking send-request-reply with possible exception } NOT what you’re looking for A note on Distributed Computing by Jim Waldo et al.
  • 18. The old “Typed Actors” trait Squarer { def squareDontCare(i: Int): Unit //fire-forget def square(i: Int): Future[Int] //non-blocking send-request-reply def squareNowPlease(i: Int): Option[Int] //blocking send-request-reply def squareNow(i: Int): Int //blocking send-request-reply @throws(classOf[Exception]) //declare it or you will get an UndeclaredThrowableException def squareTry(i: Int): Int //blocking send-request-reply with possible exception } NOT what you’re looking for - 10x slower than plain Actors (because reflection) - way too easy to expose blocking APIs (oh no!) - interface cannot express become - too much magic http://stackoverflow.com/questions/28516273/akka-typed-actors-in-java
  • 19. Akka Typed Akka Typed is primarily the work of Dr Roland Kuhn
  • 20. Akka Typed: What’s different? http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html class Greeter extends Actor { def receive = { case msg: Greet 
 println(s"Hello ${msg.whom}!") sender() ! Greeted(msg.whom) } } val system: ActorSystem = ActorSystem(“akka-actor-system“) 
 val greeter = 
 system.actorOf(Props[Greeter]) system ! Greet("kapi", system.deadLetters) Akka Actor
  • 21. Akka Typed: What’s different? http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html val greeter = Total[Greet] { msg 
 println(s"Hello ${msg.whom}!") msg.replyTo ! Greeted(msg.whom) 
 Same } val system: ActorSystem[Greet] = ActorSystem(“typed", Props(totalGreeter)) system ! Greet("kapi", system.deadLetters) class Greeter extends Actor { def receive = { case msg: Greet 
 println(s"Hello ${msg.whom}!") sender() ! Greeted(msg.whom) } } val system: ActorSystem = ActorSystem(“akka-actor-system“) 
 val greeter = 
 system.actorOf(Props[Greeter]) system ! Greet("kapi", system.deadLetters) Akka Actor Akka Typed
  • 22. Akka Typed: What’s different? http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html val greeter = Total[Greet] { msg 
 println(s"Hello ${msg.whom}!") msg.replyTo ! Greeted(msg.whom) 
 Same } val system: ActorSystem[Greet] = ActorSystem(“typed", Props(totalGreeter)) system ! Greet("kapi", system.deadLetters) class Greeter extends Actor { def receive = { case msg: Greet 
 println(s"Hello ${msg.whom}!") sender() ! Greeted(msg.whom) } } val system: ActorSystem = ActorSystem(“akka-actor-system“) 
 val greeter = 
 system.actorOf(Props[Greeter]) system ! Greet("kapi", system.deadLetters) Akka Actor Akka Typed The main concept is Behaviour[T] Explicit protocols for the win!
  • 23. Akka Typed: What’s different? http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html val greeter = Total[Greet] { msg 
 println(s"Hello ${msg.whom}!") msg.replyTo ! Greeted(msg.whom) 
 Same } val system: ActorSystem[Greet] = ActorSystem(“typed", Props(totalGreeter)) system ! Greet("kapi", system.deadLetters) class Greeter extends Actor { def receive = { case msg: Greet 
 println(s"Hello ${msg.whom}!") sender() ! Greeted(msg.whom) } } val system: ActorSystem = ActorSystem(“akka-actor-system“) 
 val greeter = 
 system.actorOf(Props[Greeter]) system ! Greet("kapi", system.deadLetters) Akka Actor Akka Typed Since Behaviour[Greet] is typed, msg is-a Greet.
  • 24. Akka Typed: What’s different? http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html val greeter = Total[Greet] { msg 
 println(s"Hello ${msg.whom}!") msg.replyTo ! Greeted(msg.whom) 
 Same } val system: ActorSystem[Greet] = ActorSystem(“typed", Props(totalGreeter)) system ! Greet("kapi", system.deadLetters) class Greeter extends Actor { def receive = { case msg: Greet 
 println(s"Hello ${msg.whom}!") sender() ! Greeted(msg.whom) } } val system: ActorSystem = ActorSystem(“akka-actor-system“) 
 val greeter = 
 system.actorOf(Props[Greeter]) system ! Greet("kapi", system.deadLetters) Akka Actor Akka Typed The Behaviour[T]is the receive.
  • 25. Akka Typed: What’s different? http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html val greeter = Total[Greet] { msg 
 println(s"Hello ${msg.whom}!") msg.replyTo ! Greeted(msg.whom) 
 Same } val system: ActorSystem[Greet] = ActorSystem(“typed", Props(totalGreeter)) system ! Greet("kapi", system.deadLetters) class Greeter extends Actor { def receive = { case msg: Greet 
 println(s"Hello ${msg.whom}!") sender() ! Greeted(msg.whom) } } val system: ActorSystem = ActorSystem(“akka-actor-system“) 
 val greeter = 
 system.actorOf(Props[Greeter]) system ! Greet("kapi", system.deadLetters) Akka Actor Akka Typed sender() is no more. Explicit protocols for the win!
  • 26. Akka Typed: What’s different? http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html val greeter = Total[Greet] { msg 
 println(s"Hello ${msg.whom}!") msg.replyTo ! Greeted(msg.whom) 
 Same } val system: ActorSystem[Greet] = ActorSystem(“typed", Props(totalGreeter)) system ! Greet("kapi", system.deadLetters) class Greeter extends Actor { def receive = { case msg: Greet 
 println(s"Hello ${msg.whom}!") sender() ! Greeted(msg.whom) } } val system: ActorSystem = ActorSystem(“akka-actor-system“) 
 val greeter = 
 system.actorOf(Props[Greeter]) system ! Greet("kapi", system.deadLetters) Akka Actor Akka Typed sender() is no more. Explicit protocols for the win! final case class Greet(whom: String, replyTo: ActorRef[Greeted])
  • 27. Akka Typed: What’s different? http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html val greeter = Total[Greet] { msg 
 println(s"Hello ${msg.whom}!") msg.replyTo ! Greeted(msg.whom) 
 Same } val system: ActorSystem[Greet] = ActorSystem(“typed", Props(totalGreeter)) system ! Greet("kapi", system.deadLetters) class Greeter extends Actor { def receive = { case msg: Greet 
 println(s"Hello ${msg.whom}!") sender() ! Greeted(msg.whom) } } val system: ActorSystem = ActorSystem(“akka-actor-system“) 
 val greeter = 
 system.actorOf(Props[Greeter]) system ! Greet("kapi", system.deadLetters) Akka Actor Akka Typed ActorRef[T] is now typed!
  • 28. Akka Typed: What’s different? http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html val greeter = Total[Greet] { msg 
 println(s"Hello ${msg.whom}!") msg.replyTo ! Greeted(msg.whom) 
 Same } val system: ActorSystem[Greet] = ActorSystem(“typed", Props(totalGreeter)) system ! Greet("kapi", system.deadLetters) class Greeter extends Actor { def receive = { case msg: Greet 
 println(s"Hello ${msg.whom}!") sender() ! Greeted(msg.whom) } } val system: ActorSystem = ActorSystem(“akka-actor-system“) 
 val greeter = 
 system.actorOf(Props[Greeter]) system ! Greet("kapi", system.deadLetters) Akka Actor Akka Typed become()is required. And replaced by returning the “next” Behaviour[T] // context.become(receive)
  • 29. Akka Typed: What’s different? http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html val greeter = Total[Greet] { msg 
 println(s"Hello ${msg.whom}!") msg.replyTo ! Greeted(msg.whom) 
 Same } val system: ActorSystem[Greet] = ActorSystem(“typed", Props(totalGreeter)) system ! Greet("kapi", system.deadLetters) class Greeter extends Actor { def receive = { case msg: Greet 
 println(s"Hello ${msg.whom}!") sender() ! Greeted(msg.whom) } } val system: ActorSystem = ActorSystem(“akka-actor-system“) 
 val greeter = 
 system.actorOf(Props[Greeter]) system ! Greet("kapi", system.deadLetters) Akka Actor Akka Typed become()is required. And replaced by returning the “next” Behaviour[T] On a conceptual level at least, we provide Static[T]if you don’t need become. // context.become(receive)
  • 30. Akka Typed: What’s different? http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html val greeter = Total[Greet] { msg 
 println(s"Hello ${msg.whom}!") msg.replyTo ! Greeted(msg.whom) 
 Same } val system: ActorSystem[Greet] = ActorSystem(“typed", Props(totalGreeter)) system ! Greet("kapi", system.deadLetters) class Greeter extends Actor { def receive = { case msg: Greet 
 println(s"Hello ${msg.whom}!") sender() ! Greeted(msg.whom) } } val system: ActorSystem = ActorSystem(“akka-actor-system“) 
 val greeter = 
 system.actorOf(Props[Greeter]) system ! Greet("kapi", system.deadLetters) Akka Actor Akka Typed become()is required. And replaced by returning the “next” Behaviour[T] Special behaviors: Same / Unhandled / Empty / Stopped / Ignore // context.become(receive)
  • 31. Akka Typed: What’s different? http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html val greeter = Total[Greet] { msg 
 println(s"Hello ${msg.whom}!") msg.replyTo ! Greeted(msg.whom) 
 Same } val system: ActorSystem[Greet] = ActorSystem(“typed", Props(totalGreeter)) system ! Greet("kapi", system.deadLetters) class Greeter extends Actor { def receive = { case msg: Greet 
 println(s"Hello ${msg.whom}!") sender() ! Greeted(msg.whom) } } val system: ActorSystem = ActorSystem(“akka-actor-system“) 
 val greeter = 
 system.actorOf(Props[Greeter]) system ! Greet("kapi", system.deadLetters) Akka Actor Akka Typed “Root actor” is not user-defined for ActorSystem[T] Encourages thinking about supervision.
  • 32. Akka Typed: Behaviors http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html Static[T] - if become not needed Total[T] - behavior is total function Partial[T] - behavior is partial function Full[T] - when interested in system signals FullTotal[T] or ActorContext
  • 33. Akka Typed: Behaviors http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html object HelloWorld { final case class Greet(whom: String, replyTo: ActorRef[Greeted]) final case class Greeted(whom: String) val greeter = Static[Greet] { msg 
 println(s"Hello ${msg.whom}!") msg.replyTo ! Greeted(msg.whom) } } Static[T] - if become not needed Total[T] - behavior is total function Partial[T] - behavior is partial function Full[T] - when interested in system signals FullTotal[T] or ActorContext
  • 34. Akka Typed: Behaviors http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html Static[T] - if become not needed Total[T] - behavior is total function Partial[T] - behavior is partial function Full[T] - when interested in system signals FullTotal[T] or ActorContext val master = Full[WorkProtocol] { case Msg(ctx, w: Work) ctx.spawn(Props(worker), s"worker-${w.id}") ! w 
 // ... }
  • 35. Akka Typed: Behavior Combinators http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html Combine behaviors: final case class And[T](left: Behavior[T], right: Behavior[T]) extends Behavior[T] { /* … */ } final case class Or[T](left: Behavior[T], right: Behavior[T]) extends Behavior[T] { /* … */ } Smarter “left orElse right”
  • 36. Akka Typed: narrow / widen http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html def narrow[U <: T]: Behavior[U] def widen[U >: T](matcher: PartialFunction[U, T]): Behavior[U] Narrowing a Behavior is always safe Widening requires help in form of a matcher:
  • 37. Akka Typed http://doc.akka.io/docs/akka/snapshot/scala/typed-actors.html More types! Root Actor is user-defined sender() is gone Lifecycle hooks are now system messages Awesome possibilities to combine Behaviours Early work-in-progress preview in 2.4.x (Currently emulated on top of Akka-Actor)
  • 43. Reactive Streams - Who? http://reactive-streams.org Kaazing Corp. RxJava @ Netflix, Reactor @ Pivotal (SpringSource), Vert.x @ Red Hat, Twitter, Akka Streams, Slick @ Typesafe, Spray @ Spray.io, Oracle, OpenJDK (?) – Doug Lea - SUNY Oswego …
  • 47. Back-pressure? WAT! What if the buffer overflows?
  • 48. Back-pressure? Push + Drop + Resend (a) Use bounded buffer, drop messages + require re-sending
  • 49. Back-pressure? Push + Drop + Resend (a) Kernel does this! Routers do this! (TCP) Use bounded buffer, drop messages + require re-sending
  • 50. Back-pressure? Unbounded queues != solution (b) Increase buffer size… Well, while you have memory available!
  • 53. Just push – not safe when Slow Subscriber Just pull – too slow when Fast Subscriber Back-pressure? RS: Dynamic Push/Pull
  • 54. Solution: Dynamic adjustment Back-pressure? RS: Dynamic Push/Pull Just push – not safe when Slow Subscriber Just pull – too slow when Fast Subscriber
  • 55. Back-pressure? RS: Dynamic Push/Pull Slow Subscriber sees it’s buffer can take 3 elements. Publisher will never blow up it’s buffer.
  • 56. Back-pressure? RS: Dynamic Push/Pull Fast Publisher will send at-most 3 elements. This is pull-based-backpressure.
  • 57. Back-pressure? RS: Dynamic Push/Pull Fast Subscriber can issue more Request(n), before more data arrives!
  • 58. Back-pressure? RS: Dynamic Push/Pull Fast Subscriber can issue more Request(n), before more data arrives. Publisher can accumulate demand.
  • 59. Back-pressure? RS: Accumulate demand Publisher accumulates total demand per subscriber.
  • 60. Back-pressure? RS: Accumulate demand Total demand of elements is safe to publish. Subscriber’s buffer will not overflow.
  • 61. Back-pressure? RS: Requesting “a lot” Fast Subscriber can issue arbitrary large requests, including “gimme all you got” (Long.MaxValue)
  • 62. Back-pressure? RS: Dynamic Push/Pull MAX speed
  • 63. Back-pressure? RS: Dynamic Push/Pull Easy MAX speed
  • 65. Akka Streams – Linear Flow
  • 66. Akka Streams – Linear Flow
  • 67. Akka Streams – Linear Flow
  • 68. Akka Streams – Linear Flow
  • 69. Akka Streams – Linear Flow Flow[Double].map(_.toInt). [...] No Source attached yet. “Pipe ready to work with Doubles”.
  • 70. Akka Streams – Linear Flow implicit val sys = ActorSystem("scalar-sys") implicit val mat = ActorFlowMaterializer() Source(1 to 3).runWith(Sink.foreach(println))
  • 71. Akka Streams – Linear Flow implicit val sys = ActorSystem("scalar-sys") implicit val mat = ActorFlowMaterializer() Source(1 to 3).runWith(Sink.foreach(println)) // sugar for runWith Source(1 to 3).foreach(println)
  • 72. Akka Streams – Linear Flow implicit val sys = ActorSystem("scalar-sys") implicit val mat = ActorFlowMaterializer() Source(1 to 3).runWith(Sink.foreach(println)) // sugar for runWith Source(1 to 3).foreach(println) Sink.fold Sink.head Sink.ignore Sink.publisher Sink.cancelled // your own Sink …
  • 73. Akka Streams <-> Actors – Advanced val subscriber = ActorSubscriber( system.actorOf(Props[SubStreamParent], ”parent”) ) Source(1 to 100) .map(_.toString) .filter(_.length == 2) .drop(2) .conflate(seed => seed)((acc, i) => acc + i) .groupBy(_.last) .runWith(subscriber) All the usual ops available for Linear Flows.
  • 74. Akka Streams <-> Actors – Advanced val subscriber = ActorSubscriber( system.actorOf(Props[SubStreamParent], ”parent”) ) Source(1 to 100) .map(_.toString) .filter(_.length == 2) .drop(2) .conflate(seed => seed)((acc, i) => acc + i) .groupBy(_.last) .runWith(subscriber) Aggregating values until downstream demand comes.
  • 75. Akka Streams <-> Actors – Advanced val subscriber = ActorSubscriber( system.actorOf(Props[SubStreamParent], ”parent”) ) Source(1 to 100) .map(_.toString) .filter(_.length == 2) .drop(2) .conflate(seed => seed)((acc, i) => acc + i) .groupBy(_.last) .runWith(subscriber) Creates a stream of streams: Source[Source[String]]
  • 76. Akka Streams: Graphs val p: Publisher[String] = FlowGraph.closed(out) { implicit b o val merge = b.add(new StrictRoundRobin[String])
 in1 ~> merge.in(0) in2 ~> merge.in(1) 
 merge.out ~> o.inlet }.run() val in1 = Source(List("a", "b", "c", "d")) val in2 = Source(List("e", "f")) val out = Sink.publisher[String]
  • 77. Akka Streams: Graphs val p: Publisher[String] = FlowGraph.closed(out) { implicit b o val merge = b.add(new StrictRoundRobin[String])
 in1 ~> merge.in(0) in2 ~> merge.in(1) 
 merge.out ~> o.inlet }.run() val in1 = Source(List("a", "b", "c", "d")) val in2 = Source(List("e", "f")) val out = Sink.publisher[String] Sink[String, Publisher[String]] imports Graphs
  • 78. Akka Streams: Graphs val p: Publisher[String] = FlowGraph.closed(out) { implicit b o val merge = b.add(new StrictRoundRobin[String])
 in1 ~> merge.in(0) in2 ~> merge.in(1) 
 merge.out ~> o.inlet }.run() val in1 = Source(List("a", "b", "c", "d")) val in2 = Source(List("e", "f")) val out = Sink.publisher[String] Sink[String, Publisher[String]] materializes a Publisher[String]
  • 79. Akka Streams: Partial Graphs FlowGraph.partial() { implicit b import FlowGraph.Implicits._ val priorityMerge = b.add(MergePreferred[In](1)) val balance = b.add(Balance[In](workerCount)) val resultsMerge = b.add(Merge[Out](workerCount)) // After merging priority and ordinary jobs, we feed them to the balancer priorityMerge ~> balance // Wire up each of the outputs of the balancer to a worker flow // then merge them back for (i <- 0 until workerCount) balance.out(i) ~> worker ~> resultsMerge.in(i) // We now expose the input ports of the priorityMerge and the output // of the resultsMerge as our PriorityWorkerPool ports // -- all neatly wrapped in our domain specific Shape PriorityWorkerPoolShape( jobsIn = priorityMerge.in(0), priorityJobsIn = priorityMerge.preferred, resultsOut = resultsMerge.out) }
  • 80. Akka Streams: Partial Graphs FlowGraph.partial() { implicit b import FlowGraph.Implicits._ val priorityMerge = b.add(MergePreferred[In](1)) val balance = b.add(Balance[In](workerCount)) val resultsMerge = b.add(Merge[Out](workerCount)) // After merging priority and ordinary jobs, we feed them to the balancer priorityMerge ~> balance // Wire up each of the outputs of the balancer to a worker flow // then merge them back for (i <- 0 until workerCount) balance.out(i) ~> worker ~> resultsMerge.in(i) // We now expose the input ports of the priorityMerge and the output // of the resultsMerge as our PriorityWorkerPool ports // -- all neatly wrapped in our domain specific Shape PriorityWorkerPoolShape( jobsIn = priorityMerge.in(0), priorityJobsIn = priorityMerge.preferred, resultsOut = resultsMerge.out) }
  • 81. Akka Streams: Partial Graphs FlowGraph.partial() { implicit b import FlowGraph.Implicits._ val priorityMerge = b.add(MergePreferred[In](1)) val balance = b.add(Balance[In](workerCount)) val resultsMerge = b.add(Merge[Out](workerCount)) // After merging priority and ordinary jobs, we feed them to the balancer priorityMerge ~> balance // Wire up each of the outputs of the balancer to a worker flow // then merge them back for (i <- 0 until workerCount) balance.out(i) ~> worker ~> resultsMerge.in(i) // We now expose the input ports of the priorityMerge and the output // of the resultsMerge as our PriorityWorkerPool ports // -- all neatly wrapped in our domain specific Shape PriorityWorkerPoolShape( jobsIn = priorityMerge.in(0), priorityJobsIn = priorityMerge.preferred, resultsOut = resultsMerge.out) } case class PriorityWorkerPoolShape[In, Out]( jobsIn: Inlet[In], priorityJobsIn: Inlet[In], resultsOut: Outlet[Out]) extends Shape { // …
  • 82. Akka Streams: Partial Graphs val worker1 = Flow[String].map("step 1 " + _) val worker2 = Flow[String].map("step 2 " + _) FlowGraph.closed() { implicit b => import FlowGraph.Implicits._ val priorityPool1 = b.add(PriorityWorkerPool(worker1, 4)) val priorityPool2 = b.add(PriorityWorkerPool(worker2, 2)) Source(1 to 100).map("job: " + _) ~> priorityPool1.jobsIn Source(1 to 100).map("priority job: " + _) ~> priorityPool1.priorityJobsIn priorityPool1.resultsOut ~> priorityPool2.jobsIn Source(1 to 100).map("one-step, priority " + _) ~> priorityPool2.priorityJobsIn priorityPool2.resultsOut ~> Sink.foreach(println) }.run()
  • 83. Akka Streams: Partial Graphs val worker1 = Flow[String].map("step 1 " + _) val worker2 = Flow[String].map("step 2 " + _) FlowGraph.closed() { implicit b => import FlowGraph.Implicits._ val priorityPool1 = b.add(PriorityWorkerPool(worker1, 4)) val priorityPool2 = b.add(PriorityWorkerPool(worker2, 2)) Source(1 to 100).map("job: " + _) ~> priorityPool1.jobsIn Source(1 to 100).map("priority job: " + _) ~> priorityPool1.priorityJobsIn priorityPool1.resultsOut ~> priorityPool2.jobsIn Source(1 to 100).map("one-step, priority " + _) ~> priorityPool2.priorityJobsIn priorityPool2.resultsOut ~> Sink.foreach(println) }.run()
  • 84. Real life example: Akka Http OutgoingConnection requestIn +----------+ +-----------------------------------------------+--->| Termi- | requestRendering | | nation +---------------------> | +-------------------------------------->| Merge | | | Termination Backchannel | +----------+ | TCP- | | | level | | Method | client | +------------+ | Bypass | flow responseOut | responsePrep | Response |<---+ | <------------+----------------| Parsing | | | Merge |<------------------------------------------ V +------------+ akka.http.engine.client.OutgoingConnectionBlueprint.scala#L47
  • 85. Reactive Streams Bigger than Scala-ecosystem - JDK-wide (and wider). Inter-operable back-pressure protocol. Future work: reactive-streams-io, reactive-streams-js Akka Streams - one of the leading Reactive Streams impls. Complex in-memory stream processing. Akka Http - Akka Streams based, the “Spray 2.0”
  • 87. Wrapping up The future is typed! More typesafety / perf / features coming in future releases. It’s not “just typesafety”, it’s profoundly better ways to model things. Static stream processing graph layouts = more constraints => better ways to optimise.
  • 88. Timing ALL DATES ARE SUBJECT TO CHANGE. It’s done “when it’s done.”
  • 89. Timing Reactive Streams - 1.0-RC5 yesterday, 1.0 in “weeks” Akka Streams – 1.0-RC1 in around 2 weeks Akka Http – 1.0-M6 in around 2 weeks Akka Typed – merged as draft + experimental in Akka 2.4.x Akka Persistence – new “read side” will use Akka Streams ALL DATES ARE SUBJECT TO CHANGE. It’s done “when it’s done.”
  • 90. ktoso @ typesafe.com twitter: ktosopl github: ktoso team blog: letitcrash.com home: akka.io Thanks! / Questions?
  • 91. ©Typesafe 2015 – All Rights Reserved