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
  • object ThriftMux extends Client[ThriftClientRequest, Array[Byte]] with Server[Array[Byte], Array[Byte]]

    The ThriftMux object is both a com.twitter.finagle.Client and a com.twitter.finagle.Server for the Thrift protocol served over com.twitter.finagle.mux.

    The ThriftMux object is both a com.twitter.finagle.Client and a com.twitter.finagle.Server for the Thrift protocol served over com.twitter.finagle.mux. Rich interfaces are provided to adhere to those generated from a Thrift IDL by Scrooge or thrift-finagle.

    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 ThriftMux.Client.newIface:

    ThriftMux.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:

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

    In Java, we need to provide the class object:

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

    Servers

    Servers are also simple to expose:

    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)
    })

    This object does not expose any configuration options. Both clients and servers are instantiated with sane defaults. Clients are labeled with the "clnt/thrift" prefix and servers with "srv/thrift". If you'd like more configuration, see the configuration documentation.

    Definition Classes
    finagle
  • Client
  • Server
  • ServerMuxer

case class Server(muxer: StackServer[Request, Response] = serverMuxer) extends StackBasedServer[Array[Byte], Array[Byte]] with ThriftRichServer with Parameterized[Server] with CommonParams[Server] with WithServerTransport[Server] with WithServerSession[Server] with WithServerAdmissionControl[Server] with OpportunisticTlsParams[Server] with Product with Serializable

Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Server
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. OpportunisticTlsParams
  7. WithServerAdmissionControl
  8. WithServerSession
  9. WithServerTransport
  10. CommonParams
  11. ThriftRichServer
  12. StackBasedServer
  13. Parameterized
  14. Server
  15. AnyRef
  16. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Server(muxer: StackServer[Request, Response] = serverMuxer)

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  6. def configured[P](psp: (P, Param[P])): Server

    Java friendly API for configured.

    Java friendly API for configured.

    The Tuple2 can often be created by calls to a mk(): (P, Stack.Param[P]) method on parameters (see com.twitter.finagle.loadbalancer.LoadBalancerFactory.Param.mk() as an example).

    Definition Classes
    ServerParameterized
  7. def configured[P](p: P)(implicit sp: Param[P]): Server

    Add the parameter, p, to the current Params.

    Add the parameter, p, to the current Params.

    Java users may find it easier to use the Tuple2 version below.

    Definition Classes
    Parameterized
  8. def configuredParams(newParams: Params): Server

    Adds all parameters, newParams, to the current Params.

    Adds all parameters, newParams, to the current Params.

    Definition Classes
    Parameterized
  9. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  10. def filtered(filter: Filter[Request, Response, Request, Response]): Server

    Prepends filter to the top of the server.

    Prepends filter to the top of the server. That is, after materializing the server (newService) filter will be the first element which requests flow through. This is a familiar chaining combinator for filters.

  11. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. val muxer: StackServer[Request, Response]
  15. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  18. def params: Params
    Definition Classes
    ServerThriftRichServerParameterized
  19. def serve(addr: SocketAddress, factory: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer

    Serve service at addr

    Serve service at addr

    Definition Classes
    ServerServer
  20. final def serve(addr: String, service: Service[Array[Byte], Array[Byte]]): ListeningServer

    Serve service at addr

    Serve service at addr

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

    Serve service at addr

    Serve service at addr

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

    Serve service at addr

    Serve service at addr

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

    Serve service at addr and announce with name.

    Serve service at addr and announce with name. Announcements will be removed when the service is closed. Omitting the addr will bind to an ephemeral port.

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

    Serve service at addr and announce with name.

    Serve service at addr and announce with name. Announcements will be removed when the service is closed. Omitting the addr will bind to an ephemeral port.

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

    Serve service at addr and announce with name.

    Serve service at addr and announce with name. Announcements will be removed when the service is closed. Omitting the addr will bind to an ephemeral port.

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

    Serve service at addr and announce with name.

    Serve service at addr and announce with name. Announcements will be removed when the service is closed. Omitting the addr will bind to an ephemeral port.

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

    Serve service at addr and announce with name.

    Serve service at addr and announce with name. Announcements will be removed when the service is closed. Omitting the addr will bind to an ephemeral port.

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

    Serve service at addr and announce with name.

    Serve service at addr and announce with name. Announcements will be removed when the service is closed. Omitting the addr will bind to an ephemeral port.

    Definition Classes
    Server
  29. 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:

    ThriftMuxRichServer
    .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
  30. 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:

    ThriftMuxRichServer
    .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
  31. def serveIfaces(addr: SocketAddress, ifaces: Map[String, AnyRef], defaultService: Option[String]): ListeningServer

    Serve multiple interfaces:

    Serve multiple interfaces:

    val serviceMap = Map(
    "echo" -> new EchoService(),
    "extendedEcho" -> new ExtendedEchoService()
    )
    
    val server = Thrift.server.serveIfaces(address, serviceMap)

    A default service name can be specified, so we can upgrade an existing non-multiplexed server to a multiplexed one without breaking the old clients:

    val server = Thrift.server.serveIfaces(
      address, serviceMap, defaultService = Some("extendedEcho"))
    Definition Classes
    ThriftRichServer
  32. def serveIfaces(addr: SocketAddress, ifaces: Map[String, AnyRef]): ListeningServer

    Serve multiple interfaces:

    Serve multiple interfaces:

    val serviceMap = Map(
    "echo" -> new EchoService(),
    "extendedEcho" -> new ExtendedEchoService()
    )
    
    val server = Thrift.server.serveIfaces(address, serviceMap)

    A default service name can be specified, so we can upgrade an existing non-multiplexed server to a multiplexed one without breaking the old clients:

    val server = Thrift.server.serveIfaces(
      address, serviceMap, defaultService = Some("extendedEcho"))
    Definition Classes
    ThriftRichServer
  33. def serveIfaces(addr: String, ifaces: Map[String, AnyRef], defaultService: Option[String] = None): ListeningServer

    Serve multiple interfaces:

    Serve multiple interfaces:

    val serviceMap = Map(
    "echo" -> new EchoService(),
    "extendedEcho" -> new ExtendedEchoService()
    )
    
    val server = Thrift.server.serveIfaces(address, serviceMap)

    A default service name can be specified, so we can upgrade an existing non-multiplexed server to a multiplexed one without breaking the old clients:

    val server = Thrift.server.serveIfaces(
      address, serviceMap, defaultService = Some("extendedEcho"))
    Definition Classes
    ThriftRichServer
  34. val serverParam: RichServerParam
    Attributes
    protected
    Definition Classes
    ServerThriftRichServer
  35. def stack: Stack[ServiceFactory[Request, Response]]
  36. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  37. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  38. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  39. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  40. val withAdmissionControl: ServerAdmissionControlParams[Server]
    Definition Classes
    ServerWithServerAdmissionControl
  41. def withExceptionStatsHandler(exceptionStatsHandler: ExceptionStatsHandler): Server

    Configures this server or client with given exception stats handler.

    Configures this server or client with given exception stats handler.

    Definition Classes
    ServerCommonParams
  42. def withLabel(label: String): Server

    Configures this server or client with given label (default: empty string).

    Configures this server or client with given label (default: empty string).

    The label value is used for stats reporting to scope stats reported from different clients/servers to a single stats receiver.

    Definition Classes
    ServerCommonParams
  43. def withMaxReusableBufferSize(size: Int): Server

    Produce a com.twitter.finagle.ThriftMux.Server with the specified max size of the reusable buffer for thrift responses.

    Produce a com.twitter.finagle.ThriftMux.Server with the specified max size of the reusable buffer for thrift responses. If this size is exceeded, the buffer is not reused and a new buffer is allocated for the next thrift response. The default max size is 16Kb.

    size

    Max size of the reusable buffer for thrift responses in bytes.

  44. def withMonitor(monitor: Monitor): Server

    Configures this server or client with given util.Monitor (default: com.twitter.finagle.util.DefaultMonitor).

    Configures this server or client with given util.Monitor (default: com.twitter.finagle.util.DefaultMonitor).

    Definition Classes
    ServerCommonParams
  45. def withNoOpportunisticTls: Server

    Disables opportunistic TLS.

    Disables opportunistic TLS.

    If this is still TLS configured, it will speak mux over TLS. To instead configure this to be Off, use withOpportunisticTls(OpportunisticTls.Off).

    Definition Classes
    OpportunisticTlsParams
  46. def withOpportunisticTls(level: Level): Server

    Configures whether to speak TLS or not.

    Configures whether to speak TLS or not.

    By default, don't use opportunistic TLS, and instead try to speak mux over TLS if TLS has been configured.

    The valid levels are Off, which indicates this will never speak TLS, Desired, which indicates it may speak TLS, but may also not speak TLS, and Required, which indicates it must speak TLS.

    Peers that are configured with level Required cannot speak to peers that are configured with level Off.

    Note that opportunistic TLS is negotiated in a cleartext handshake, and is incompatible with mux over TLS.

    Definition Classes
    OpportunisticTlsParams
  47. def withParams(ps: Params): Server
    Definition Classes
    ServerParameterized
  48. def withProtocolFactory(pf: TProtocolFactory): Server

    Produce a com.twitter.finagle.Thrift.Server using the provided TProtocolFactory.

  49. def withRequestTimeout(timeout: Duration): Server

    Configures the request timeout of this server or client (default: unbounded).

    Configures the request timeout of this server or client (default: unbounded).

    If the request has not completed within the given timeout, the pending work will be interrupted via com.twitter.util.Future.raise.

    Client's Request Timeout

    The client request timeout is the maximum amount of time given to a single request (if there are retries, they each get a fresh request timeout). The timeout is applied only after a connection has been acquired. That is: it is applied to the interval between the dispatch of the request and the receipt of the response.

    Server's Request Timeout

    The server request timeout is the maximum amount of time, a server is allowed to spend handling the incoming request. Using the Finagle terminology, this is an amount of time after which a non-satisfied future returned from the user-defined service times out.

    Definition Classes
    ServerCommonParams
    See also

    https://twitter.github.io/finagle/guide/Clients.html#timeouts-expiration

  50. def withRequestTimeout(timeout: Tunable[Duration]): Server

    Configures the Tunable request timeout of this server or client (if applying the Tunable produces a value of None, an unbounded timeout is used for the request).

    Configures the Tunable request timeout of this server or client (if applying the Tunable produces a value of None, an unbounded timeout is used for the request).

    If the request has not completed within the Duration resulting from timeout.apply(), the pending work will be interrupted via com.twitter.util.Future.raise.

    Client's Request Timeout

    The client request timeout is the maximum amount of time given to a single request (if there are retries, they each get a fresh request timeout). The timeout is applied only after a connection has been acquired. That is: it is applied to the interval between the dispatch of the request and the receipt of the response.

    Server's Request Timeout

    The server request timeout is the maximum amount of time, a server is allowed to spend handling the incoming request. Using the Finagle terminology, this is an amount of time after which a non-satisfied future returned from the user-defined service times out.

    Definition Classes
    CommonParams
    See also

    https://twitter.github.io/finagle/guide/Clients.html#timeouts-expiration and https://twitter.github.io/finagle/guide/Configuration.html#tunables

  51. def withResponseClassifier(responseClassifier: ResponseClassifier): Server

    Configure a com.twitter.finagle.service.ResponseClassifier which is used to determine the result of a request/response.

    Configure a com.twitter.finagle.service.ResponseClassifier which is used to determine the result of a request/response.

    This allows developers to give Finagle the additional application-specific knowledge necessary in order to properly classify responses. Without this, Finagle cannot make judgements about application-level failures as it only has a narrow understanding of failures (for example: transport level, timeouts, and nacks).

    As an example take an HTTP server that returns a response with a 500 status code. To Finagle this is a successful request/response. However, the application developer may want to treat all 500 status codes as failures and can do so via setting a com.twitter.finagle.service.ResponseClassifier.

    ResponseClassifier is a PartialFunction and as such multiple classifiers can be composed together via PartialFunction.orElse.

    Response classification is independently configured on the client and server. For client-side response classification using com.twitter.finagle.builder.ClientBuilder, see com.twitter.finagle.builder.ClientBuilder.responseClassifier

    Definition Classes
    CommonParams
    Note

    If unspecified, the default classifier is com.twitter.finagle.service.ResponseClassifier.Default which is a total function fully covering the input domain.

    See also

    com.twitter.finagle.http.service.HttpResponseClassifier for some HTTP classification tools.

  52. val withSession: SessionParams[Server]
    Definition Classes
    ServerWithServerSession
  53. def withStack(stack: Stack[ServiceFactory[Request, Response]]): Server

    Produce a com.twitter.finagle.ThriftMux.Server using the provided stack.

  54. def withStatsReceiver(statsReceiver: StatsReceiver): Server

    Configures this server or client with given stats.StatsReceiver (default: stats.DefaultStatsReceiver).

    Configures this server or client with given stats.StatsReceiver (default: stats.DefaultStatsReceiver).

    Definition Classes
    ServerCommonParams
  55. def withTracer(tracer: Tracer): Server

    Configures this server or client with given tracing.Tracer (default: com.twitter.finagle.tracing.DefaultTracer).

    Configures this server or client with given tracing.Tracer (default: com.twitter.finagle.tracing.DefaultTracer).

    Definition Classes
    ServerCommonParams
  56. val withTransport: ServerTransportParams[Server]
    Definition Classes
    ServerWithServerTransport

Deprecated Value Members

  1. def maxThriftBufferSize: Int
    Attributes
    protected
    Definition Classes
    ServerThriftRichServer
    Annotations
    @deprecated
    Deprecated

    (Since version 2017-08-16) Use serverParam.maxThriftBufferSize

  2. def protocolFactory: TProtocolFactory
    Attributes
    protected
    Definition Classes
    ServerThriftRichServer
    Annotations
    @deprecated
    Deprecated

    (Since version 2017-08-16) Use serverParam.protocolFactory

  3. def serverLabel: String
    Attributes
    protected
    Definition Classes
    ServerThriftRichServer
    Annotations
    @deprecated
    Deprecated

    (Since version 2017-08-16) Use serverParam.serviceName

  4. def serverStats: StatsReceiver
    Attributes
    protected
    Definition Classes
    ServerThriftRichServer
    Annotations
    @deprecated
    Deprecated

    (Since version 2017-08-16) Use serverParam.serverStats

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from OpportunisticTlsParams[Server]

Inherited from WithServerSession[Server]

Inherited from WithServerTransport[Server]

Inherited from CommonParams[Server]

Inherited from ThriftRichServer

Inherited from StackBasedServer[Array[Byte], Array[Byte]]

Inherited from Parameterized[Server]

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

Inherited from AnyRef

Inherited from Any

Ungrouped