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

Scala ActorPath类代码示例

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

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



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

示例1: RoutedActorRef

//设置package包名称以及导入依赖的类
package akka.routing

import scala.concurrent.duration._
import akka.ConfigurationException
import akka.actor.ActorPath
import akka.actor.ActorSystemImpl
import akka.actor.Cell
import akka.actor.InternalActorRef
import akka.actor.Props
import akka.actor.RepointableActorRef
import akka.actor.UnstartedCell
import akka.dispatch.BalancingDispatcher
import akka.dispatch.MailboxType
import akka.dispatch.MessageDispatcher


private[akka] class RoutedActorRef(
  _system: ActorSystemImpl,
  _routerProps: Props,
  _routerDispatcher: MessageDispatcher,
  _routerMailbox: MailboxType,
  _routeeProps: Props,
  _supervisor: InternalActorRef,
  _path: ActorPath)
  extends RepointableActorRef(_system, _routerProps, _routerDispatcher, _routerMailbox, _supervisor, _path) {

  // verify that a BalancingDispatcher is not used with a Router
  if (_routerProps.routerConfig != NoRouter && _routerDispatcher.isInstanceOf[BalancingDispatcher]) {
    throw new ConfigurationException(
      "Configuration for " + this +
        " is invalid - you can not use a 'BalancingDispatcher' as a Router's dispatcher, you can however use it for the routees.")
  } else _routerProps.routerConfig.verifyConfig(_path)

  override def newCell(old: UnstartedCell): Cell = {
    val cell = props.routerConfig match {
      case pool: Pool if pool.resizer.isDefined ?
        new ResizablePoolCell(system, this, props, dispatcher, _routeeProps, supervisor, pool)
      case _ ?
        new RoutedActorCell(system, this, props, dispatcher, _routeeProps, supervisor)
    }
    cell.init(sendSupervise = false, mailboxType)
  }

} 
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:45,代码来源:RoutedActorRef.scala


示例2: Registration

//设置package包名称以及导入依赖的类
package com.bob.scalatour.akka.cluster

import akka.actor.{ActorPath, ActorRef, Actor}
import akka.cluster.{Member, Cluster}
import akka.cluster.ClusterEvent.{MemberEvent, UnreachableMember, MemberUp, InitialStateAsEvents}

object Registration extends Serializable

trait EventMessage extends Serializable

case class RawNginxRecord(sourceHost: String, line: String) extends EventMessage

case class NginxRecord(sourceHost: String, eventCode: String, line: String) extends EventMessage

case class FilteredRecord(sourceHost: String, eventCode: String, line: String, logDate: String, realIp: String) extends EventMessage

abstract class ClusterRoledWorker extends Actor {

  // ????Cluster??
  val cluster = Cluster(context.system)
  // ????????????
  var workers = IndexedSeq.empty[ActorRef]

  @throws[Exception](classOf[Exception])
  override def preStart(): Unit = {
    super.preStart()
    // ??????
    cluster.subscribe(self, initialStateMode = InitialStateAsEvents, classOf[MemberUp], classOf[UnreachableMember], classOf[MemberEvent])
  }

  @throws[Exception](classOf[Exception])
  override def postStop(): Unit = {
    cluster.unsubscribe(self)
    super.postStop()
  }

  def register(member: Member, createPath: (Member) => ActorPath): Unit = {
    val actorPath = createPath(member)
    println("Actor path: " + actorPath)
    val actorSelection = context.actorSelection(actorPath)
    actorSelection ! Registration
  }

}

 
开发者ID:bobxwang,项目名称:scalatour,代码行数:45,代码来源:ClusterWorker.scala


示例3: AssemblyApp

//设置package包名称以及导入依赖的类
package csw.services.integtration.apps

import akka.actor.{Actor, ActorPath, Props}
import akka.serialization.Serialization
import csw.services.integtration.common.TestFutureExtension.RichFuture
import csw.services.location.commons.{ClusterSettings, CswCluster}
import csw.services.location.models.Connection.AkkaConnection
import csw.services.location.models.{AkkaRegistration, ComponentId, ComponentType}
import csw.services.location.scaladsl.{ActorSystemFactory, LocationServiceFactory}

object AssemblyApp {
  private val cswCluster = CswCluster.withSettings(ClusterSettings().withInterface("eth1"))

  val assemblyActorRef = ActorSystemFactory.remote.actorOf(Props[AssemblyApp], "assembly")
  val componentId      = ComponentId("assembly", ComponentType.Assembly)
  val connection       = AkkaConnection(componentId)

  val actorPath          = ActorPath.fromString(Serialization.serializedActorPath(assemblyActorRef))
  val registration       = AkkaRegistration(connection, assemblyActorRef)
  val registrationResult = LocationServiceFactory.withCluster(cswCluster).register(registration).await

  def main(args: Array[String]): Unit = {}

}

class AssemblyApp extends Actor {
  override def receive: Receive = {
    case "Unregister" => {
      AssemblyApp.registrationResult.unregister()
    }
  }
} 
开发者ID:tmtsoftware,项目名称:csw-prod,代码行数:33,代码来源:AssemblyApp.scala


示例4: JBasicLoggerActor

//设置package包名称以及导入依赖的类
package csw.services.logging.javadsl
import java.util.Optional

import akka.actor.{AbstractActor, ActorPath}
import akka.serialization.Serialization
import akka.typed.javadsl.ActorContext
import csw.services.logging.internal.JLogger
import csw.services.logging.scaladsl.LoggerImpl

import scala.compat.java8.OptionConverters.RichOptionalGeneric


abstract class JBasicLoggerActor extends AbstractActor {
  protected def maybeComponentName: Optional[String]
  protected def getLogger: ILogger = {
    val actorName = ActorPath.fromString(Serialization.serializedActorPath(getSelf)).toString
    val log       = new LoggerImpl(maybeComponentName.asScala, Some(actorName))
    new JLogger(log, getClass)
  }
}

import akka.typed.scaladsl.adapter._
abstract class JBasicLoggerTypedActor[T](actorContext: ActorContext[T])
    extends akka.typed.javadsl.Actor.MutableBehavior[T] {
  protected def maybeComponentName: Optional[String]
  protected def getLogger: ILogger = {
    val actorName = ActorPath.fromString(Serialization.serializedActorPath(actorContext.getSelf.toUntyped)).toString
    val log       = new LoggerImpl(maybeComponentName.asScala, Some(actorName))
    new JLogger(log, getClass)
  }
} 
开发者ID:tmtsoftware,项目名称:csw-prod,代码行数:32,代码来源:loggers.scala


示例5: ConnectedClientsStore

//设置package包名称以及导入依赖的类
package websocket

import akka.actor.{Actor, ActorLogging, ActorPath, ActorRef, Props, Terminated}
import core.entities.UserID
import websocket.ConnectedClientsStore._


class ConnectedClientsStore() extends Actor with ActorLogging {

  var clientsEndpoints: Map[UserID, ActorRef] = Map.empty
  var userEndpoints: Map[ActorPath, UserID]   = Map.empty

  override def receive: Receive = {

    case FindClient(userId) =>
      sender ! clientsEndpoints.get(userId).fold[ClientStoreResponse](ClientNotFound)(ClientFound)

    case ClientConnected(userId, clientEndpoint) =>
      clientsEndpoints += userId           -> clientEndpoint
      userEndpoints += clientEndpoint.path -> userId
      context.watch(clientEndpoint)

    case ClientDisconnected(userId) =>
      clientsEndpoints.get(userId).foreach(context.stop)

    case Terminated(clientEndpoint) =>
      userEndpoints.get(clientEndpoint.path).foreach { userId =>
        clientsEndpoints -= userId
        userEndpoints -= clientEndpoint.path
      }
  }
}

object ConnectedClientsStore {

  def props(): Props = Props(new ConnectedClientsStore)

  case class ClientConnected(userId: UserID, clientEndpoint: ActorRef)
  case class ClientDisconnected(userId: UserID)
  case class FindClient(userId: UserID)

  trait ClientStoreResponse
  case object ClientNotFound extends ClientStoreResponse
  case class ClientFound(endpoint: ActorRef) extends ClientStoreResponse
} 
开发者ID:lymr,项目名称:fun-chat,代码行数:46,代码来源:ConnectedClientsStore.scala


示例6: RoutedActorRef

//设置package包名称以及导入依赖的类
package akka.routing

import akka.ConfigurationException
import akka.actor.ActorPath
import akka.actor.ActorSystemImpl
import akka.actor.Cell
import akka.actor.InternalActorRef
import akka.actor.Props
import akka.actor.RepointableActorRef
import akka.actor.UnstartedCell
import akka.dispatch.BalancingDispatcher
import akka.dispatch.MailboxType
import akka.dispatch.MessageDispatcher


private[akka] class RoutedActorRef(
  _system: ActorSystemImpl,
  _routerProps: Props,
  _routerDispatcher: MessageDispatcher,
  _routerMailbox: MailboxType,
  _routeeProps: Props,
  _supervisor: InternalActorRef,
  _path: ActorPath
)
    extends RepointableActorRef(_system, _routerProps, _routerDispatcher, _routerMailbox, _supervisor, _path) {

  // verify that a BalancingDispatcher is not used with a Router
  if (_routerProps.routerConfig != NoRouter && _routerDispatcher.isInstanceOf[BalancingDispatcher]) {
    throw new ConfigurationException(
      "Configuration for " + this +
        " is invalid - you can not use a 'BalancingDispatcher' as a Router's dispatcher, you can however use it for the routees."
    )
  } else _routerProps.routerConfig.verifyConfig(_path)

  override def newCell(old: UnstartedCell): Cell = {
    val cell = props.routerConfig match {
      case pool: Pool if pool.resizer.isDefined ?
        new ResizablePoolCell(system, this, props, dispatcher, _routeeProps, supervisor, pool)
      case _ ?
        new RoutedActorCell(system, this, props, dispatcher, _routeeProps, supervisor)
    }
    cell.init(sendSupervise = false, mailboxType)
  }

} 
开发者ID:rorygraves,项目名称:perf_tester,代码行数:46,代码来源:RoutedActorRef.scala


示例7: Main

//设置package包名称以及导入依赖的类
package hu.jonas.client

import akka.actor.{Actor, ActorLogging, ActorPath, ActorSystem, Props}
import akka.cluster.Cluster
import akka.cluster.ClusterEvent.{InitialStateAsEvents, MemberEvent, MemberUp, UnreachableMember}
import akka.cluster.client.{ClusterClient, ClusterClientSettings}
import com.typesafe.config.ConfigFactory
import hu.jonas.cluster.ClusterController

object Main extends App {

  val system = ActorSystem("Cluster", ConfigFactory.load("client"))

  val client = system.actorOf(Props[Client], "Proxy")
}

class Client extends Actor with ActorLogging {

  val cluster = Cluster(context.system)

  val initialContacts = Set(
    ActorPath.fromString("akka.tcp://[email protected]:2551/system/receptionist"))

  val setting = ClusterClientSettings(context.system).withInitialContacts(initialContacts)
  val client = context.system.actorOf(ClusterClient.props(setting), "Client")

  def send(msg: Any): Unit = {
      client ! ClusterClient.Send("/user/Controller", msg, localAffinity = true)
  }

  override def preStart() = {
    cluster.subscribe(self, initialStateMode = InitialStateAsEvents,
      classOf[MemberEvent], classOf[UnreachableMember])
  }

  override def postStop() = {
    cluster.unsubscribe(self)
  }

  def receive = {
    case MemberUp(member) =>
      log.info("Member is up")
      send(ClusterController.Status)
    case msg @ _ =>
      log.info(s"Got message $msg")
  }
} 
开发者ID:jonasrichard,项目名称:simple-cluster,代码行数:48,代码来源:Client.scala


示例8: MqttDispatchingListener

//设置package包名称以及导入依赖的类
package mqtt

import akka.actor.{ActorPath, ActorSystem}
import mqtt.MqttListenerMessage.ConsumeMessage
import org.eclipse.paho.client.mqttv3.{IMqttDeliveryToken, MqttCallback, MqttMessage}
import play.api.Logger


class MqttDispatchingListener(actorSystem: ActorSystem) extends MqttCallback {
  var listeners: List[ActorPath] = List.empty

  override def deliveryComplete(token: IMqttDeliveryToken): Unit = {}
  override def connectionLost(cause: Throwable): Unit = {}

  def addListener(listener:ActorPath): Unit = {
    listeners = listener :: listeners
  }

  override def messageArrived(topic: String, message: MqttMessage): Unit = {
    val msgStr = new String(message.getPayload)
    Logger.debug(s"Mqtt topic $topic received $msgStr")

    listeners.foreach(actorSystem.actorSelection(_) ! ConsumeMessage(topic, msgStr))
  }
}

object MqttListenerMessage {
  case class Ping()
  case class ConsumeMessage(receivedTopic: String, message: String)
} 
开发者ID:vavravl1,项目名称:home_center,代码行数:31,代码来源:MqttDispatchingListener.scala


示例9: GreetingActor

//设置package包名称以及导入依赖的类
import akka.actor.{Actor, ActorPath, ActorSystem, Props}


object GreetingActor extends App {
  case class Name(name: String)
  class GreetingActor extends Actor {
    def receive = {
      case Name(n) => {
        println()
        println("Hello " + n)
        println("sender is " + sender.toString())
        println("actor system name is " + context.system.name)
        println()
      }
    }

    // if the message did not match any pattern in the receive method
    override def unhandled(message: Any): Unit = {
      println("unhandled: " + message)
      println("sender is " + sender.toString())
      self ! Name("who am i?")
    }

    override def preStart(): Unit = {
      println("initiating resources...")
    }

    override def postStop(): Unit = {
      println("The actor has stopped!")
    }
  }

  val system = ActorSystem("greetings")
  system.actorOf(Props[GreetingActor], name = "greetings-actor")
  val path:ActorPath = system / "greetings-actor"
  val b = system.actorSelection(path)

  b ! Name("JHDFOE")
  b ! "RECALL TO LIFE"
  Thread.sleep(50)
  system.shutdown()
} 
开发者ID:missbrown,项目名称:sbtInActionProject,代码行数:43,代码来源:GreetingActor.scala


示例10: ActorSystems

//设置package包名称以及导入依赖的类
package akkaviz.events

import akka.actor.{ActorPath, ActorRef, ActorSystem}
import akka.viz.ActorCellInstrumentation

import scala.collection.breakOut
import scala.ref.WeakReference
import scala.util.Try

object ActorSystems {

  private[this] val systemReferences = scala.collection.mutable.Map[String, WeakReference[ActorSystem]]()

  def systems: scala.collection.immutable.Map[String, ActorSystem] = systemReferences.flatMap {
    case (name, ref) => ref.get.map {
      system => name -> system
    }
  }(breakOut)

  def registerSystem(system: ActorSystem): Unit = {
    systemReferences.update(system.name, WeakReference(system))
  }

  def tell(path: String, message: Any): Unit = {
    Try {
      val actorPath = ActorPath.fromString(path)
      systems.get(actorPath.address.system).foreach {
        system =>
          system.actorSelection(actorPath).tell(message, ActorRef.noSender)
      }
    }
  }

  def refreshActorState(path: String): Unit = {
    tell(path, ActorCellInstrumentation.RefreshInternalStateMsg)
  }

} 
开发者ID:blstream,项目名称:akka-viz,代码行数:39,代码来源:ActorSystems.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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