Packages

  • package root
    Definition Classes
    root
  • package com
    Definition Classes
    root
  • package twitter

    Start with com.twitter.finagle.

    Definition Classes
    com
  • package finagle

    Finagle is an extensible RPC system.

    Finagle is an extensible RPC system.

    Services are represented by class com.twitter.finagle.Service. Clients make use of com.twitter.finagle.Service objects while servers implement them.

    Finagle contains a number of protocol implementations; each of these implement Client and/or com.twitter.finagle.Server. For example, Finagle's HTTP implementation, com.twitter.finagle.Http (in package finagle-http), exposes both.

    Thus a simple HTTP server is built like this:

    import com.twitter.finagle.{Http, Service}
    import com.twitter.finagle.http.{Request, Response}
    import com.twitter.util.{Await, Future}
    
    val service = new Service[Request, Response] {
      def apply(req: Request): Future[Response] =
        Future.value(Response())
    }
    val server = Http.server.serve(":8080", service)
    Await.ready(server)

    We first define a service to which requests are dispatched. In this case, the service returns immediately with a HTTP 200 OK response, and with no content.

    This service is then served via the Http protocol on TCP port 8080. Finally we wait for the server to stop serving.

    We can now query our web server:

    % curl -D - localhost:8080
    HTTP/1.1 200 OK

    Building an HTTP client is also simple. (Note that type annotations are added for illustration.)

    import com.twitter.finagle.{Http, Service}
    import com.twitter.finagle.http.{Request, Response}
    import com.twitter.util.{Future, Return, Throw}
    
    val client: Service[Request, Response] = Http.client.newService("localhost:8080")
    val f: Future[Response] = client(Request()).respond {
      case Return(rep) =>
        printf("Got HTTP response %s\n", rep)
      case Throw(exc) =>
        printf("Got error %s\n", exc)
    }

    Http.client.newService("localhost:8080") constructs a new com.twitter.finagle.Service instance connected to localhost TCP port 8080. We then issue a HTTP/1.1 GET request to URI "/". The service returns a com.twitter.util.Future representing the result of the operation. We listen to this future, printing an appropriate message when the response arrives.

    The Finagle homepage contains useful documentation and resources for using Finagle.

    Definition Classes
    twitter
  • package addr
    Definition Classes
    finagle
  • package builder
    Definition Classes
    finagle
  • ClientBuilder
  • ClientConfig
  • ClientConfigEvidence
  • IncompleteSpecification
  • ServerBuilder
  • ServerConfig
  • ServerConfigEvidence
  • SourceTrackingMonitor
  • package client
    Definition Classes
    finagle
  • package context
    Definition Classes
    finagle
  • package core
    Definition Classes
    finagle
  • package dispatch
    Definition Classes
    finagle
  • package exp

    Package exp contains experimental code.

    Package exp contains experimental code. This can be removed or stabilized (moved elsewhere) at any time.

    Definition Classes
    finagle
  • package factory
    Definition Classes
    finagle
  • package filter
    Definition Classes
    finagle
  • package liveness
    Definition Classes
    finagle
  • package loadbalancer

    This package implements client side load balancing algorithms.

    This package implements client side load balancing algorithms.

    As an end-user, see the Balancers API to create instances which can be used to configure a Finagle client with various load balancing strategies.

    As an implementor, each algorithm gets its own subdirectory and is exposed via the Balancers object. Several convenient traits are provided which factor out common behavior and can be mixed in (i.e. Balancer, DistributorT, NodeT, and Updating).

    Definition Classes
    finagle
  • package namer
    Definition Classes
    finagle
  • package naming
    Definition Classes
    finagle
  • package offload
    Definition Classes
    finagle
  • package param

    Defines common com.twitter.finagle.Stack.Param's shared between finagle clients and servers.

    Defines common com.twitter.finagle.Stack.Param's shared between finagle clients and servers.

    Definition Classes
    finagle
  • package pool
    Definition Classes
    finagle
  • package pushsession
    Definition Classes
    finagle
  • package server
    Definition Classes
    finagle
  • package service
    Definition Classes
    finagle
  • package ssl
    Definition Classes
    finagle
  • package stats
    Definition Classes
    finagle
  • package thrift
    Definition Classes
    finagle
  • package tracing
    Definition Classes
    finagle
  • package transport
    Definition Classes
    finagle
  • package util
    Definition Classes
    finagle

package builder

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

  1. class ClientBuilder[Req, Rep, HasCluster, HasCodec, HasHostConnectionLimit] extends AnyRef

    A builder of Finagle Clients.

    A builder of Finagle Clients.

    Please see the user guide for information on the preferred with-style and MethodBuilder client-construction APIs.

    val client = ClientBuilder()
      .stack(Http.client)
      .hosts("localhost:10000,localhost:10001,localhost:10003")
      .hostConnectionLimit(1)
      .tcpConnectTimeout(1.second)        // max time to spend establishing a TCP connection.
      .retries(2)                         // (1) per-request retries
      .reportTo(DefaultStatsReceiver)     // export host-level load data to the loaded-StatsReceiver
      .build()

    The ClientBuilder requires the definition of cluster, stack, and hostConnectionLimit. In Scala, these are statically type checked, and in Java the lack of any of the above causes a runtime error.

    The build method uses an implicit argument to statically typecheck the builder (to ensure completeness, see above). The Java compiler cannot provide such implicit, so we provide a separate function in Java to accomplish this. Thus, the Java code for the above is

    Service<HttpRequest, HttpResponse> service =
     ClientBuilder.safeBuild(
       ClientBuilder.get()
         .stack(Http.client())
         .hosts("localhost:10000,localhost:10001,localhost:10003")
         .hostConnectionLimit(1)
         .tcpConnectTimeout(1.second)
         .retries(2)
         .reportTo(DefaultStatsReceiver)

    Alternatively, using the unsafeBuild method on ClientBuilder verifies the builder dynamically, resulting in a runtime error instead of a compiler error.

    Defaults

    The following defaults are applied to clients constructed via ClientBuilder, unless overridden with the corresponding method. These defaults were chosen carefully so as to work well for most use cases.

    Commonly-configured options:

    • connectTimeout: Duration.Top
    • tcpConnectTimeout: 1 second
    • requestTimeout: Duration.Top
    • timeout: Duration.Top
    • hostConnectionLimit: Int.MaxValue
    • hostConnectionCoresize: 0
    • hostConnectionIdleTime: Duration.Top
    • hostConnectionMaxWaiters: Int.MaxValue
    • failFast: true
    • failureAccrualParams, failureAccrualFactory: numFailures = 5, markDeadFor = 5 seconds

    Advanced options:

    Before changing any of these, make sure that you know exactly how they will affect your application -- these options are typically only changed by expert users.

    • keepAlive: Unspecified, in which case the Java default of false is used
    • hostConnectionMaxIdleTime: Duration.Top
    • hostConnectionMaxLifeTime: Duration.Top
    See also

    The user guide for information on the preferred with-style and MethodBuilder client-construction APIs.

  2. trait ClientConfigEvidence[HasCluster, HasCodec, HasHostConnectionLimit] extends AnyRef
    Annotations
    @implicitNotFound("Builder is not fully configured: Cluster: ${HasCluster}, Codec: ${HasCodec}, HostConnectionLimit: ${HasHostConnectionLimit}")
  3. class IncompleteSpecification extends Exception

    Used by builder to throw exceptions if the specification is incomplete.

    Used by builder to throw exceptions if the specification is incomplete.

    if (!_codec.isDefined)
      throw new IncompleteSpecification("No codec was specified")
  4. class ServerBuilder[Req, Rep, HasCodec, HasBindTo, HasName] extends AnyRef

    A handy Builder for constructing Servers (i.e., binding Services to a port).

    A handy Builder for constructing Servers (i.e., binding Services to a port). This class is subclassable. Override copy() and build() to do your own dirty work.

    Please see the Finagle user guide for information on the preferred with-style client-construction APIs.

    The main class to use is com.twitter.finagle.builder.ServerBuilder, as so

    ServerBuilder()
      .stack(Http.server)
      .hostConnectionMaxLifeTime(5.minutes)
      .readTimeout(2.minutes)
      .name("servicename")
      .bindTo(new InetSocketAddress(serverPort))
      .build(plusOneService)

    The ServerBuilder requires the definition of stack, bindTo and name. In Scala, these are statically type checked, and in Java the lack of any of the above causes a runtime error.

    The build method uses an implicit argument to statically typecheck the builder (to ensure completeness, see above). The Java compiler cannot provide such implicit, so we provide a separate function in Java to accomplish this. Thus, the Java code for the above is

    ServerBuilder.safeBuild(
     plusOneService,
     ServerBuilder.get()
      .stack(Http.server())
      .hostConnectionMaxLifeTime(5.minutes)
      .readTimeout(2.minutes)
      .name("servicename")
      .bindTo(new InetSocketAddress(serverPort)));

    Alternatively, using the unsafeBuild method on ServerBuilder verifies the builder dynamically, resulting in a runtime error instead of a compiler error.

    Defaults

    The following defaults are applied to servers constructed via ServerBuilder, unless overridden with the corresponding method. These defaults were chosen carefully so as to work well for most use cases. Before changing any of them, make sure that you know exactly how they will affect your application -- these options are typically only changed by expert users.

    - openConnectionsThresholds: None - maxConcurrentRequests: Int.MaxValue - backlog: OS-defined default value

    See also

    The user guide for information on the preferred with-style APIs insead.

  5. trait ServerConfigEvidence[HasCodec, HasBindTo, HasName] extends AnyRef
    Annotations
    @implicitNotFound("Builder is not fully configured: Codec: ${HasCodec}, BindTo: ${HasBindTo}, Name: ${HasName}")
  6. class SourceTrackingMonitor extends Monitor

    A monitor that unrolls the exception causes to report source information if any

Ungrouped