=rem #15007 add ability to bind to a different address than the remoting waits messages from

This can be used to traverse NATs with the following configuration:

akka.remote.netty.tcp {
  ...
  hostname = my-external-address.lt
  bind-hostname = 192.168.1.100
}

Use Akka BoundAddressesExtension to get bound addresses
This commit is contained in:
Martynas Mickevicius 2014-09-15 18:30:12 +03:00
parent 60ab0fb3d0
commit 47556a0ebf
13 changed files with 328 additions and 24 deletions

View file

@ -0,0 +1,32 @@
/**
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.remote
import akka.actor.ActorSystem
import akka.actor.Address
import akka.actor.ExtendedActorSystem
import akka.actor.Extension
import akka.actor.ExtensionId
import akka.actor.ExtensionIdProvider
/**
* Extension provides access to bound addresses.
*/
object BoundAddressesExtension extends ExtensionId[BoundAddressesExtension] with ExtensionIdProvider {
override def get(system: ActorSystem): BoundAddressesExtension = super.get(system)
override def lookup = BoundAddressesExtension
override def createExtension(system: ExtendedActorSystem): BoundAddressesExtension =
new BoundAddressesExtension(system)
}
class BoundAddressesExtension(val system: ExtendedActorSystem) extends Extension {
/**
* Returns a mapping from a protocol to a set of bound addresses.
*/
def boundAddresses: Map[String, Set[Address]] = system.provider
.asInstanceOf[RemoteActorRefProvider].transport
.asInstanceOf[Remoting].boundAddresses
}