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 thrift

    Please use the new interface, com.twitter.finagle.Thrift, for constructing Thrift clients and servers.

    Deprecation

    Please use the new interface, com.twitter.finagle.Thrift, for constructing Thrift clients and servers.

    Thrift codecs

    We provide client and server protocol support for the framed protocol. The public implementations are defined on the Thrift object:

    The type of the server codec is Service[Array[Byte], Array[Byte]] and the client codecs are Service[ThriftClientRequest, Array[Byte]]. The service provided is that of a "transport" of thrift messages (requests and replies) according to the protocol chosen. This is why the client codecs need to have access to a thrift ProtocolFactory.

    These transports are used by the services produced by the finagle thrift codegenerator.

    val service: Service[ThriftClientRequest, Array[Byte]] = ClientBuilder()
      .hosts("foobar.com:123")
      .stack(Thrift.client)
      .build()
    
    // Wrap the raw Thrift transport in a Client decorator. The client
    // provides a convenient procedural interface for accessing the Thrift
    // server.
    val client = new Hello.ServiceToClient(service, protocolFactory)

    In this example, Hello is the thrift interface, and the inner class ServiceToClient is provided by the finagle thrift code generator.

    Definition Classes
    finagle
  • package exp
    Definition Classes
    thrift
  • package filter
    Definition Classes
    thrift
  • package scribe
    Definition Classes
    thrift
  • package service
    Definition Classes
    thrift
  • Filterable
  • MethodPerEndpointBuilder
  • ReqRepMethodPerEndpointBuilder
  • ReqRepServicePerEndpointBuilder
  • ServicePerEndpointBuilder
  • ThriftCodec
  • ThriftReqRepServicePerEndpoint
  • ThriftResponseClassifier
  • ThriftServicePerEndpoint
  • package thrift
    Definition Classes
    thrift
  • package thriftscala
    Definition Classes
    thrift

package service

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. Protected

Type Members

  1. trait Filterable[+T] extends service.Filterable[T]

    Used in conjunction with a ServicePerEndpoint builder to allow for filtering of a ServicePerEndpoint.

  2. trait MethodPerEndpointBuilder[ServicePerEndpoint, MethodPerEndpoint] extends AnyRef

    A typeclass to construct a MethodPerEndpoint by wrapping a ServicePerEndpoint.

    A typeclass to construct a MethodPerEndpoint by wrapping a ServicePerEndpoint. This is a compatibility constructor to replace an existing Future interface with one built from a ServicePerEndpoint.

    Scrooge generates implementations of this builder.

  3. trait ReqRepMethodPerEndpointBuilder[ReqRepServicePerEndpoint, MethodPerEndpoint] extends MethodPerEndpointBuilder[ReqRepServicePerEndpoint, MethodPerEndpoint]

    A typeclass to construct a MethodPerEndpoint by wrapping a ReqRepServicePerEndpoint.

    A typeclass to construct a MethodPerEndpoint by wrapping a ReqRepServicePerEndpoint.

    This is a compatibility constructor to replace an existing Future interface with one built from a ReqRepServicePerEndpoint.

    Scrooge generates implementations of this builder.

  4. trait ReqRepServicePerEndpointBuilder[ReqRepServicePerEndpoint <: Filterable[ReqRepServicePerEndpoint]] extends ServicePerEndpointBuilder[ReqRepServicePerEndpoint]

    Typeclass ReqRepServicePerEndpointBuilder[T] creates T-typed interfaces from thrift clients.

    Typeclass ReqRepServicePerEndpointBuilder[T] creates T-typed interfaces from thrift clients.

    Scrooge generates implementations of this builder.

  5. trait ServicePerEndpointBuilder[ServicePerEndpoint <: Filterable[ServicePerEndpoint]] extends AnyRef

    Typeclass ServicePerEndpointBuilder[T] creates T-typed interfaces from thrift clients.

    Typeclass ServicePerEndpointBuilder[T] creates T-typed interfaces from thrift clients. Scrooge generates implementations of this builder.

Value Members

  1. object ThriftCodec
  2. object ThriftReqRepServicePerEndpoint

    Construct Service[scrooge.Request[method.Args],scrooge.Response[method.SuccessType]] interface for a ThriftMethod.

    Construct Service[scrooge.Request[method.Args],scrooge.Response[method.SuccessType]] interface for a ThriftMethod.

    There are two ways to use a Scrooge-generated Thrift Service with Finagle:

    1. Using a Service interface, i.e. a collection of Finagle Services, e.g., ReqRepServicePerEndpoint.

    2. Using a method interface, i.e. a collection of methods returning Futures, e.g, MethodPerEndpoint.

    Example: for a Thrift service IDL:

    service Logger {
      string log(1: string message, 2: i32 logLevel);
      i32 getLogSize();
    }

    the Service interface, or ReqRepServicePerEndpoint, is

    trait LoggerServiceIface {
      val log: com.twitter.finagle.Service[scrooge.Request[Logger.Log.Args], scrooge.Response[Logger.Log.SuccessType]]
      val getLogSize: com.twitter.finagle.Service[[scrooge.Request[Logger.GetLogSize.Args], scrooge.Response[Logger.GetLogSize.SuccessType]]
    }

    and the method interface, or MethodPerEndpoint, is

    trait Logger.MethodPerEndpoint {
      def log(message: String, logLevel: Int): Future[String]
      def getLogSize(): Future[Int]
    }

    ReqRepServicePerEndpoints can be modified and composed with Finagle Filters.

  3. object ThriftResponseClassifier

    ResponseClassifiers for use with finagle-thrift request/responses.

    ResponseClassifiers for use with finagle-thrift request/responses.

    Thrift (and ThriftMux) services are a bit unusual in that there is only a single Service from Array[Byte] to Array[Byte] for all the methods of an IDL's service.

    Thrift classifiers should be written in terms of the Scrooge generated request $Service.$Method.Args type and the method's response type. This is because there is support in Scrooge and Thrift.newService/newClient to deserialize the responses into the expected application types so that classifiers can be written in a normal way.

    Given an idl:

    exception NotFoundException { 1: string reason }
    exception RateLimitedException { 1: string reason }
    
    service SocialGraph {
      i32 follow(1: i64 follower, 2: i64 followee) throws (
        1: NotFoundException ex, 2: RateLimitedException ex
      )
    }
    

    One possible custom classifier would be:

    val classifier: ResponseClassifier = {
      case ReqRep(_, Throw(_: RateLimitedException)) => RetryableFailure
      case ReqRep(_, Throw(_: NotFoundException)) => NonRetryableFailure
      case ReqRep(_, Return(x: Int)) if x == 0 => NonRetryableFailure
      case ReqRep(SocialGraph.Follow.Args(a, b), _) if a <= 0 || b <= 0 => NonRetryableFailure // avoid this style!
    }

    Often times, a good default classifier is ThriftResponseClassifier.ThriftExceptionsAsFailures which treats any Thrift response that deserializes into an Exception as a non-retryable failure.

    See also

    The user guide for more information on Response Classification of Thrift and ThriftMux Clients and Servers.

  4. object ThriftServicePerEndpoint

    Construct Service interface for a Thrift method.

    Construct Service interface for a Thrift method.

    There are two ways to use a Scrooge-generated Thrift Service with Finagle:

    1. Using a Service interface, i.e. a collection of Finagle Services.

    2. Using a method interface, i.e. a collection of methods returning Futures.

    Example: for a Thrift service IDL:

    service Logger {
      string log(1: string message, 2: i32 logLevel);
      i32 getLogSize();
    }

    the Service interface, or ServicePerEndpoint, is

    trait LoggerServicePerEndpoint {
      val log: com.twitter.finagle.Service[Logger.Log.Args, Logger.Log.SuccessType]
      val getLogSize: com.twitter.finagle.Service[Logger.GetLogSize.Args, Logger.GetLogSize.SuccessType]
    }

    and the method interface, or MethodPerEndpoint, is

    trait Logger.MethodPerEndpoint {
      def log(message: String, logLevel: Int): Future[String]
      def getLogSize(): Future[Int]
    }

    Service interfaces can be modified and composed with Finagle Filters.

Ungrouped