Object

com.twitter.finagle

Thrift

Related Doc: package finagle

Permalink

object Thrift extends Client[ThriftClientRequest, Array[Byte]] with Server[Array[Byte], Array[Byte]]

Client and server for Apache Thrift. Thrift implements Thrift framed transport and binary protocol by default, though custom protocol factories (i.e. wire encoding) may be injected with withProtocolFactory. The client, Client[ThriftClientRequest, Array[Byte]] provides direct access to the thrift transport, but we recommend using code generation through either Scrooge or a fork of the Apache generator. A rich API is provided to support interfaces generated with either of these code generators.

The client and server uses the standard thrift protocols, with support for both framed and buffered transports. Finagle attempts to upgrade the protocol in order to ship an extra envelope carrying additional request metadata, containing, among other things, request IDs for Finagle's RPC tracing facilities.

The negotiation is simple: on connection establishment, an improbably-named method is dispatched on the server. If that method isn't found, we are dealing with a legacy thrift server, and the standard protocol is used. If the remote server is also a finagle server (or any other supporting this extension), we reply to the request, and every subsequent request is dispatched with an envelope carrying trace metadata. The envelope itself is also a Thrift struct described here.

Clients

Clients can be created directly from an interface generated from a Thrift IDL:

For example, this IDL:

service TestService {
  string query(1: string x)
}

compiled with Scrooge, generates the interface TestService.FutureIface. This is then passed into Thrift.Client.newIface:

Thrift.client.newIface[TestService.FutureIface](
  addr, classOf[TestService.FutureIface])

However note that the Scala compiler can insert the latter Class for us, for which another variant of newIface is provided:

Thrift.client.newIface[TestService.FutureIface](addr)

In Java, we need to provide the class object:

TestService.FutureIface client =
  Thrift.client.newIface(addr, TestService.FutureIface.class);

The client uses the standard thrift protocols, with support for both framed and buffered transports. Finagle attempts to upgrade the protocol in order to ship an extra envelope carrying trace IDs and client IDs associated with the request. These are used by Finagle's tracing facilities and may be collected via aggregators like Zipkin.

The negotiation is simple: on connection establishment, an improbably-named method is dispatched on the server. If that method isn't found, we are dealing with a legacy thrift server, and the standard protocol is used. If the remote server is also a finagle server (or any other supporting this extension), we reply to the request, and every subsequent request is dispatched with an envelope carrying trace metadata. The envelope itself is also a Thrift struct described here.

Servers

TestService.FutureIface must be implemented and passed into serveIface:

// An echo service
ThriftMux.server.serveIface(":*", new TestService.FutureIface {
  def query(x: String): Future[String] = Future.value(x)
})
Linear Supertypes
finagle.Server[Array[Byte], Array[Byte]], finagle.Client[ThriftClientRequest, Array[Byte]], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Thrift
  2. Server
  3. Client
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. case class Client(stack: Stack[ServiceFactory[ThriftClientRequest, Array[Byte]]] = Client.stack, params: Params = ...) extends StdStackClient[ThriftClientRequest, Array[Byte], Client] with WithSessionPool[Client] with WithDefaultLoadBalancer[Client] with ThriftRichClient with Product with Serializable

    Permalink

    A ThriftMux com.twitter.finagle.Client.

    A ThriftMux com.twitter.finagle.Client.

    See also

    Mux documentation

    Thrift documentation

    Configuration documentation

  2. case class Server(stack: Stack[ServiceFactory[Array[Byte], Array[Byte]]] = Server.stack, params: Params = ...) extends StdStackServer[Array[Byte], Array[Byte], Server] with ThriftRichServer with Product with Serializable

    Permalink

    A ThriftMux com.twitter.finagle.Server.

    A ThriftMux com.twitter.finagle.Server.

    See also

    Thrift documentation

    Configuration documentation

  3. case class ThriftImpl(transporter: (Params) ⇒ (SocketAddress) ⇒ Transporter[ThriftClientRequest, Array[Byte]], listener: (Params) ⇒ Listener[Array[Byte], Array[Byte]]) extends Product with Serializable

    Permalink

    The vanilla Thrift Transporter and Listener factories deviate from other protocols in the result of the netty pipeline: most other protocols expect to receive a framed Buf while vanilla thrift produces an Array[Byte].

    The vanilla Thrift Transporter and Listener factories deviate from other protocols in the result of the netty pipeline: most other protocols expect to receive a framed Buf while vanilla thrift produces an Array[Byte]. This has two related motivations. First, the end result needed by the thrift implementations is an Array[Byte], which is relatively trivial to deal with and is a JVM native type so it's unnecessary to go through a Buf. By avoiding an indirection through Buf we can avoid an unnecessary copy in the netty4 pipeline that would be required to ensure that the bytes were on the heap before entering the Finagle transport types.

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. object Client extends Serializable

    Permalink
  5. object Server extends Serializable

    Permalink
  6. object ThriftImpl extends Serializable

    Permalink
  7. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  8. val client: Client

    Permalink
  9. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  14. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  16. val maxThriftBufferSize: Int

    Permalink
  17. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  18. def newClient(dest: Name, label: String): ServiceFactory[ThriftClientRequest, Array[Byte]]

    Permalink
    Definition Classes
    Thrift → Client
  19. final def newClient(dest: String, label: String): ServiceFactory[ThriftClientRequest, Array[Byte]]

    Permalink
    Definition Classes
    Client
  20. final def newClient(dest: String): ServiceFactory[ThriftClientRequest, Array[Byte]]

    Permalink
    Definition Classes
    Client
  21. def newService(dest: Name, label: String): Service[ThriftClientRequest, Array[Byte]]

    Permalink
    Definition Classes
    Thrift → Client
  22. final def newService(dest: String, label: String): Service[ThriftClientRequest, Array[Byte]]

    Permalink
    Definition Classes
    Client
  23. final def newService(dest: String): Service[ThriftClientRequest, Array[Byte]]

    Permalink
    Definition Classes
    Client
  24. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  25. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  26. object param

    Permalink
  27. val protocolFactory: TProtocolFactory

    Permalink
  28. def serve(addr: SocketAddress, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer

    Permalink
    Definition Classes
    Thrift → Server
  29. def serve(addr: String, service: Service[Array[Byte], Array[Byte]]): ListeningServer

    Permalink
    Definition Classes
    Server
  30. def serve(addr: String, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer

    Permalink
    Definition Classes
    Server
  31. def serve(addr: SocketAddress, service: Service[Array[Byte], Array[Byte]]): ListeningServer

    Permalink
    Definition Classes
    Server
  32. def serveAndAnnounce(name: String, service: Service[Array[Byte], Array[Byte]]): ListeningServer

    Permalink
    Definition Classes
    Server
  33. def serveAndAnnounce(name: String, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer

    Permalink
    Definition Classes
    Server
  34. def serveAndAnnounce(name: String, addr: String, service: Service[Array[Byte], Array[Byte]]): ListeningServer

    Permalink
    Definition Classes
    Server
  35. def serveAndAnnounce(name: String, addr: String, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer

    Permalink
    Definition Classes
    Server
  36. def serveAndAnnounce(name: String, addr: SocketAddress, service: Service[Array[Byte], Array[Byte]]): ListeningServer

    Permalink
    Definition Classes
    Server
  37. def serveAndAnnounce(name: String, addr: SocketAddress, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer

    Permalink
    Definition Classes
    Server
  38. val server: Server

    Permalink
  39. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  40. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  41. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  42. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  43. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. final def newClient(dest: Group[SocketAddress]): ServiceFactory[ThriftClientRequest, Array[Byte]]

    Permalink
    Definition Classes
    Client
    Annotations
    @deprecated
    Deprecated

    (Since version 6.7.x) Use destination names

  2. final def newService(dest: Group[SocketAddress]): Service[ThriftClientRequest, Array[Byte]]

    Permalink
    Definition Classes
    Client
    Annotations
    @deprecated
    Deprecated

    (Since version 6.7.x) Use destination names

  3. def withClientId(clientId: ClientId): Client

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 6.22.0) Use Thrift.client.withClientId

  4. def withProtocolFactory(protocolFactory: TProtocolFactory): Client

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 6.22.0) Use Thrift.client.withProtocolFactory

Inherited from finagle.Server[Array[Byte], Array[Byte]]

Inherited from finagle.Client[ThriftClientRequest, Array[Byte]]

Inherited from AnyRef

Inherited from Any

Ungrouped