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

Scala Identify类代码示例

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

本文整理汇总了Scala中akka.actor.Identify的典型用法代码示例。如果您正苦于以下问题:Scala Identify类的具体用法?Scala Identify怎么用?Scala Identify使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Identify类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala Event类代码示例发布时间:2022-05-23
下一篇:
Scala ExtensionIdProvider类代码示例发布时间: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