pekko/akka-actor/src/main/scala/akka/actor/Address.scala

45 lines
1.2 KiB
Scala
Raw Normal View History

/**
2012-01-19 18:21:06 +01:00
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.actor
import java.net.URI
import java.net.URISyntaxException
/**
* The address specifies the physical location under which an Actor can be
* reached. Examples are local addresses, identified by the ActorSystems
* name, and remote addresses, identified by protocol, host and port.
*/
abstract class Address {
def protocol: String
def hostPort: String
@transient
override lazy val toString = protocol + "://" + hostPort
}
case class LocalAddress(systemName: String) extends Address {
def protocol = "akka"
def hostPort = systemName
}
object RelativeActorPath {
def unapply(addr: String): Option[Iterable[String]] = {
try {
val uri = new URI(addr)
if (uri.isAbsolute) None
else Some(ActorPath.split(uri.getPath))
}
}
}
object LocalActorPath {
def unapply(addr: String): Option[(LocalAddress, Iterable[String])] = {
try {
val uri = new URI(addr)
2011-12-05 17:31:54 +01:00
if (uri.getScheme != "akka" || uri.getUserInfo != null || uri.getHost == null || uri.getPath == null) None
else Some(LocalAddress(uri.getHost), ActorPath.split(uri.getPath).drop(1))
} catch {
case _: URISyntaxException None
}
}
}