本文整理汇总了Scala中play.libs.Akka类的典型用法代码示例。如果您正苦于以下问题:Scala Akka类的具体用法?Scala Akka怎么用?Scala Akka使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Akka类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Module
//设置package包名称以及导入依赖的类
import java.util.function.Function
import akka.actor.ActorRef
import com.google.inject.AbstractModule
import com.google.inject.name.Names
import com.google.inject.util.Providers
import controllers.{DefaultKnolxControllerComponents, KnolxControllerComponents}
import net.codingwell.scalaguice.ScalaModule
import play.libs.Akka
import schedulers.SessionsScheduler
class Module extends AbstractModule with ScalaModule {
override def configure(): Unit = {
bind[ActorRef]
.annotatedWith(Names.named("SessionsScheduler"))
.toProvider(Providers.guicify(Akka.providerOf(classOf[SessionsScheduler], "SessionsScheduler", Function.identity())))
.asEagerSingleton
bind(classOf[KnolxControllerComponents])
.to(classOf[DefaultKnolxControllerComponents])
.asEagerSingleton()
}
}
示例2: BoardActor
//设置package包名称以及导入依赖的类
package actors
import akka.actor.Actor
import akka.actor.ActorLogging
import akka.event.LoggingReceive
import akka.actor.ActorRef
import akka.actor.Terminated
import play.libs.Akka
import akka.actor.Props
class BoardActor extends Actor with ActorLogging {
var users = Set[ActorRef]()
def receive = LoggingReceive {
case m:Message => users map { _ ! m}
case Subscribe => {
users += sender
context watch sender
}
case Terminated(user) => users -= user
}
}
object BoardActor {
lazy val board = Akka.system().actorOf(Props[BoardActor])
def apply() = board
}
case class Message(uuid: String, s: String)
object Subscribe
示例3: BoardActor
//设置package包名称以及导入依赖的类
package actors
import akka.actor.Actor
import akka.actor.ActorLogging
import akka.event.LoggingReceive
import akka.actor.ActorRef
import akka.actor.Terminated
import play.libs.Akka
import akka.actor.Props
class BoardActor extends Actor with ActorLogging {
var users = Set[ActorRef]()
def receive = LoggingReceive {
case m: Message =>
users foreach { user =>
user ! m
}
case Subscribe =>
users += sender
context watch sender
case Terminated(user) =>
users -= user
}
}
object BoardActor {
lazy val board: ActorRef = Akka.system().actorOf(Props[BoardActor])
def apply(): ActorRef = board
}
case class Message(nickname: String, userId: Int, msg: String)
object Subscribe
示例4: createNewExecutionContext
//设置package包名称以及导入依赖的类
package com.smule.smg
import java.util.concurrent.{Executors, ConcurrentHashMap}
import scala.collection.concurrent
import scala.collection.JavaConversions._
import play.libs.Akka
import scala.concurrent.ExecutionContext
val rrdGraphCtx: ExecutionContext = Akka.system.dispatchers.lookup("akka-contexts.rrd-graph")
val monitorCtx: ExecutionContext = Akka.system.dispatchers.lookup("akka-contexts.monitor")
private val log = SMGLogger
private val ctxMap: concurrent.Map[Int,ExecutionContext] = new ConcurrentHashMap[Int, ExecutionContext]()
private def createNewExecutionContext(maxThreads: Int): ExecutionContext = {
val es = Executors.newFixedThreadPool(maxThreads)
ExecutionContext.fromExecutorService(es)
}
def ctxForInterval(interval: Int): ExecutionContext = {
ctxMap(interval)
}
def initializeUpdateContexts(intervals: Seq[Int], threadsPerIntervalMap: Map[Int,Int], defaultThreadsPerInterval: Int): Unit = {
intervals.foreach { interval =>
if (!ctxMap.contains(interval)) {
val maxThreads = if (threadsPerIntervalMap.contains(interval)) threadsPerIntervalMap(interval) else defaultThreadsPerInterval
val ec = createNewExecutionContext(maxThreads)
ctxMap(interval) = ec
log.info("ExecutionContexts.initializeUpdateContexts: Created ExecutionContext for interval=" + interval +
" maxThreads=" + maxThreads + " ec.class="+ ec.getClass.getName)
}
}
}
}
示例5: BoardActor
//设置package包名称以及导入依赖的类
package actors
import akka.actor.Actor
import akka.actor.ActorLogging
import akka.event.LoggingReceive
import akka.actor.ActorRef
import akka.actor.Terminated
import play.libs.Akka
import akka.actor.Props
import scala.collection.mutable.Map
class BoardActor extends Actor with ActorLogging {
var users = Set[ActorRef]()
var usersid = Set[String]()
var userIDmap = Map[ActorRef, String]()
def receive = LoggingReceive {
case s:Subscribe => {
users += sender
usersid += s.userID
userIDmap += (sender -> s.userID)
context watch sender
}
case AcquireUsers => sender ! users
case AcquireUsersID => sender ! usersid
case AcquireUserIDMap => sender ! userIDmap
case Terminated(user) => users -= user
}
}
object BoardActor {
lazy val board = Akka.system().actorOf(Props[BoardActor])
def apply() = board
}
case class Message(uuid: String, senderClock: Map[String, Int], s: String)
case class MessageToMyself(uuid:String, s:String)
case class Subscribe(userID:String)
object AcquireUsers
object AcquireUsersID
object AcquireUserIDMap
case class newUser(user:ActorRef, id:String)
示例6: BuildingStatusWebSocketActor
//设置package包名称以及导入依赖的类
package actors
import akka.actor._
import akka.event.LoggingReceive
import play.api.libs.json._
import play.libs.Akka
import actors.DomoscalaActor.GetRooms
object BuildingStatusWebSocketActor {
def props(out: ActorRef, buildingId: String) =
Props(new BuildingStatusWebSocketActor(out, buildingId))
}
class BuildingStatusWebSocketActor(out: ActorRef, buildingId: String) extends Actor with ActorLogging {
override def preStart() = {
// look for our "root" actor, and look for rooms
val domo = Akka.system.actorSelection("user/domoscala")
domo ! GetRooms(buildingId)
}
def init: Receive = LoggingReceive {
case res: Set[_] =>
res.asInstanceOf[Set[Room]].foreach { room =>
context.actorOf(RoomStatusWebSocketActor.props(self, buildingId, room.id))
}
context.become(main)
}
def main: Receive = LoggingReceive {
// receiving from rooms, forwarding to out
case msg => out forward msg
}
// initially, we have to wait to receive rooms
def receive = init
}
示例7: RoomStatusWebSocketActor
//设置package包名称以及导入依赖的类
package actors
import akka.actor._
import akka.event.LoggingReceive
import play.api.libs.json._
import play.libs.Akka
import actors.DomoscalaActor.GetDevices
object RoomStatusWebSocketActor {
def props(out: ActorRef, buildingId: String, roomId: String) =
Props(new RoomStatusWebSocketActor(out, buildingId, roomId))
}
class RoomStatusWebSocketActor(out: ActorRef, buildingId: String,
roomId: String) extends Actor with ActorLogging {
override def preStart() = {
// look for our "root" actor, and look for given room actor
val domo = Akka.system.actorSelection("user/domoscala")
domo ! GetDevices(buildingId, roomId)
}
def init: Receive = LoggingReceive {
case devices: Set[_] =>
devices.asInstanceOf[Set[Dev]].map {
dev =>
context.actorOf(DeviceStatusWebSocketActor.props(self, buildingId, roomId, dev.id))
}
context.become(main)
}
def main: Receive = LoggingReceive {
// receiving from devices, forwarding to out
case msg => out forward msg
}
// initially, we have to wait to receive devices of selected room
def receive = init
}
示例8: SystemStatusWebSocketActor
//设置package包名称以及导入依赖的类
package actors
import akka.actor._
import akka.event.LoggingReceive
import play.api.libs.json._
import play.libs.Akka
import actors.DomoscalaActor.GetBuildings
object SystemStatusWebSocketActor {
def props(out: ActorRef) =
Props(new SystemStatusWebSocketActor(out))
}
class SystemStatusWebSocketActor(out: ActorRef) extends Actor with ActorLogging {
override def preStart() = {
// look for our "root" actor, and get buildings
val domo = Akka.system.actorSelection("user/domoscala")
domo ! GetBuildings
}
def init: Receive = LoggingReceive {
case res: Set[_] =>
res.asInstanceOf[Set[Building]].foreach { building =>
context.actorOf(BuildingStatusWebSocketActor.props(self, building.id))
}
context.become(main)
}
def main: Receive = LoggingReceive {
// receiving from buildings, forwarding to out
case msg => out forward msg
}
// initially, we have to wait to receive buildings
def receive = init
}
示例9: AnalyticsController
//设置package包名称以及导入依赖的类
package controllers
import controllers.zonetv.unity.analytics.{Payload, KeenAnalyticsProvider}
import play.api._
import play.api.libs.json._
import play.api.mvc._
import play.libs.Akka
import scala.concurrent.{ExecutionContext, Future}
object AnalyticsController extends Controller{
object Contexts {
implicit val keenExecutionContext: ExecutionContext = Akka.system.dispatchers.lookup("keen-context")
}
def version = Action{ implicit request =>
Logger.info("Get version")
Ok("2.5.0")
}
def start = Action{ request =>
this.collect("start", request)
}
def end = Action{ request =>
this.collect("end", request)
}
def content = Action{ request =>
this.collect("content", request)
}
def feature = Action{ request =>
this.collect("feature", request)
}
def collect(event: String, request: Request[AnyContent] ): Result = {
val payload = request.body.asXml
.map { xml => new Payload(xml) }
.getOrElse {
request.body.asJson.map { json => new Payload(json) }
.orNull
}
payload.event = Some(event)
Future {
KeenAnalyticsProvider.collect(payload)
}(Contexts.keenExecutionContext)
if (request.accepts("application/json"))
Ok(Json.obj("session" -> payload.sessionId.toString))
else if (request.accepts("application/xml"))
Ok(<session>
{payload.sessionId.toString}
</session>)
else
Ok(payload.sessionId.toString)
}
}
示例10: StreamManagerActor
//设置package包名称以及导入依赖的类
package actors
import akka.actor.{Props, ActorRef, Actor}
import akka.actor.Actor.Receive
import play.libs.Akka
class StreamManagerActor extends Actor{
//create all these instances upon the creation of StreamManager
val driverManager = DriverManagerActor.driverManagerActor
//val tripManager = TripManagerActor.tripManagerActor
val streamListenerActor = StreamListenerActor.streamListenerActor
override def receive: Receive = {
case StartStreaming => {
//todo:keep listening to a stream and upon event ,update driver and trips
// but the prob here is we can not block on this,becoz then we can not send a mess asking it to stop processing
//so create another actor(streamListenerActor) whose sole purpose is to listen on events and uupdates drivers and trips
streamListenerActor ! Listen
}
case StopStreaming => {
context.stop(streamListenerActor)
}
}
}
object StreamManagerActor{
lazy val streamManagerActor: ActorRef = Akka.system.actorOf(Props(classOf[StreamManagerActor]))
}
case object StartStreaming
case object StopStreaming