Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf ·...
Transcript of Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf ·...
![Page 1: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/1.jpg)
Isolates, channels and
event streams for composable distributed programming
Aleksandar Prokopec
Martin Odersky
![Page 2: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/2.jpg)
State of the art
![Page 3: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/3.jpg)
class NameServer extends Actor {
}
![Page 4: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/4.jpg)
class NameServer extends Actor {
val actors = Map[String, ActorRef]()
}
![Page 5: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/5.jpg)
class NameServer extends Actor {
val actors = Map[String, ActorRef]()
def receive = {
case nm: String => sender ! actors(nm)
}
}
![Page 6: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/6.jpg)
class NameServer extends Actor {
val actors = Map[String, ActorRef]()
def receive = {
case nm: String => sender ! actors(nm)
}
}
val ns = actorOf(NameServer)
![Page 7: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/7.jpg)
class NameServer extends Actor {
val actors = Map[String, ActorRef]()
def receive = {
case nm: String => sender ! actors(nm)
}
}
val ns = actorOf(NameServer)
class Client extends Actor {
ns ! “p”
}
for (i <- 0 until 2) actorOf(Client)
![Page 8: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/8.jpg)
NameServer
actors
Client Client
y x
![Page 9: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/9.jpg)
The problem
![Page 10: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/10.jpg)
class Server[T, S](f: T => S) extends Actor {
}
![Page 11: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/11.jpg)
class Server[T, S](f: T => S) extends Actor {
def receive = { case x: T => sender ! f(x) }
}
![Page 12: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/12.jpg)
class Server[T, S](f: T => S) extends Actor {
def receive = { case x: T => sender ! f(x) }
}
class Client[T, S]
(server: ActorRef, req: T, action: S => Unit)
extends Actor {
}
![Page 13: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/13.jpg)
class Server[T, S](f: T => S) extends Actor {
def receive = { case x: T => sender ! f(x) }
}
class Client[T, S]
(server: ActorRef, req: T, action: S => Unit)
extends Actor {
server ! req
}
![Page 14: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/14.jpg)
class Server[T, S](f: T => S) extends Actor {
def receive = { case x: T => sender ! f(x) }
}
class Client[T, S]
(server: ActorRef, req: T, action: S => Unit)
extends Actor {
server ! req
def receive = { case x: S => action(x) }
}
![Page 15: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/15.jpg)
val actors = Map[String, ActorRef]()
![Page 16: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/16.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
![Page 17: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/17.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
![Page 18: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/18.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
NameServer
actors Client
![Page 19: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/19.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
NameServer
actors Client p
![Page 20: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/20.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
NameServer
actors Client p r
![Page 21: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/21.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
NameServer
actors
Cache
![Page 22: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/22.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
NameServer
actors
Cache p
Cache is a client.
![Page 23: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/23.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
NameServer
actors
Cache
r
Cache is a client.
![Page 24: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/24.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
NameServer
actors
Cache
r
Cache is a client.
![Page 25: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/25.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r)
NameServer
actors
Cache
r
![Page 26: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/26.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r)
NameServer
actors
Cache
r Client p
Cache is a server.
![Page 27: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/27.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r)
NameServer
actors
Cache
r Client r
Cache is a server.
![Page 28: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/28.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r) {
def receive = super.receive orElse {
case “p” => sender ! cached
NameServer
actors
Cache
r Client
![Page 29: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/29.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r) {
def receive = super.receive orElse {
case “p” => sender ! cached
Cache
r
Cache can be refreshed.
NameServer
actors
![Page 30: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/30.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r) {
def receive = super.receive orElse {
case “p” => sender ! cached
NameServer
actors
Cache
r
Cache can be refreshed.
![Page 31: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/31.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r) {
def receive = super.receive orElse {
case “p” => sender ! cached
Cache
r
Cache can be refreshed.
![Page 32: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/32.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r) {
def receive = super.receive orElse {
case “p” => sender ! cached
NameServer’
actors
Cache
r
Cache can be refreshed.
![Page 33: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/33.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r) {
def receive = super.receive orElse {
case “p” => sender ! cached
NameServer’
actors
Cache
r p
Cache can be refreshed.
![Page 34: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/34.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r) {
def receive = super.receive orElse {
case “p” => sender ! cached
NameServer’
actors
Cache
r q
Cache can be refreshed.
![Page 35: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/35.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r) {
def receive = super.receive orElse {
case “p” => sender ! cached
NameServer’
actors
Cache
q
Cache can be refreshed.
![Page 36: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/36.jpg)
val actors = Map[String, ActorRef]()
val ns = actorOf(Server(actors))
val client = actorOf(Client(ns, “p”, println))
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r) {
def receive = super.receive orElse {
case “p” => sender ! cached
case newNs: ActorRef => newNs ! “p”
}
}
NameServer
actors
Cache
q
![Page 37: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/37.jpg)
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r) {
def receive = super.receive orElse {
case “p” => sender ! cached
case newNs: ActorRef => newNs ! “p”
}
}
NameServer
actors
Cache
q
Not just ugly, but also incorrect.
![Page 38: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/38.jpg)
...
def receive = { case x: S => action(x) }
...
class Cache(var cached: ActorRef = null)
extends Client(ns, “p”, r => cached = r) {
def receive = super.receive orElse {
case “p” => sender ! cached
case newNs: ActorRef => newNs ! “p”
}
}
NameServer
actors
Cache
r
![Page 39: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/39.jpg)
...
def receive = { case x: S => action(x) }
...
class Cache(var cached: ActorRef = null)
extends Client(reg, “p”, r => cached = r) {
def receive = {
case r: ActorRef => cached = r
case “p” => sender ! cached
case newNs: ActorRef => newNs ! “p”
}
} NameServer
actors
Cache
r
![Page 40: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/40.jpg)
Fundamental problem Implementer needs to be aware of all the
protocols running in the actor.
![Page 41: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/41.jpg)
First ingredient Express concurrency in the system
![Page 42: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/42.jpg)
class NameServer
extends Iso[String] {
val channels = Map[String, Channel[_]]()
}
NameServer
channels
![Page 43: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/43.jpg)
NameServer
channels
class NameServer
extends Iso[String] {
val channels = Map[String, Channel[_]]()
}
val ns: Channel[String] = isolate(NameServer)
ns
![Page 44: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/44.jpg)
Second ingredient Send information to other processes
![Page 45: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/45.jpg)
class NameServer
extends Iso[String] {
val channels = Map[String, Channel[_]]()
}
val ns: Channel[String] = isolate(NameServer)
ns ! “p”
NameServer
channels
ns
![Page 46: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/46.jpg)
class NameServer
extends Iso[String] {
val channels = Map[String, Channel[_]]()
}
val ns: Channel[String] = isolate(NameServer)
ns ! “p”
NameServer
channels
ns p
![Page 47: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/47.jpg)
Third ingredient Receive information from other processes
![Page 48: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/48.jpg)
class NameServer
extends Iso[String] {
val channels = Map[String, Channel[_]]()
events onMatch {
case name => sender ! channels(name)
}
}
NameServer
channels
ns p events
![Page 49: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/49.jpg)
class NameServer
extends Iso[String] {
val channels = Map[String, Channel[_]]()
events onMatch {
case name => sender ! channels(name)
}
}
NameServer
channels
ns p events
![Page 50: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/50.jpg)
class NameServer
extends Iso[(String, Channel[Channel[_]])] {
val channels = Map[String, Channel[_]]()
events onMatch {
case (name, ch) => ch ! channels(name)
}
}
NameServer
channels
ns events (p, ch)
ch
![Page 51: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/51.jpg)
class NameServer
extends Iso[(String, Channel[Channel[_]])] {
val channels = Map[String, Channel[_]]()
events onMatch {
case (name, ch) => ch ! channels(name)
}
}
NameServer
channels
ns events
ch
(p, ch)
c
![Page 52: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/52.jpg)
def open[T]: (Channel[T], Events[T])
trait Channel[T] {
def !(x: T): Unit
}
trait Events[T] {
def onEvent(f: T => Unit)
def onMatch(f: PartialFunction[T, Unit])
def forward(c: Channel[T])
}
![Page 53: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/53.jpg)
class NameServer
extends Iso[(String, Channel[Channel[_]])] {
val channels = Map[String, Channel[_]]()
events onMatch {
case (name, ch) => ch ! channels(name)
}
}
type Req[T, S] = Channel[(T, Channel[S])]
![Page 54: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/54.jpg)
class NameServer
extends Iso[(String, Channel[Channel[_]])] {
val channels = Map[String, Channel[_]]()
events onMatch {
case (name, ch) => ch ! channels(name)
}
}
type Req[T, S] = Channel[(T, Channel[S])]
def server[T, S](f: T => S): Req[T, S]
![Page 55: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/55.jpg)
class NameServer
extends Iso[(String, Channel[Channel[_]])] {
val channels = Map[String, Channel[_]]()
events onMatch {
case (name, ch) => ch ! channels(name)
}
}
type Req[T, S] = Channel[(T, Channel[S])]
def server[T, S](f: T => S): Req[T, S] = {
val (ch, events) = open[(T, Channel[S])]
}
![Page 56: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/56.jpg)
class NameServer
extends Iso[(String, Channel[Channel[_]])] {
val channels = Map[String, Channel[_]]()
events onMatch {
case (name, ch) => ch ! channels(name)
}
}
type Req[T, S] = Channel[(T, Channel[S])]
def server[T, S](f: T => S): Req[T, S] = {
val (ch, events) = open[(T, Channel[S])]
events onMatch { case (x, c) => c ! f(x) }
}
![Page 57: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/57.jpg)
class NameServer
extends Iso[(String, Channel[Channel[_]])] {
val channels = Map[String, Channel[_]]()
events onMatch {
case (name, ch) => ch ! channels(name)
}
}
type Req[T, S] = Channel[(T, Channel[S])]
def server[T, S](f: T => S): Req[T, S] = {
val (ch, events) = open[(T, Channel[S])]
events onMatch { case (x, c) => c ! f(x) }
ch
}
![Page 58: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/58.jpg)
class NameServer
extends Iso[(String, Channel[Channel[_]])] {
val s = server(Map[String, Channel[_]]())
events.forward(s)
}
type Req[T, S] = Channel[(T, Channel[S])]
def server[T, S](f: T => S): Req[T, S] = {
val (ch, events) = open[(T, Channel[S])]
events onMatch { case (x, c) => c ! f(x) }
ch
}
![Page 59: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/59.jpg)
type Req[T, S] = Channel[(T, Channel[S])]
def ?[T, S](r: Req[T, S], x: T): Events[S]
![Page 60: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/60.jpg)
type Req[T, S] = Channel[(T, Channel[S])]
def ?[T, S](r: Req[T, S], x: T): Events[S] = {
val (ch, events) = open[S]
}
![Page 61: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/61.jpg)
type Req[T, S] = Channel[(T, Channel[S])]
def ?[T, S](r: Req[T, S], x: T): Events[S] = {
val (ch, events) = open[S]
r ! (x, ch)
}
![Page 62: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/62.jpg)
type Req[T, S] = Channel[(T, Channel[S])]
def ?[T, S](r: Req[T, S], x: T): Events[S] = {
val (ch, events) = open[S]
r ! (x, ch)
events
}
![Page 63: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/63.jpg)
class Client(val ns: Req[String, Channel[_]])
extends Iso[Unit] {
val response = server ? “p”
response.onEvent(println)
}
type Req[T, S] = Channel[(T, Channel[S])]
def ?[T, S](r: Req[T, S], x: T): Events[S] = {
val (ch, events) = open[S]
r ! (x, ch)
events
}
![Page 64: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/64.jpg)
class Cache(val ns: Req[String, Channel[_]])
extends Iso[(String, Channel[Channel[_]])] {
}
Cache
![Page 65: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/65.jpg)
class Cache(val ns: Req[String, Channel[_]])
extends Iso[(String, Channel[Channel[_]])] {
var cached: Channel[_] = null
events.forward(server(x => cached))
}
Cache server Client
![Page 66: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/66.jpg)
class Cache(val ns: Req[String, Channel[_]])
extends Iso[(String, Channel[Channel[_]])] {
var cached: Channel[_] = null
events.forward(server(x => cached))
val response = server ? “p”
response.onEvent(c => cached = c)
}
Cache server client Client
NameServer
channels
![Page 67: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/67.jpg)
class Cache(val ns: Req[String, Channel[_]])
extends Iso[(String, Channel[Channel[_]])] {
var cached: Channel[_] = null
events.forward(server(x => cached))
val response = server ? “p”
response.onEvent(ch => cached(“p”) = ch)
open[Req[String, Channel[_]]].events.onEvent(
ns => (ns ? “p”).onEvent(c => cached = c))
}
Cache server client
push
Client
NameServer
channels
![Page 68: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/68.jpg)
Systems can compose
Broadcast def bcst[T](s: Set[Channel[T]]): Channel[T]
![Page 69: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/69.jpg)
Systems can compose
Broadcast def bcst[T](s: Set[Channel[T]]): Channel[T]
CRDT def crdt[T, D](bcst: Channel[T],
update: (D, T) => D): (T => Unit, () => D)
![Page 70: Isolates, channels and event streamsaleksandar-prokopec.com/resources/docs/onward15.pdf · Isolates, channels and event streams for composable distributed programming Aleksandar Prokopec](https://reader033.fdocuments.net/reader033/viewer/2022042710/5f598e3f1d59b41d8151f863/html5/thumbnails/70.jpg)
Thank you!