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 builder
    Definition Classes
    finagle
  • ClientBuilder
  • ClientConfig
  • ClientConfigEvidence
  • IncompleteSpecification
  • Server
  • ServerBuilder
  • ServerConfig
  • ServerConfigEvidence
  • SourceTrackingMonitor

class ServerBuilder[Req, Rep, HasCodec, HasBindTo, HasName] extends AnyRef

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.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ServerBuilder
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. type FullySpecifiedConfig = ServerConfig[Req, Rep, Yes, Yes, Yes]
  2. type This = ServerBuilder[Req, Rep, HasCodec, HasBindTo, HasName]
  3. type ThisConfig = ServerConfig[Req, Rep, HasCodec, HasBindTo, HasName]

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 backlog(value: Int): This
  6. def bindTo(address: SocketAddress): ServerBuilder[Req, Rep, HasCodec, Yes, HasName]

    To migrate to the Stack-based APIs, use Server.serve.

    To migrate to the Stack-based APIs, use Server.serve. For example:

    import com.twitter.finagle.Http
    import com.twitter.finagle.Service
    
    val service: Service[Req, Rep] = ???
    Http.server.serve(address, service)
  7. def build(serviceFactory: ServiceFactory[Req, Rep])(implicit THE_BUILDER_IS_NOT_FULLY_SPECIFIED_SEE_ServerBuilder_DOCUMENTATION: ServerConfigEvidence[HasCodec, HasBindTo, HasName]): Server

    Construct the Server, given the provided ServiceFactory.

    Construct the Server, given the provided ServiceFactory. This is useful if the protocol is stateful (e.g., requires authentication or supports transactions).

  8. def build(service: Service[Req, Rep])(implicit THE_BUILDER_IS_NOT_FULLY_SPECIFIED_SEE_ServerBuilder_DOCUMENTATION: ServerConfigEvidence[HasCodec, HasBindTo, HasName]): Server

    Construct the Server, given the provided Service.

  9. def cancelOnHangup(yesOrNo: Boolean): This

    Cancel pending futures whenever the the connection is shut down.

    Cancel pending futures whenever the the connection is shut down. This defaults to true.

    To migrate to the Stack-based APIs, use configured. For example:

    import com.twitter.finagle.Http
    import com.twitter.finagle.filter.MaskCancelFilter
    
    Http.server.configured(MaskCancelFilter.Param(!yesOrNo))
    See also

    com.twitter.finagle.filter.ServerAdmissionControl

  10. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  11. def configured[P](paramAndStackParam: (P, Param[P])): This

    Java friendly API for configuring the underlying Params.

    Java friendly API for configuring the underlying Params.

    paramAndStackParam

    Configures the server with a given param represented as the tuple (param value, stack param instance) 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).

  12. def configured[P](param: P)(implicit stackParam: Param[P]): This

    Configure the underlying Params.

    Configure the underlying Params.

    param

    Configures the server with a given param Java users may find it easier to use the Tuple2 version below.

  13. def copy[Req1, Rep1, HasCodec1, HasBindTo1, HasName1](ps: Params, newServer: (Params) ⇒ finagle.Server[Req1, Rep1]): ServerBuilder[Req1, Rep1, HasCodec1, HasBindTo1, HasName1]
    Attributes
    protected
  14. def daemon(daemonize: Boolean): This

    When true, the server is daemonized.

    When true, the server is daemonized. As with java threads, a process can only exit only when all remaining servers are daemonized. False by default.

    The default for the Stack-based APIs is for the server to be daemonized.

  15. def enableAdmissionControl(enable: Boolean): This

    Configure admission control filters in the server Stack.

    Configure admission control filters in the server Stack.

    To migrate to the Stack-based APIs, use configured. For example:

    import com.twitter.finagle.Http
    import com.twitter.finagle.filter.ServerAdmissionControl
    
    Http.server.configured(ServerAdmissionControl.Param(enable))
    See also

    com.twitter.finagle.filter.ServerAdmissionControl

  16. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  18. def exceptionCategorizer(exceptionStatsHandler: ExceptionStatsHandler): This

    Provide an alternative to putting all request exceptions under a "failures" stat.

    Provide an alternative to putting all request exceptions under a "failures" stat. Typical implementations may report any cancellations or validation errors separately so success rate considers only valid non cancelled requests.

    To migrate to the Stack-based APIs, use CommonParams.withExceptionStatsHandler. For example:

    import com.twitter.finagle.Http
    
    Http.server.withExceptionStatsHandler(exceptionStatsHandler)
    exceptionStatsHandler

    function to record failure details.

  19. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  20. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  21. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  22. def hostConnectionMaxIdleTime(howlong: Duration): This
  23. def hostConnectionMaxLifeTime(howlong: Duration): This
  24. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  25. def keepAlive(value: Boolean): This
  26. def logChannelActivity(v: Boolean): This

    To migrate to the Stack-based APIs, use ServerTransportParams.verbose.

    To migrate to the Stack-based APIs, use ServerTransportParams.verbose. For example:

    import com.twitter.finagle.Http
    
    Http.server.withTransport.verbose
  27. def logger(logger: Logger): This

    To migrate to the Stack-based APIs, use configured.

    To migrate to the Stack-based APIs, use configured. For example:

    import com.twitter.finagle.Http
    import com.twitter.finagle.param
    
    Http.server.configured(param.Logger(logger))
  28. def maxConcurrentRequests(max: Int): This

    Configures the maximum concurrent requests that are admitted by the server at any given time.

    Configures the maximum concurrent requests that are admitted by the server at any given time. If the server receives a burst of traffic that exceeds this limit, the burst is rejected with a Failure.Rejected exception. Note, this failure signals a graceful rejection which is transmitted to clients by certain protocols in Finagle (e.g. Http, ThriftMux). The limit is global to all sessions.

    To migrate to the Stack-based APIs, use ServerAdmissionControlParams.concurrencyLimit. For example:

    import com.twitter.finagle.Http
    
    Http.server.withAdmissionControl.concurrencyLimit(10, 0)
  29. def monitor(mFactory: (String, SocketAddress) ⇒ Monitor): This

    To migrate to the Stack-based APIs, use CommonParams.withMonitor.

    To migrate to the Stack-based APIs, use CommonParams.withMonitor. For example:

    import com.twitter.finagle.Http
    import com.twitter.util.Monitor
    
    val monitor: Monitor = ???
    Http.server.withMonitor(monitor)
  30. def name(value: String): ServerBuilder[Req, Rep, HasCodec, HasBindTo, Yes]

    To migrate to the Stack-based APIs, use CommonParams.withLabel.

    To migrate to the Stack-based APIs, use CommonParams.withLabel. For example:

    import com.twitter.finagle.Http
    
    Http.server.withLabel("my_server")
  31. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  32. def newFinagleSslEngine(v: () ⇒ Engine): This
  33. def newSslEngine(newSsl: () ⇒ SSLEngine): This

    Provide a raw SSL engine that is used to establish SSL sessions.

  34. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  35. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  36. val params: Params
  37. def readTimeout(howlong: Duration): This

    To migrate to the Stack-based APIs, use TransportParams.readTimeout.

    To migrate to the Stack-based APIs, use TransportParams.readTimeout. For example:

    import com.twitter.finagle.Http
    
    Http.server.withTransport.readTimeout(howlong)
  38. def recvBufferSize(value: Int): This

    To migrate to the Stack-based APIs, use ServerTransportParams.receiveBufferSize.

    To migrate to the Stack-based APIs, use ServerTransportParams.receiveBufferSize. For example:

    import com.twitter.finagle.Http
    
    Http.server.withTransport.receiveBufferSize(value)
  39. def reportTo(receiver: StatsReceiver): This

    To migrate to the Stack-based APIs, use CommonParams.withStatsReceiver.

    To migrate to the Stack-based APIs, use CommonParams.withStatsReceiver. For example:

    import com.twitter.finagle.Http
    
    Http.server.withStatsReceiver(receiver)
  40. def requestTimeout(howlong: Duration): This

    To migrate to the Stack-based APIs, use CommonParams.withRequestTimeout.

    To migrate to the Stack-based APIs, use CommonParams.withRequestTimeout. For example:

    import com.twitter.finagle.Http
    
    Http.server.withRequestTimeout(howlong)
    Note

    if the request is not complete after howlong, the work that is in progress will be interrupted via Future.raise.

  41. def responseClassifier: ResponseClassifier

    The currently configured com.twitter.finagle.service.ResponseClassifier.

    Note

    If unspecified, the default classifier is com.twitter.finagle.service.ResponseClassifier.Default.

  42. def responseClassifier(classifier: ResponseClassifier): This

    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

    To migrate to the Stack-based APIs, use CommonParams.withResponseClassifier. For example:

    import com.twitter.finagle.Http
    
    Http.server.withResponseClassifier(classifier)
    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.

  43. def sendBufferSize(value: Int): This

    To migrate to the Stack-based APIs, use ServerTransportParams.sendBufferSize.

    To migrate to the Stack-based APIs, use ServerTransportParams.sendBufferSize. For example:

    import com.twitter.finagle.Http
    
    Http.server.withTransport.sendBufferSize(value)
  44. def stack[Req1, Rep1](server: StackBasedServer[Req1, Rep1]): ServerBuilder[Req1, Rep1, Yes, HasBindTo, HasName]

    Overrides the stack and com.twitter.finagle.Server that will be used by this builder.

    Overrides the stack and com.twitter.finagle.Server that will be used by this builder.

    server

    A StackBasedServer representation of a com.twitter.finagle.Server. server is materialized with the state of configuration when build is called. There is no guarantee that all builder parameters will be used by the resultant Server; it is up to the discretion of server itself and the protocol implementation.

  45. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  46. def tls(certificatePath: String, keyPath: String, caCertificatePath: String = null, ciphers: String = null, nextProtos: String = null): This

    Encrypt the connection with SSL/TLS.

    Encrypt the connection with SSL/TLS.

    To migrate to the Stack-based APIs, use ServerTransportParams.tls. For example:

    import com.twitter.finagle.Http
    
    Http.server.withTransport.tls(...)
  47. def tls(config: SslServerConfiguration, engineFactory: SslServerEngineFactory, sessionVerifier: SslServerSessionVerifier): This

    Encrypt the connection with SSL/TLS.

    Encrypt the connection with SSL/TLS.

    To migrate to the Stack-based APIs, use ServerTransportParams.tls. For example:

    import com.twitter.finagle.Http
    
    Http.server.withTransport.tls(config, engineFactory, sessionVerifier)
  48. def tls(config: SslServerConfiguration, sessionVerifier: SslServerSessionVerifier): This

    Encrypt the connection with SSL/TLS.

    Encrypt the connection with SSL/TLS.

    To migrate to the Stack-based APIs, use ServerTransportParams.tls. For example:

    import com.twitter.finagle.Http
    
    Http.server.withTransport.tls(config, sessionVerifier)
  49. def tls(config: SslServerConfiguration, engineFactory: SslServerEngineFactory): This

    Encrypt the connection with SSL/TLS.

    Encrypt the connection with SSL/TLS.

    To migrate to the Stack-based APIs, use ServerTransportParams.tls. For example:

    import com.twitter.finagle.Http
    
    Http.server.withTransport.tls(config, engineFactory)
  50. def tls(config: SslServerConfiguration): This

    Encrypt the connection with SSL/TLS.

    Encrypt the connection with SSL/TLS.

    To migrate to the Stack-based APIs, use ServerTransportParams.tls. For example:

    import com.twitter.finagle.Http
    
    Http.server.withTransport.tls(config)
  51. def toString(): String
    Definition Classes
    ServerBuilder → AnyRef → Any
  52. def tracer(t: Tracer): This

    To migrate to the Stack-based APIs, use CommonParams.withTracer.

    To migrate to the Stack-based APIs, use CommonParams.withTracer. For example:

    import com.twitter.finagle.Http
    
    Http.server.withTracer(t)
  53. def trafficClass(value: Option[Int]): This

    Configures the traffic class.

    Configures the traffic class.

    To migrate to the Stack-based APIs, use configured. For example:

    import com.twitter.finagle.Http
    import com.twitter.finagle.server.Listener
    
    Http.server.configured(Listener.TrafficClass(value))
    See also

    Listener.TrafficClass

  54. def unsafeBuild(service: Service[Req, Rep]): Server

    Construct a Service, with runtime checks for builder completeness.

  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
    @native() @throws( ... )
  58. def writeCompletionTimeout(howlong: Duration): This

    To migrate to the Stack-based APIs, use TransportParams.writeTimeout.

    To migrate to the Stack-based APIs, use TransportParams.writeTimeout. For example:

    import com.twitter.finagle.Http
    
    Http.server.withTransport.writeTimeout(howlong)

Deprecated Value Members

  1. final def build(serviceFactory: ServiceFactory[Req, Rep], THE_BUILDER_IS_NOT_FULLY_SPECIFIED_SEE_ServerBuilder_DOCUMENTATION: =:=[ThisConfig, FullySpecifiedConfig]): Server
    Annotations
    @deprecated
    Deprecated

    (Since version 5.0.1) Used for ABI compat

  2. final def build(serviceFactory: (ClientConnection) ⇒ Service[Req, Rep])(implicit THE_BUILDER_IS_NOT_FULLY_SPECIFIED_SEE_ServerBuilder_DOCUMENTATION: =:=[ThisConfig, FullySpecifiedConfig]): Server

    Construct the Server, given the provided ServiceFactory.

    Construct the Server, given the provided ServiceFactory. This is useful if the protocol is stateful (e.g., requires authentication or supports transactions).

    Annotations
    @deprecated
    Deprecated

    (Since version 5.0.1) Use the ServiceFactory variant instead

  3. final def build(serviceFactory: () ⇒ Service[Req, Rep])(implicit THE_BUILDER_IS_NOT_FULLY_SPECIFIED_SEE_ServerBuilder_DOCUMENTATION: =:=[ThisConfig, FullySpecifiedConfig]): Server

    Construct the Server, given the provided Service factory.

    Construct the Server, given the provided Service factory.

    Annotations
    @deprecated
    Deprecated

    (Since version 5.0.1) Use the ServiceFactory variant instead

  4. final def build(service: Service[Req, Rep], THE_BUILDER_IS_NOT_FULLY_SPECIFIED_SEE_ServerBuilder_DOCUMENTATION: =:=[ThisConfig, FullySpecifiedConfig]): Server
    Annotations
    @deprecated
    Deprecated

    (Since version 5.0.1) Used for ABI compat

  5. def stack[Req1, Rep1](mk: (Params) ⇒ finagle.Server[Req1, Rep1]): ServerBuilder[Req1, Rep1, Yes, HasBindTo, HasName]

    Overrides the stack and com.twitter.finagle.Server that will be used by this builder.

    Overrides the stack and com.twitter.finagle.Server that will be used by this builder.

    mk

    A function that materializes a Server from a set of Params. mk is passed the state of configuration when build is called. There is no guarantee that all the builder parameters will be used by the server created by mk; it is up to the discretion of the server and protocol implementation.

    Annotations
    @deprecated
    Deprecated

    (Since version 7.0.0) Use stack(server: StackBasedServer)

Inherited from AnyRef

Inherited from Any

Ungrouped