start using actor selections
This commit is contained in:
parent
84a468cf7a
commit
1fe0c35ce6
|
@ -12,6 +12,12 @@ final class Scheduler(system: ActorSystem, enabled: Boolean) {
|
|||
enabled ! system.scheduler.schedule(freq, randomize(freq), to._1, to._2)
|
||||
}
|
||||
|
||||
def messageToSelection(freq: FiniteDuration)(to: ⇒ (ActorSelection, Any)) {
|
||||
enabled ! system.scheduler.schedule(freq, randomize(freq)) {
|
||||
to._1 ! to._2
|
||||
}
|
||||
}
|
||||
|
||||
def effect(freq: FiniteDuration, name: String)(op: ⇒ Unit) {
|
||||
enabled ! future(freq, name)(fuccess(op))
|
||||
}
|
||||
|
|
|
@ -8,11 +8,13 @@ import akka.util.Timeout
|
|||
// like ActorSelection, but supports ask pattern
|
||||
final class ActorLazyRef private (system: ActorSystem, path: String) {
|
||||
|
||||
def ref = system actorFor path
|
||||
// def ref = system actorFor path
|
||||
// def ref = selection
|
||||
lazy val selection = system actorSelection path
|
||||
|
||||
def !(msg: Any)(implicit sender: ActorRef = Actor.noSender) { ref ! msg }
|
||||
def !(msg: Any)(implicit sender: ActorRef = Actor.noSender) { selection ! msg }
|
||||
|
||||
def ?(msg: Any)(implicit timeout: Timeout, sender: ActorRef = Actor.noSender): Fu[Any] = ref ? msg
|
||||
def ?(msg: Any)(implicit timeout: Timeout, sender: ActorRef = Actor.noSender): Fu[Any] = selection ? msg
|
||||
}
|
||||
|
||||
object ActorLazyRef {
|
||||
|
|
|
@ -19,7 +19,7 @@ private[notification] final class Api(socketHub: lila.hub.ActorLazyRef, renderer
|
|||
val request = actorApi.RenderNotification(notif.id, notif.from, notif.html)
|
||||
renderer ? request map {
|
||||
case rendered: Html ⇒ SendTo(userId, "notificationAdd", rendered.toString)
|
||||
} logFailure "[notification] cannot render" pipeTo socketHub.ref
|
||||
} logFailure "[notification] cannot render" pipeToSelection socketHub.selection
|
||||
}
|
||||
|
||||
def get(userId: String): List[Notification] = ~(repo get userId)
|
||||
|
|
|
@ -72,7 +72,7 @@ private[relation] final class RelationActor(
|
|||
"us" -> usernames,
|
||||
"nb" -> nb
|
||||
))
|
||||
} pipeTo socketHub.ref
|
||||
} pipeToSelection socketHub.selection
|
||||
}
|
||||
|
||||
private def notifyFollowers(users: List[User], message: String) {
|
||||
|
|
|
@ -27,7 +27,7 @@ private[setup] final class Challenger(
|
|||
"html" -> html.toString
|
||||
)
|
||||
))
|
||||
} pipeTo hub.ref
|
||||
} pipeToSelection hub.selection
|
||||
|
||||
case msg @ DeclineChallenge(gameId) ⇒ roundHub ! Tell(gameId, msg)
|
||||
}
|
||||
|
|
|
@ -17,11 +17,11 @@ final class Env(
|
|||
import scala.concurrent.duration._
|
||||
|
||||
scheduler.once(5 seconds) {
|
||||
scheduler.message(4 seconds) {
|
||||
hub.socket.hub.ref -> actorApi.Broom
|
||||
scheduler.messageToSelection(4 seconds) {
|
||||
hub.socket.hub.selection -> actorApi.Broom
|
||||
}
|
||||
scheduler.message(1 seconds) {
|
||||
hub.socket.hub.ref -> GetNbMembers
|
||||
scheduler.messageToSelection(1 seconds) {
|
||||
hub.socket.hub.selection -> GetNbMembers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ private[timeline] final class GamePush(
|
|||
$insert(entry) >>- {
|
||||
renderer ? entry map {
|
||||
case view: Html ⇒ GameEntryView(view.body)
|
||||
} pipeTo lobbySocket.ref
|
||||
} pipeToSelection lobbySocket.selection
|
||||
}
|
||||
} logFailure ("[timeline] push " + game.id)
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ private[timeline] final class Push(
|
|||
case Propagate(data, propagations) ⇒ propagate(propagations) foreach { users ⇒
|
||||
if (users.nonEmpty) makeEntry(users, data) >>-
|
||||
(users foreach { u ⇒
|
||||
lobbySocket.ref ! ReloadTimeline(u)
|
||||
lobbySocket.selection ! ReloadTimeline(u)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue