com.twitter.finagle

Thrift

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

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 https://github.com/twitter/finagle/blob/master/finagle-thrift/src/main/thrift/tracing.thrift here.

Clients

For example, this IDL:

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

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

Thrift.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.newIface[TestService.FutureIface](addr)

In Java, we need to provide the class object:

TestService.FutureIface client =
Thrift.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:

Thrift.serveIface(":*", new TestService.FutureIface {
  def query(x: String) = Future.value(x)  // (echo service)
})
Linear Supertypes
ThriftRichServer, finagle.Server[Array[Byte], Array[Byte]], ThriftRichClient, finagle.Client[ThriftClientRequest, Array[Byte]], AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Thrift
  2. ThriftRichServer
  3. Server
  4. ThriftRichClient
  5. Client
  6. AnyRef
  7. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. case class Client(stack: Stack[ServiceFactory[ThriftClientRequest, Array[Byte]]] = Thrift.this.Client.stack, params: Params = ..., framed: Boolean = true) extends StdStackClient[ThriftClientRequest, Array[Byte], Client] with ThriftRichClient with Product with Serializable

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

Value Members

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

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

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

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. object Client extends Serializable

  7. object Server extends Serializable

  8. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  9. val client: Client

  10. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  11. lazy val defaultClientName: String

    Attributes
    protected
    Definition Classes
    ThriftThriftRichClient
  12. final def eq(arg0: AnyRef): Boolean

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

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

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

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

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

    Definition Classes
    Any
  18. val maxThriftBufferSize: Int

    Definition Classes
    ThriftRichServer
  19. final def ne(arg0: AnyRef): Boolean

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

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

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

    Definition Classes
    Client
  23. def newIface[Iface](name: Name, label: String, cls: Class[_]): Iface

    Create a new client of type Iface, which must be generated by either Scrooge or thrift-finagle.

    Create a new client of type Iface, which must be generated by either Scrooge or thrift-finagle.

    Definition Classes
    ThriftRichClient
  24. def newIface[Iface](dest: Name, label: String)(implicit arg0: ClassTag[Iface]): Iface

    Definition Classes
    ThriftRichClient
  25. def newIface[Iface](dest: String, label: String)(implicit arg0: ClassTag[Iface]): Iface

    Definition Classes
    ThriftRichClient
  26. def newIface[Iface](dest: String)(implicit arg0: ClassTag[Iface]): Iface

    Create a new client of type Iface, which must be generated by either Scrooge or thrift-finagle.

    Create a new client of type Iface, which must be generated by either Scrooge or thrift-finagle.

    Definition Classes
    ThriftRichClient
  27. def newIface[Iface](dest: String, label: String, cls: Class[_]): Iface

    Create a new client of type Iface, which must be generated by either Scrooge or thrift-finagle.

    Create a new client of type Iface, which must be generated by either Scrooge or thrift-finagle.

    Definition Classes
    ThriftRichClient
  28. def newIface[Iface](dest: String, cls: Class[_]): Iface

    Create a new client of type Iface, which must be generated by either Scrooge or thrift-finagle.

    Create a new client of type Iface, which must be generated by either Scrooge or thrift-finagle.

    Definition Classes
    ThriftRichClient
  29. def newMethodIface[ServiceIface, FutureIface](serviceIface: ServiceIface)(implicit builder: MethodIfaceBuilder[ServiceIface, FutureIface]): FutureIface

    Definition Classes
    ThriftRichClient
  30. def newService(dest: Name, label: String): Service[ThriftClientRequest, Array[Byte]]

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

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

    Definition Classes
    Client
  33. def newServiceIface[ServiceIface](dest: Name)(implicit builder: ServiceIfaceBuilder[ServiceIface]): ServiceIface

    Definition Classes
    ThriftRichClient
  34. def newServiceIface[ServiceIface](dest: String)(implicit builder: ServiceIfaceBuilder[ServiceIface]): ServiceIface

    Construct a Finagle Service interface for a Scrooge-generated thrift object.

    Construct a Finagle Service interface for a Scrooge-generated thrift object.

    E.g. given a thrift service

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

    you can construct a client interface with a Finagle Service per thrift method:

    val loggerService = Thrift.newServiceIface(Logger, "localhost:8000")
    val response = loggerService.log(Logger.Log.Args("log message", 1))
    dest

    Address of the service to connect to, in the format accepted by Resolver.eval.

    builder

    The builder type is generated by Scrooge for a thrift service.

    Definition Classes
    ThriftRichClient
  35. final def notify(): Unit

    Definition Classes
    AnyRef
  36. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  37. object param

  38. val protocolFactory: TProtocolFactory

    Definition Classes
    ThriftThriftRichServerThriftRichClient
  39. def serve(addr: SocketAddress, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer

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

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

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

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

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

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

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

    Definition Classes
    Server
  47. def serveIface(addr: SocketAddress, iface: AnyRef): ListeningServer

    Serve the interface implementation iface, which must be generated by either Scrooge or thrift-finagle.

    Serve the interface implementation iface, which must be generated by either Scrooge or thrift-finagle.

    Given the IDL:

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

    Scrooge will generate an interface, TestService.FutureIface, implementing the above IDL.

    TestService.FutureIface must be implemented and passed into serveIface:

    Thrift.serveIface(":*", new TestService.FutureIface {
      def query(x: String) = Future.value(x)  // (echo service)
    })

    Note that this interface is discovered by reflection. Passing an invalid interface implementation will result in a runtime error.

    Definition Classes
    ThriftRichServer
  48. def serveIface(addr: String, iface: AnyRef): ListeningServer

    Serve the interface implementation iface, which must be generated by either Scrooge or thrift-finagle.

    Serve the interface implementation iface, which must be generated by either Scrooge or thrift-finagle.

    Given the IDL:

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

    Scrooge will generate an interface, TestService.FutureIface, implementing the above IDL.

    TestService.FutureIface must be implemented and passed into serveIface:

    Thrift.serveIface(":*", new TestService.FutureIface {
      def query(x: String) = Future.value(x)  // (echo service)
    })

    Note that this interface is discovered by reflection. Passing an invalid interface implementation will result in a runtime error.

    Definition Classes
    ThriftRichServer
  49. val server: Server

  50. val serverLabel: String

    Attributes
    protected
    Definition Classes
    ThriftRichServer
  51. lazy val serverStats: StatsReceiver

    Attributes
    protected
    Definition Classes
    ThriftRichServer
  52. lazy val stats: StatsReceiver

    Attributes
    protected
    Definition Classes
    ThriftThriftRichClient
  53. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  54. def toString(): String

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

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

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

    Definition Classes
    Client
    Annotations
    @deprecated
    Deprecated

    (Since version 6.7.x) Use destination names

  2. def newIface[Iface](group: Group[SocketAddress], cls: Class[_]): Iface

    Create a new client of type Iface, which must be generated by either Scrooge or thrift-finagle.

    Create a new client of type Iface, which must be generated by either Scrooge or thrift-finagle.

    Definition Classes
    ThriftRichClient
    Annotations
    @deprecated
    Deprecated

    (Since version 6.7.x) Use destination names via newIface(String) or newIface(Name)

  3. def newIface[Iface](group: Group[SocketAddress])(implicit arg0: ClassTag[Iface]): Iface

    Create a new client of type Iface, which must be generated by either Scrooge or thrift-finagle.

    Create a new client of type Iface, which must be generated by either Scrooge or thrift-finagle.

    Definition Classes
    ThriftRichClient
    Annotations
    @deprecated
    Deprecated

    (Since version 6.7.x) Use destination names via newIface(String) or newIface(Name)

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

    Definition Classes
    Client
    Annotations
    @deprecated
    Deprecated

    (Since version 6.7.x) Use destination names

  5. def withClientId(clientId: ClientId): Client

    Annotations
    @deprecated
    Deprecated

    (Since version 6.22.0) Use Thrift.client.withClientId

  6. def withProtocolFactory(protocolFactory: TProtocolFactory): Client

    Annotations
    @deprecated
    Deprecated

    (Since version 6.22.0) Use Thrift.client.withProtocolFactory

Inherited from ThriftRichServer

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

Inherited from ThriftRichClient

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

Inherited from AnyRef

Inherited from Any

Ungrouped