• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Akka类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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()
  }

} 
开发者ID:knoldus,项目名称:knolx-portal,代码行数:26,代码来源:Module.scala


示例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 
开发者ID:OCervantes,项目名称:websocket-play,代码行数:31,代码来源:BoardActor.scala


示例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 
开发者ID:baydindima,项目名称:ScalaChat,代码行数:34,代码来源:BoardActor.scala


示例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)
      }
    }
  }
} 
开发者ID:asen,项目名称:smg,代码行数:42,代码来源:ExecutionContexts.scala


示例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) 
开发者ID:liuchaoren,项目名称:Distributed-Chatting-Web-Application,代码行数:44,代码来源:BoardActor.scala


示例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

} 
开发者ID:bar2cha,项目名称:DomoScalaB2C,代码行数:41,代码来源:BuildingStatusWebSocketActor.scala


示例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

} 
开发者ID:bar2cha,项目名称:DomoScalaB2C,代码行数:42,代码来源:RoomStatusWebSocketActor.scala


示例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

} 
开发者ID:bar2cha,项目名称:DomoScalaB2C,代码行数:41,代码来源:SystemStatusWebSocketActor.scala


示例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)
  }
} 
开发者ID:qchen-es3,项目名称:keen-collect-proxy,代码行数:61,代码来源:AnalyticsController.scala


示例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 
开发者ID:bbnsumanth,项目名称:Reactive-pings,代码行数:31,代码来源:StreamManagerActor.scala



注:本文中的play.libs.Akka类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala JDBCOptions类代码示例发布时间:2022-05-23
下一篇:
Scala ActorNotFound类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap