make unbalanced Address() constructor private, fix parsing, see #1806
This commit is contained in:
parent
9b9378c2f8
commit
669a4ff9ca
7 changed files with 27 additions and 24 deletions
|
|
@ -305,6 +305,7 @@ class ActorLookupSpec extends AkkaSpec with DefaultTimeout {
|
|||
intercept[MalformedURLException] { ActorPath.fromString("://hallo") }
|
||||
intercept[MalformedURLException] { ActorPath.fromString("s://dd@:12") }
|
||||
intercept[MalformedURLException] { ActorPath.fromString("s://dd@h:hd") }
|
||||
intercept[MalformedURLException] { ActorPath.fromString("a://l:1/b") }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import java.net.MalformedURLException
|
|||
* for example a remote transport would want to associate additional
|
||||
* information with an address, then this must be done externally.
|
||||
*/
|
||||
final case class Address(protocol: String, system: String, host: Option[String], port: Option[Int]) {
|
||||
final case class Address private (protocol: String, system: String, host: Option[String], port: Option[Int]) {
|
||||
|
||||
def this(protocol: String, system: String) = this(protocol, system, None, None)
|
||||
def this(protocol: String, system: String, host: String, port: Int) = this(protocol, system, Option(host), Some(port))
|
||||
|
|
@ -62,19 +62,24 @@ object RelativeActorPath {
|
|||
* This object serves as extractor for Scala and as address parser for Java.
|
||||
*/
|
||||
object AddressExtractor {
|
||||
def unapply(addr: String): Option[Address] = {
|
||||
def unapply(addr: String): Option[Address] =
|
||||
try {
|
||||
val uri = new URI(addr)
|
||||
if (uri.getScheme == null || (uri.getUserInfo == null && uri.getHost == null)) None
|
||||
else {
|
||||
val addr = Address(uri.getScheme, if (uri.getUserInfo != null) uri.getUserInfo else uri.getHost,
|
||||
if (uri.getUserInfo == null || uri.getHost == null) None else Some(uri.getHost),
|
||||
if (uri.getPort < 0) None else Some(uri.getPort))
|
||||
Some(addr)
|
||||
}
|
||||
unapply(uri)
|
||||
} catch {
|
||||
case _: URISyntaxException ⇒ None
|
||||
}
|
||||
|
||||
def unapply(uri: URI): Option[Address] =
|
||||
if (uri.getScheme == null || (uri.getUserInfo == null && uri.getHost == null)) None
|
||||
else if (uri.getUserInfo == null) { // case 1: “akka://system”
|
||||
if (uri.getPort != -1) None
|
||||
else Some(Address(uri.getScheme, uri.getHost))
|
||||
} else { // case 2: “akka://system@host:port”
|
||||
if (uri.getHost == null || uri.getPort == -1) None
|
||||
else Some(
|
||||
if (uri.getUserInfo == null) Address(uri.getScheme, uri.getHost)
|
||||
else Address(uri.getScheme, uri.getUserInfo, uri.getHost, uri.getPort))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -92,18 +97,15 @@ object AddressExtractor {
|
|||
}
|
||||
|
||||
object ActorPathExtractor {
|
||||
def unapply(addr: String): Option[(Address, Iterable[String])] = {
|
||||
def unapply(addr: String): Option[(Address, Iterable[String])] =
|
||||
try {
|
||||
val uri = new URI(addr)
|
||||
if (uri.getScheme == null || (uri.getUserInfo == null && uri.getHost == null) || uri.getPath == null) None
|
||||
else {
|
||||
val addr = Address(uri.getScheme, if (uri.getUserInfo != null) uri.getUserInfo else uri.getHost,
|
||||
if (uri.getUserInfo == null || uri.getHost == null) None else Some(uri.getHost),
|
||||
if (uri.getPort < 0) None else Some(uri.getPort))
|
||||
Some((addr, ActorPath.split(uri.getPath).drop(1)))
|
||||
if (uri.getPath == null) None
|
||||
else AddressExtractor.unapply(uri) match {
|
||||
case None ⇒ None
|
||||
case Some(addr) ⇒ Some((addr, ActorPath.split(uri.getPath).drop(1)))
|
||||
}
|
||||
} catch {
|
||||
case _: URISyntaxException ⇒ None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ class RemoteDeploymentDocSpec extends AkkaSpec("""
|
|||
import RemoteDeploymentDocSpec._
|
||||
|
||||
val other = ActorSystem("remote", system.settings.config)
|
||||
val address = other.asInstanceOf[ExtendedActorSystem].provider.getExternalAddressFor(Address("akka", "s", Some("host"), Some(1))).get
|
||||
val address = other.asInstanceOf[ExtendedActorSystem].provider.getExternalAddressFor(Address("akka", "s", "host", 1)).get
|
||||
|
||||
override def atTermination() { other.shutdown() }
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class NettyRemoteTransport(val remoteSettings: RemoteSettings, val system: Actor
|
|||
case sa: InetSocketAddress ⇒ sa
|
||||
case x ⇒ throw new RemoteTransportException("unknown local address type " + x.getClass, null)
|
||||
}
|
||||
_address.compareAndSet(null, Address("akka", remoteSettings.systemName, Some(settings.Hostname), Some(addr.getPort)))
|
||||
_address.compareAndSet(null, Address("akka", remoteSettings.systemName, settings.Hostname, addr.getPort))
|
||||
}
|
||||
|
||||
def address = _address.get
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ class RemoteServerHandler(
|
|||
instruction.getCommandType match {
|
||||
case CommandType.CONNECT if settings.UsePassiveConnections ⇒
|
||||
val origin = instruction.getOrigin
|
||||
val inbound = Address("akka", origin.getSystem, Some(origin.getHostname), Some(origin.getPort))
|
||||
val inbound = Address("akka", origin.getSystem, origin.getHostname, origin.getPort)
|
||||
val client = new PassiveRemoteClient(event.getChannel, netty, inbound)
|
||||
netty.bindClient(inbound, client)
|
||||
case CommandType.SHUTDOWN ⇒ //Will be unbound in channelClosed
|
||||
|
|
@ -203,7 +203,7 @@ class RemoteServerHandler(
|
|||
|
||||
private def getClientAddress(c: Channel): Option[Address] =
|
||||
c.getRemoteAddress match {
|
||||
case inet: InetSocketAddress ⇒ Some(Address("akka", "unknown(yet)", Some(inet.getAddress.toString), Some(inet.getPort)))
|
||||
case inet: InetSocketAddress ⇒ Some(Address("akka", "unknown(yet)", inet.getAddress.toString, inet.getPort))
|
||||
case _ ⇒ None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class RemoteDeployerSpec extends AkkaSpec(RemoteDeployerSpec.deployerConf) {
|
|||
service,
|
||||
deployment.get.config,
|
||||
RoundRobinRouter(3),
|
||||
RemoteScope(Address("akka", "sys", Some("wallace"), Some(2552))))))
|
||||
RemoteScope(Address("akka", "sys", "wallace", 2552)))))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ akka.actor.deployment {
|
|||
children must have size 2
|
||||
val parents = children.map(_.parent)
|
||||
parents must have size 1
|
||||
parents.head.address must be(Address("akka", "remote_sys", Some("localhost"), Some(12347)))
|
||||
parents.head.address must be(Address("akka", "remote_sys", "localhost", 12347))
|
||||
children foreach (_.address.toString must be === "akka://remote_sys@localhost:12347")
|
||||
system.stop(router)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue