Skip to content

Latest commit

 

History

History
32 lines (20 loc) · 908 Bytes

6.Actor路径是怎么表示的.MD

File metadata and controls

32 lines (20 loc) · 908 Bytes
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))

  def hasLocalScope: Boolean = host.isEmpty

  def hasGlobalScope: Boolean = host.isDefined

  @transient override lazy val hashCode: Int = scala.util.hashing.MurmurHash3.productHash(this)

  /**
   * `protocol://system@host:port`
   */
  @transient
  override lazy val toString: String = {
    val sb = (new java.lang.StringBuilder(protocol)).append("://").append(system)

    if (host.isDefined) sb.append('@').append(host.get)
    if (port.isDefined) sb.append(':').append(port.get)

    sb.toString
  }

  def hostPort: String = toString.substring(protocol.length + 3)
}