2011-11-24 16:58:23 +01:00
|
|
|
|
/**
|
2012-01-19 18:21:06 +01:00
|
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
2011-11-24 16:58:23 +01:00
|
|
|
|
*/
|
|
|
|
|
|
package akka.actor
|
2011-11-29 16:32:50 +01:00
|
|
|
|
import java.net.URI
|
|
|
|
|
|
import java.net.URISyntaxException
|
2011-11-24 16:58:23 +01:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The address specifies the physical location under which an Actor can be
|
|
|
|
|
|
* reached. Examples are local addresses, identified by the ActorSystem’s
|
|
|
|
|
|
* 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
|
2011-11-29 16:32:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-12-03 11:06:38 +01:00
|
|
|
|
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))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-11-29 16:32:50 +01:00
|
|
|
|
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))
|
2011-11-29 16:32:50 +01:00
|
|
|
|
} catch {
|
|
|
|
|
|
case _: URISyntaxException ⇒ None
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2011-11-24 16:58:23 +01:00
|
|
|
|
}
|