Permalink
Browse files

未登録Publisherからのpublishを弾く

  • Loading branch information...
matsu-chara committed Dec 11, 2015
1 parent d29103f commit 884b2c6d8151bf9dead6cf751dccb4377a5712c2
Showing with 17 additions and 4 deletions.
  1. +4 −0 main.pony
  2. +5 −2 publisher.pony
  3. +8 −2 server.pony
View
@@ -32,3 +32,7 @@ actor Main
p3.publish(server, "niconico!")
p4.publish(server, "nyanyan!")
p5.publish(server, "kameeee!")
// this message will be ignored
p1.publish(server, "new presentation!")
View
@@ -7,6 +7,9 @@ class Publisher
fun val register(server: Server) =>
server.register_publisher(this)
fun publish(server: Server, message: String) =>
server.publish(name + " sends " + message)
fun val publish(server: Server, message: String) =>
server.publish(this, name + " sends " + message)
fun box eq(that: Publisher box): Bool =>
name == that.name
View
@@ -2,7 +2,7 @@ use "collections"
actor Server
let _env: Env
var pubs: List[Publisher val] iso
var pubs: List[Publisher val] trn
let sub_workers: List[Worker]
new create(env': Env) =>
@@ -19,7 +19,13 @@ actor Server
be register_subscriber(sub: Subscriber val) =>
sub_workers.push(Worker(sub))
be publish(message: String) =>
be publish(sender: Publisher val, message: String) =>
var isRegistered = false
for pub in pubs.values() do
isRegistered = isRegistered or (sender == pub)
end
if isRegistered == false then return end
for worker in sub_workers.values() do
worker.receive(message)
end

0 comments on commit 884b2c6

Please sign in to comment.