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