pekko/akka-actor/src/main/scala/akka/actor/Address.scala
2012-01-19 18:21:06 +01:00

45 lines
No EOL
1.2 KiB
Scala
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 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)
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
}
}
}