Skip to content

Commit

Permalink
Added scope query methods to Address.
Browse files Browse the repository at this point in the history
  • Loading branch information
Endre Sándor Varga committed Jan 4, 2013
1 parent 58324eb commit dc5f835
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion akka-actor/src/main/scala/akka/actor/Address.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,27 @@ import scala.collection.immutable
*/
@SerialVersionUID(1L)
final case class Address private (protocol: String, system: String, host: Option[String], port: Option[Int]) {
// Please note that local/non-local distinction must be preserved: host.isDefined == !isLocal
// Please note that local/non-local distinction must be preserved:
// host.isDefined == hasGlobalScope
// host.isEmpty == hasLocalScope
// hasLocalScope == !hasGlobalScope

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))

/**
* Returns true if this Address is only defined locally. It is not safe to send locally scoped addresses to remote
* hosts. See also [[akka.actor.Address#hasGlobalScope]].
*/
def hasLocalScope: Boolean = host.isEmpty

/**
* Returns true if this Address is usable globally. Unlike locally defined addresses ([[akka.actor.Address#hasLocalScope]])
* addresses of global scope are safe to sent to other hosts, as they globally and uniquely identify an addressable
* entity.
*/
def hasGlobalScope: Boolean = host.isDefined

/**
* Returns the canonical String representation of this Address formatted as:
*
Expand Down

0 comments on commit dc5f835

Please sign in to comment.