本文整理汇总了Scala中akka.actor.ActorIdentity类的典型用法代码示例。如果您正苦于以下问题:Scala ActorIdentity类的具体用法?Scala ActorIdentity怎么用?Scala ActorIdentity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ActorIdentity类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: RouteeCreationSpec
//设置package包名称以及导入依赖的类
package akka.routing
import akka.testkit.AkkaSpec
import akka.actor.Props
import akka.actor.Actor
import akka.actor.ActorRef
import akka.actor.LocalActorRef
import scala.concurrent.duration._
import akka.actor.Identify
import akka.actor.ActorIdentity
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
class RouteeCreationSpec extends AkkaSpec {
"Creating Routees" must {
"result in visible routees" in {
val N = 100
system.actorOf(RoundRobinPool(N).props(Props(new Actor {
system.actorSelection(self.path).tell(Identify(self.path), testActor)
def receive = Actor.emptyBehavior
})))
for (i ? 1 to N) {
expectMsgType[ActorIdentity] match {
case ActorIdentity(_, Some(_)) ? // fine
case x ? fail(s"routee $i was not found $x")
}
}
}
"allow sending to context.parent" in {
val N = 100
system.actorOf(RoundRobinPool(N).props(Props(new Actor {
context.parent ! "one"
def receive = {
case "one" ? testActor forward "two"
}
})))
val gotit = receiveWhile(messages = N) {
case "two" ? lastSender.toString
}
expectNoMsg(100.millis)
if (gotit.size != N) {
fail(s"got only ${gotit.size} from [${gotit mkString ", "}]")
}
}
}
}
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:51,代码来源:RouteeCreationSpec.scala
示例2: LookupActor
//设置package包名称以及导入依赖的类
package sample.remote.calculator
import scala.concurrent.duration._
import akka.actor.Actor
import akka.actor.ActorIdentity
import akka.actor.ActorRef
import akka.actor.Identify
import akka.actor.ReceiveTimeout
import akka.actor.Terminated
class LookupActor(path: String) extends Actor {
sendIdentifyRequest()
def sendIdentifyRequest(): Unit = {
context.actorSelection(path) ! Identify(path)
import context.dispatcher
context.system.scheduler.scheduleOnce(3.seconds, self, ReceiveTimeout)
}
def receive = identifying
def identifying: Actor.Receive = {
case ActorIdentity(`path`, Some(actor)) =>
context.watch(actor)
context.become(active(actor))
case ActorIdentity(`path`, None) => println(s"Remote actor not available: $path")
case ReceiveTimeout => sendIdentifyRequest()
case _ => println("Not ready yet")
}
def active(actor: ActorRef): Actor.Receive = {
case op: MathOp => actor ! op
case result: MathResult => result match {
case AddResult(n1, n2, r) =>
printf("Add result: %d + %d = %d\n", n1, n2, r)
case SubtractResult(n1, n2, r) =>
printf("Sub result: %d - %d = %d\n", n1, n2, r)
}
case Terminated(`actor`) =>
println("Calculator terminated")
sendIdentifyRequest()
context.become(identifying)
case ReceiveTimeout =>
// ignore
}
}
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:49,代码来源:LookupActor.scala
示例3: Watcher
//设置package包名称以及导入依赖的类
package com.udemy.akka.actorpath
import akka.actor.{Actor, ActorIdentity, ActorRef, Identify}
class Watcher extends Actor {
var counterRef:ActorRef = _
val selection = context.actorSelection("/user/counter")
selection ! Identify(None)
override def receive: Receive = {
case ActorIdentity(_,Some(ref)) =>
println(s"Actor reference for counter is $ref")
case ActorIdentity(_,None)=>
println("Actor selection of actor does not exist ")
}
}
开发者ID:akshay-harale,项目名称:udemy-akka,代码行数:19,代码来源:Watcher.scala
示例4: ControllerActor
//设置package包名称以及导入依赖的类
package org.remote.app.controller
import akka.actor.{Actor, ActorIdentity, ActorRef, Identify, Props, ReceiveTimeout, Terminated}
import org.remote.app.messaging.Action
import org.remote.app.sender.ManagerActor
import scala.concurrent.duration._
object ControllerActor {
def props(remoteHost: String): Props = {
Props(classOf[ControllerActor], remoteHost)
}
def actorName(host: String) = s"${host}controller"
}
class ControllerActor(remoteHost: String) extends Actor {
val remoteActorPath = s"akka.tcp://${context.system.name}@$remoteHost/user/${ManagerActor.actorName}"
def resolve(): Unit = {
context.actorSelection(remoteActorPath) ! Identify(remoteActorPath)
import context.dispatcher
context.system.scheduler.scheduleOnce(10.seconds, self, ReceiveTimeout)
}
resolve()
override def receive: Receive = identifying
def identifying: Receive = {
case ActorIdentity(`remoteActorPath`, Some(actor)) =>
context.watch(actor)
println(s"ActorIdentity was received from ${actor.path}")
context become active(actor)
case ActorIdentity(_, None) => println(s"Remote actor not available $remoteActorPath")
case ReceiveTimeout => resolve()
case a => println(s"Not ready yet for $a")
}
def active(actor: ActorRef): Receive = {
case ac: Action =>
println(ac)
actor ! ac
case Terminated(`actor`) =>
println(s"${actor.path} was terminated")
resolve()
context.become(identifying)
case ReceiveTimeout => //Ignore
}
}
开发者ID:ayuzhanin,项目名称:test-akka,代码行数:51,代码来源:ControllerActor.scala
示例5: RemoteLookupProxy
//设置package包名称以及导入依赖的类
package com.jordimasip
import akka.actor._
import akka.actor.ActorIdentity
import akka.actor.Identify
import scala.concurrent.duration._
class RemoteLookupProxy(path: String) extends Actor with ActorLogging {
context.setReceiveTimeout(3 seconds)
sendIdentifyRequest()
def sendIdentifyRequest(): Unit = {
val selection = context.actorSelection(path)
selection ! Identify(path)
}
def receive = identify
def identify: Receive = {
case ActorIdentity(`path`, Some(actor)) =>
context.setReceiveTimeout(Duration.Undefined)
log.info("switching to active state")
context.become(active(actor))
context.watch(actor)
case ActorIdentity(`path`, None) =>
log.error(s"Remote actor with path $path is not available.")
case ReceiveTimeout =>
sendIdentifyRequest()
case msg: Any =>
log.error(s"Ignoring message $msg, remote actor is not ready yet.")
}
def active(actor: ActorRef): Receive = {
case Terminated(actorRef) =>
log.info("Actor $actorRef terminated.")
log.info("switching to identify state")
context.become(identify)
context.setReceiveTimeout(3 seconds)
sendIdentifyRequest()
case msg: Any => actor forward msg
}
}
开发者ID:jordimasip,项目名称:go-tickets-akka,代码行数:48,代码来源:RemoteLookupProxy.scala
示例6: MyActor
//设置package包名称以及导入依赖的类
package com.example
import akka.actor.{Actor, ActorIdentity, Identify, Props}
import akka.event.Logging
class MyActor extends Actor {
val log = Logging(context.system, this)
val identifyId = 1 // ???????
val child = context.actorOf(Props[MyActor2], name = "myChild")
var lastSender = context.system.deadLetters
def receive = {
case "search" => {
context.actorSelection("/user/myActor/myChild") ! Identify(identifyId) // ????
// ????????
// context.actorSelection("../myActor/myChild") ! Identify(identifyId) // ????
// context.actorSelection("myChild") ! Identify(identifyId) // ???? (`./myChild` ???)
// context.actorSelection("myChi*") ! Identify(identifyId) // ???????
lastSender = sender
}
case ActorIdentity(`identifyId`, Some(ref)) => {
log.info("found")
lastSender ! ref // ???????
}
case ActorIdentity(`identifyId`, None) => {
log.info("not found")
}
case s: String => {
log.info(s)
child ! s
}
case _ => {
}
}
}
开发者ID:shigemk2,项目名称:my-actor-search-sample,代码行数:43,代码来源:MyActor.scala
示例7: RemoteLookupProxy
//设置package包名称以及导入依赖的类
package com.goticks
import akka.actor._
import akka.actor.ActorIdentity
import akka.actor.Identify
import scala.concurrent.duration._
class RemoteLookupProxy(path: String)
extends Actor with ActorLogging {
context.setReceiveTimeout(3 seconds)
sendIdentifyRequest()
def sendIdentifyRequest(): Unit = {
val selection = context.actorSelection(path)
selection ! Identify(path)
}
def receive = identify
def identify: Receive = {
case ActorIdentity(`path`, Some(actor)) =>
context.setReceiveTimeout(Duration.Undefined)
log.info("switching to active state")
context.become(active(actor))
context.watch(actor)
case ActorIdentity(`path`, None) =>
log.error(s"Remote actor with path $path is not available.")
case ReceiveTimeout =>
sendIdentifyRequest()
case msg: Any =>
log.error(s"Ignoring message $msg, remote actor is not ready yet.")
}
def active(actor: ActorRef): Receive = {
case Terminated(actorRef) =>
log.info(s"Actor $actorRef terminated.")
log.info("switching to identify state")
context.become(identify)
context.setReceiveTimeout(3 seconds)
sendIdentifyRequest()
case msg: Any => actor forward msg
}
}
开发者ID:gilbutITbook,项目名称:006877,代码行数:50,代码来源:RemoteLookupProxy.scala
示例8: receive
//设置package包名称以及导入依赖的类
package com.github.lzenczuk.akka.course.failover
import akka.actor.{Actor, ActorIdentity, ActorLogging, ActorSelection, Identify, Terminated}
Market_*") ! Identify()
}
override def receive = {
case ActorIdentity(_, Some(ref)) =>
log.info(s"Receive market ref: ${ref.path}")
context.watch(ref)
case Terminated(ref) =>
log.info(s"Market ${ref.path} terminated.")
context.unwatch(ref)
case x:Any =>
log.info(s"Receive message: $x")
}
}
开发者ID:lzenczuk,项目名称:akka-app-one,代码行数:19,代码来源:MarketsObserver.scala
注:本文中的akka.actor.ActorIdentity类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论