com.twitter.finagle

builder

package builder

Visibility
  1. Public
  2. All

Type Members

  1. class ClientBuilder[Req, Rep, HasCluster, HasCodec, HasHostConnectionLimit] extends AnyRef

    A builder of Finagle Clients.

    A builder of Finagle Clients.

    Please see the Finagle user guide for information on a newer set of client-construction APIs introduced in Finagle v6.

    val client = ClientBuilder()
      .codec(Http)
      .hosts("localhost:10000,localhost:10001,localhost:10003")
      .hostConnectionLimit(1)
      .tcpConnectTimeout(1.second)        // max time to spend establishing a TCP connection.
      .retries(2)                         // (1) per-request retries
      .reportTo(new OstrichStatsReceiver) // export host-level load data to ostrich
      .logger(Logger.getLogger("http"))
      .build()

    The ClientBuilder requires the definition of cluster, codec, and hostConnectionLimit. 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

    Service<HttpRequest, HttpResponse> service =
     ClientBuilder.safeBuild(
       ClientBuilder.get()
         .codec(new Http())
         .hosts("localhost:10000,localhost:10001,localhost:10003")
         .hostConnectionLimit(1)
         .tcpConnectTimeout(1.second)
         .retries(2)
         .reportTo(new OstrichStatsReceiver())
         .logger(Logger.getLogger("http")))

    Alternatively, using the unsafeBuild method on ClientBuilder verifies the builder dynamically, resulting in a runtime error instead of a compiler error.

    Defaults

    The following defaults are applied to clients constructed via ClientBuilder, unless overridden with the corresponding method. These defaults were chosen carefully so as to work well for most use cases.

    Commonly-configured options:

    • connectTimeout: Duration.Top
    • tcpConnectTimeout: 1 second
    • requestTimeout: Duration.Top
    • timeout: Duration.Top
    • hostConnectionLimit: Int.MaxValue
    • hostConnectionCoresize: 0
    • hostConnectionIdleTime: Duration.Top
    • hostConnectionMaxWaiters: Int.MaxValue
    • failFast: true
    • failureAccrualParams, failureAccrualFactory: numFailures = 5, markDeadFor = 5 seconds

    Advanced options:

    Before changing any of these, make sure that you know exactly how they will affect your application -- these options are typically only changed by expert users.

    • keepAlive: Unspecified, in which case the Java default of false is used
    • readerIdleTimeout: Duration.Top
    • writerIdleTimeout: Duration.Top
    • hostConnectionMaxIdleTime: Duration.Top
    • hostConnectionMaxLifeTime: Duration.Top
    • sendBufferSize, recvBufferSize: OS-defined default value
  2. class IncompleteSpecification extends Exception

    Used by builder to throw exceptions if the specification is incomplete.

    Used by builder to throw exceptions if the specification is incomplete.

    if (!_codec.isDefined)
      throw new IncompleteSpecification("No codec was specified")
  3. trait Server extends ListeningServer

    A listening server.

    A listening server. This is for compatibility with older code that is using builder.Server. New code should use the ListeningServer trait.

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

    A handy Builder for constructing Servers (i.e., binding Services to a port).

    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.

    The main class to use is com.twitter.finagle.builder.ServerBuilder, as so

    ServerBuilder()
      .codec(Http)
      .hostConnectionMaxLifeTime(5.minutes)
      .readTimeout(2.minutes)
      .name("servicename")
      .bindTo(new InetSocketAddress(serverPort))
      .build(plusOneService)

    The ServerBuilder requires the definition of codec, 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()
      .codec(Http)
      .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

  5. trait ServerConfigEvidence[HasCodec, HasBindTo, HasName] extends AnyRef

    Annotations
    @implicitNotFound( ... )
  6. class SourceTrackingMonitor extends Monitor

    A monitor that unrolls the exception causes to report source information if any

  7. trait Cluster[T] extends AnyRef

    Cluster is a collection of servers.

    Cluster is a collection of servers. The intention of this interface to express membership in a cluster of servers that provide a specific service.

    Note that a Cluster can be elastic: members can join or leave at any time.

    Annotations
    @deprecated
    Deprecated

    (Since version 2014-11-21) Use com.twitter.finagle.Name to represent clusters instead

  8. class MinimumSetCluster[T] extends Cluster[T]

    A Cluster implementation that guarantees a minimum set while allowing you to specify a Cluster to supplement the initial static set.

    A Cluster implementation that guarantees a minimum set while allowing you to specify a Cluster to supplement the initial static set. All operations that would remove entries in the minimum set are censored and counted.

    Annotations
    @deprecated
    Deprecated

    (Since version 2014-11-21) Use com.twitter.finagle.Name to represent clusters instead

  9. class NonShrinkingCluster[T] extends Cluster[T]

    Dynamic clusters, such as serversets, can be volatile and untrustworthy.

    Dynamic clusters, such as serversets, can be volatile and untrustworthy. Finagle has mechanisms for handling failed nodes that haven't been removed from the cluster. However there are cases where a server's entry me be falsely removed from the cluster thus causing clients to exert unnecessary pressure on remaining nodes. This filter reduces that impact by delaying node removals. We do so by disallowing the cluster to shrink. Add events are always propagated but Rem events require a corresponding Add.

    Annotations
    @deprecated
    Deprecated

    (Since version 2014-11-21) Use com.twitter.finagle.Name to represent clusters instead

  10. case class StaticCluster[T](underlying: Seq[T]) extends Cluster[T] with Product with Serializable

    A simple static cluster implementation.

    A simple static cluster implementation.

    Annotations
    @deprecated
    Deprecated

    (Since version 2014-11-21) Use com.twitter.finagle.Name to represent clusters instead

Value Members

  1. object ClientBuilder

    Factory for com.twitter.finagle.builder.ClientBuilder instances

  2. object ClientConfig

  3. object Cluster

  4. object ServerBuilder

    Factory for com.twitter.finagle.builder.ServerBuilder instances

  5. object ServerConfig

Ungrouped