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 addr
    Definition Classes
    finagle
  • package builder
    Definition Classes
    finagle
  • package client
    Definition Classes
    finagle
  • package context
    Definition Classes
    finagle
  • package core
    Definition Classes
    finagle
  • package dispatch
    Definition Classes
    finagle
  • package exp

    Package exp contains experimental code.

    Package exp contains experimental code. This can be removed or stabilized (moved elsewhere) at any time.

    Definition Classes
    finagle
  • package factory
    Definition Classes
    finagle
  • package filter
    Definition Classes
    finagle
  • package liveness
    Definition Classes
    finagle
  • package loadbalancer

    This package implements client side load balancing algorithms.

    This package implements client side load balancing algorithms.

    As an end-user, see the Balancers API to create instances which can be used to configure a Finagle client with various load balancing strategies.

    As an implementor, each algorithm gets its own subdirectory and is exposed via the Balancers object. Several convenient traits are provided which factor out common behavior and can be mixed in (i.e. Balancer, DistributorT, NodeT, and Updating).

    Definition Classes
    finagle
  • package aperture
  • package exp
  • BalancerRegistry
  • Balancers
  • EndpointFactory
  • FlagBalancerFactory
  • LoadBalancerFactory
  • Metadata
  • NoNodesOpenException
  • WhenNoNodesOpen
  • WhenNoNodesOpens
  • defaultBalancer
  • perHostStats
  • package namer
    Definition Classes
    finagle
  • package naming
    Definition Classes
    finagle
  • package offload
    Definition Classes
    finagle
  • package param

    Defines common com.twitter.finagle.Stack.Param's shared between finagle clients and servers.

    Defines common com.twitter.finagle.Stack.Param's shared between finagle clients and servers.

    Definition Classes
    finagle
  • package pool
    Definition Classes
    finagle
  • package pushsession
    Definition Classes
    finagle
  • package server
    Definition Classes
    finagle
  • package service
    Definition Classes
    finagle
  • package ssl
    Definition Classes
    finagle
  • package stats
    Definition Classes
    finagle
  • package thrift
    Definition Classes
    finagle
  • package tracing
    Definition Classes
    finagle
  • package transport
    Definition Classes
    finagle
  • package util
    Definition Classes
    finagle
p

com.twitter.finagle

loadbalancer

package loadbalancer

This package implements client side load balancing algorithms.

As an end-user, see the Balancers API to create instances which can be used to configure a Finagle client with various load balancing strategies.

As an implementor, each algorithm gets its own subdirectory and is exposed via the Balancers object. Several convenient traits are provided which factor out common behavior and can be mixed in (i.e. Balancer, DistributorT, NodeT, and Updating).

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

Package Members

  1. package aperture
  2. package exp

Type Members

  1. final class BalancerRegistry extends AnyRef

    A registry of load balancers currently in use.

    A registry of load balancers currently in use.

    This class is thread-safe.

    See also

    BalancerRegistry$.get()

    TwitterServer's "/admin/balancers.json" admin endpoint.

  2. trait EndpointFactory[Req, Rep] extends ServiceFactory[Req, Rep]

    A specialized ServiceFactory which admits that it backs a concrete endpoint.

    A specialized ServiceFactory which admits that it backs a concrete endpoint. The extra information and functionality provided here is used by Finagle's load balancers.

  3. abstract class LoadBalancerFactory extends AnyRef

    A thin interface around a Balancer's constructor that allows Finagle to pass in context from the stack to the balancers at construction time.

    A thin interface around a Balancer's constructor that allows Finagle to pass in context from the stack to the balancers at construction time.

    See also

    Balancers for a collection of available balancers.

    The user guide for more details.

  4. final class Metadata extends AnyRef

    Information about a load balancer.

    Information about a load balancer.

    This class is thread-safe and while the class itself is immutable, it proxies data from a Balancer which may be mutable.

    See also

    BalancerRegistry

    TwitterServer's "/admin/balancers.json" admin endpoint.

  5. class NoNodesOpenException extends RuntimeException with FailureFlags[NoNodesOpenException] with HasLogLevel with SourcedException

    While this exception is safe to retry, the assumption used here is that the underlying situation will not change soon enough to make a retry worthwhile as retrying is most likely to eat up the entire budget.

  6. sealed trait WhenNoNodesOpen extends AnyRef

    The behavior the load balancer should take when none of its nodes have a com.twitter.finagle.Status of Open.

    The behavior the load balancer should take when none of its nodes have a com.twitter.finagle.Status of Open.

    The default behavior is WhenNoNodesOpen.PickOne and can be customized on a client through LoadBalancerFactory.WhenNoNodesOpenParam:

    import com.twitter.finagle.loadbalancer.LoadBalancerFactory.WhenNoNodesOpenParam
    import com.twitter.finagle.loadbalancer.WhenNoNodesOpen
    import com.twitter.finagle.Http
    
    Http.client
      .configured(WhenNoNodesOpenParam(WhenNoNodesOpen.FailFast))
    See also

    the user guide.

    WhenNoNodesOpens for Java friendly API.

  7. final class WhenNoNodesOpens extends AnyRef

    Java API for WhenNoNodesOpen.

Value Members

  1. def defaultAddressOrdering: Ordering[Address]

    Returns the default process global Address ordering as set via defaultAddressOrdering.

    Returns the default process global Address ordering as set via defaultAddressOrdering. If no value is set, Address.HashOrdering is used with the assumption that hosts resolved via Finagle provide the load balancer with resolved InetAddresses. If a separate resolution process is used, outside of Finagle, the default ordering should be overridden.

  2. def defaultAddressOrdering(order: Ordering[Address]): Unit

    Set the default Address ordering for the entire process (outside of clients which override it).

    Set the default Address ordering for the entire process (outside of clients which override it).

    See also

    LoadBalancerFactory.AddressOrdering for more info.

  3. def defaultBalancerFactory: LoadBalancerFactory

    Returns the default process global LoadBalancerFactory as set via defaultBalancerFactory.

  4. def defaultBalancerFactory(factory: LoadBalancerFactory): Unit

    Set the default LoadBalancerFactory for the entire process (outside of clients which override it).

    Set the default LoadBalancerFactory for the entire process (outside of clients which override it).

    See also

    LoadBalancerFactory.Param for more info.

  5. object BalancerRegistry
  6. object Balancers

    Constructor methods for various load balancers.

    Constructor methods for various load balancers. The methods take balancer specific parameters and return a LoadBalancerFactory that allows you to easily inject a balancer into the Finagle client stack via the withLoadBalancer method.

    Example:
    1. configuring a client with a load balancer

      $Protocol.client
        .withLoadBalancer(Balancers.aperture())
        .newClient(...)
    See also

    The user guide for more details.

  7. object FlagBalancerFactory extends LoadBalancerFactory

    A LoadBalancerFactory proxy which instantiates the underlying based on flags (see flags.scala for applicable flags).

  8. object LoadBalancerFactory

    Exposes a Stack.Module which composes load balancing into the respective Stack.

    Exposes a Stack.Module which composes load balancing into the respective Stack. This is mixed in by default into Finagle's com.twitter.finagle.client.StackClient. The only necessary configuration is a LoadBalancerFactory.Dest which represents a changing collection of addresses that is load balanced over.

  9. object WhenNoNodesOpen
  10. object defaultBalancer extends GlobalFlag[String]

    A GlobalFlag that changes the default balancer for every client in the process.

    A GlobalFlag that changes the default balancer for every client in the process. Valid choices are ['heap', 'choice', 'aperture', and 'random_aperture'].

    Note

    that 'random_aperture' should only be used in unusual situations such as for testing instances and requires extra configuration. See the aperture documentation for more information. To configure the load balancer on a per-client granularity instead, use the withLoadBalancer method like so: {{ val balancer = Balancers.aperture(...) $Protocol.client.withLoadBalancer(balancer) }}

  11. object perHostStats extends GlobalFlag[Boolean]

    A GlobalFlag which allows the configuration of per host (or endpoint) stats to be toggled.

    A GlobalFlag which allows the configuration of per host (or endpoint) stats to be toggled. Note, these are off by default because they tend to be expensive, especially when the size of the destination cluster is large. However, they can be quite useful for debugging.

Inherited from AnyRef

Inherited from Any

Ungrouped