def bound()

in finagle-core/src/main/scala/com/twitter/finagle/Name.scala [106:181]


  def bound(addrs: Address*): Name.Bound =
    Name.Bound(Var.value(Addr.Bound(addrs: _*)), addrs.toSet)

  /**
   * Create a pre-bound [[Address]] which points directly to the provided [[Service]].
   *
   * @note This method can be extremely useful in testing the functionality of a Finagle
   * client without involving the network.
   *
   * {{{
   *   import com.twitter.conversions.DurationOps._
   *   import com.twitter.finagle.{Http, Name, Service}
   *   import com.twitter.finagle.http.{Request, Response, Status}
   *   import com.twitter.util.{Await, Future}
   *
   *   val service: Service[Request, Response] = Service.mk { request =>
   *     val response = Response()
   *     response.status = Status.Ok
   *     response.contentString = "Hello"
   *     Future.value(response)
   *   }
   *   val name = Name.bound(service)
   *   val client = Http.client.newService(name, "hello-service-example")
   *   val result = Await.result(client(Request("/")), 1.second)
   *   result.contentString // "Hello"
   * }}}
   */
  def bound[Req, Rep](service: Service[Req, Rep]): Name.Bound =
    bound(Address.ServiceFactory[Req, Rep](ServiceFactory.const(service)))

  /**
   * An always-empty name.
   * @see [[Names.empty]] for Java compatibility.
   */
  val empty: Name.Bound = bound()

  /**
   * Create a path-based Name which is interpreted vis-à-vis
   * the current request-local delegation table.
   * @see [[Names.fromPath]] for Java compatibility.
   */
  def apply(path: com.twitter.finagle.Path): Name =
    Name.Path(path)

  /**
   * Create a path-based Name which is interpreted vis-à-vis
   * the current request-local delegation table.
   * @see [[Names.fromPath]] for Java compatibility.
   */
  def apply(path: String): Name =
    Name.Path(com.twitter.finagle.Path.read(path))

  // Create a name representing the union of the passed-in names.
  // Metadata is not preserved on bound addresses.
  private[finagle] def all(names: Set[Name.Bound]): Name.Bound =
    if (names.isEmpty) empty
    else if (names.size == 1) names.head
    else {
      val va = Var.collect(names.view.map(_.addr).toSeq) map {
        case addrs if addrs.exists({ case Addr.Bound(_, _) => true; case _ => false }) =>
          val endpointAddrs = addrs.view.flatMap {
            case Addr.Bound(as, _) => as
            case _ => Seq.empty[Address]
          }
          Addr.Bound(endpointAddrs.toSet, Addr.Metadata.empty)

        case addrs if addrs.forall(_ == Addr.Neg) => Addr.Neg
        case addrs if addrs.forall({ case Addr.Failed(_) => true; case _ => false }) =>
          Addr.Failed(new Exception)

        case _ => Addr.Pending
      }

      val id = names map { case bound @ Name.Bound(_) => bound.id }
      Name.Bound(va, id)
    }