com.twitter

finagle

package finagle

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 org.jboss.netty.handler.codec.http.{
  HttpRequest, HttpResponse, DefaultHttpResponse}
import org.jboss.netty.handler.codec.http.HttpVersion._
import org.jboss.netty.handler.codec.http.HttpResponseStatus._
import com.twitter.util.{Future, Await}

val service = new Service[HttpRequest, HttpResponse] {
  def apply(req: HttpRequest) =
    Future.value(new DefaultHttpResponse(HTTP_1_1, OK))
}
val server = Http.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 org.jboss.netty.handler.codec.http.{
  HttpRequest, HttpResponse, DefaultHttpRequest}
import org.jboss.netty.handler.codec.http.HttpVersion._
import org.jboss.netty.handler.codec.http.HttpMethod._
import com.twitter.util.{Future, Return, Throw}

val client: Service[HttpRequest, HttpResponse] =
  Http.newService("localhost:8080")
val f: Future[HttpResponse] =
  client(new DefaultHttpRequest(HTTP_1_1, GET, "/"))
f respond {
  case Return(res) =>
    printf("Got HTTP response %s\n", res)
  case Throw(exc) =>
    printf("Got error %s\n", exc)
}

Http.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.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. finagle
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. abstract class AbstractCodec[Req, Rep] extends Codec[Req, Rep]

    An abstract class version of the above for java compatibility.

  2. sealed trait Addr extends AnyRef

    An address identifies the location of an object--it is a bound name.

  3. trait Announcement extends Closable

  4. trait Announcer extends AnyRef

  5. class AnnouncerForumInvalid extends Exception

  6. class AnnouncerNotFoundException extends Exception

  7. class ApiException extends Exception

  8. class ApplicationException extends Exception

  9. trait CanStackFrom[-From, To] extends AnyRef

    A typeclass for "stackable" items.

  10. class CancelledConnectionException extends RequestException

  11. class CancelledReadException extends TransportException

  12. class CancelledRequestException extends RequestException

  13. class CancelledWriteException extends TransportException

  14. class ChannelBufferUsageException extends Exception

  15. class ChannelClosedException extends ChannelException with NoStacktrace

  16. class ChannelException extends Exception with SourcedException

  17. case class ChannelWriteException(underlying: Throwable) extends ChannelException with WriteException with NoStacktrace with Product with Serializable

    Default implementation for WriteException that wraps an underlying exception.

  18. trait Client[Req, Rep] extends AnyRef

    RPC clients with Req-typed requests and Rep typed replies.

  19. case class ClientCodecConfig(serviceName: String) extends Product with Serializable

    Clients

  20. trait ClientConnection extends Closable

    Information about a client, passed to a Service factory for each new connection.

  21. trait Codec[Req, Rep] extends AnyRef

    Superclass for all codecs.

  22. class CodecException extends Exception

  23. trait CodecFactory[Req, Rep] extends AnyRef

    A combined codec factory provides both client and server codec factories in one (when available).

  24. class ConnectionFailedException extends ChannelException with NoStacktrace

  25. case class ConnectionRefusedException(remoteAddress: SocketAddress) extends ChannelException with Product with Serializable

  26. trait ContextHandler extends AnyRef

    A ContextHandler is responsible for maintaining a context.

  27. case class Dentry(prefix: Path, dst: NameTree[Path]) extends Product with Serializable

    Trait Dentry describes a delegation table entry.

  28. case class Dtab(dentries0: IndexedSeq[Dentry]) extends IndexedSeq[Dentry] with Namer with Product with Serializable

    A Dtab--short for delegation table--comprises a sequence of delegation rules.

  29. final class DtabBuilder extends Builder[Dentry, Dtab]

  30. class FactoryToService[Req, Rep] extends Service[Req, Rep]

  31. case class FailFastException() extends ChannelException with Product with Serializable

  32. class FailedFastException extends RequestException

  33. final case class Failure extends RuntimeException with NoStacktrace with Product with Serializable

    Base exception for all Finagle originated failures.

  34. abstract class Filter[-ReqIn, +RepOut, +ReqOut, -RepIn] extends (ReqIn, Service[ReqOut, RepIn]) ⇒ Future[RepOut]

    A Filter acts as a decorator/transformer of a service.

  35. class GlobalRequestTimeoutException extends RequestTimeoutException

  36. class InconsistentStateException extends ChannelException

  37. class IndividualRequestTimeoutException extends RequestTimeoutException

  38. class InvalidPipelineException extends ApiException

  39. case class LabelledGroup[T](underlying: Group[T], name: String) extends Group[T] with Product with Serializable

    A mixin trait to assign a name to the group.

  40. trait ListeningServer extends Closable with Awaitable[Unit] with Group[SocketAddress]

    Trait ListeningServer represents a bound and listening server.

  41. class MultipleAnnouncersPerSchemeException extends Exception with NoStacktrace

  42. class MultipleResolversPerSchemeException extends Exception with NoStacktrace

  43. trait MutableGroup[T] extends Group[T]

  44. sealed trait Name extends AnyRef

    Names identify network locations.

  45. sealed trait NameTree[+T] extends AnyRef

    Name trees represent a composite T-typed name whose interpretation is subject to evaluation rules.

  46. trait Namer extends AnyRef

    A namer is a context in which a com.twitter.finagle.NameTree NameTree is bound.

  47. class NoBrokersAvailableException extends RequestException

  48. trait NoStacktrace extends Exception

  49. class NotServableException extends RequestException

  50. class NotShardableException extends NotServableException

  51. class NotYetConnectedException extends ApiException

  52. case class Path(elems: Buf*) extends Product with Serializable

    A Path comprises a sequence of byte buffers naming a hierarchically-addressed object.

  53. trait ProxyAnnouncement extends Announcement with Proxy

  54. case class RefusedByRateLimiter() extends ChannelException with Product with Serializable

  55. class ReplyCastException extends RequestException

  56. class RequestException extends Exception with NoStacktrace with SourcedException

    Request failures (eg.

  57. class RequestTimeoutException extends RequestException with TimeoutException

  58. trait Resolver extends AnyRef

    A resolver binds a name, represented by a string, to a variable address.

  59. class ResolverAddressInvalid extends Exception

  60. class ResolverNotFoundException extends Exception

  61. class RetryFailureException extends RequestException

  62. trait Server[Req, Rep] extends AnyRef

    Servers implement RPC servers with Req-typed requests and Rep-typed responses.

  63. case class ServerCodecConfig(serviceName: String, boundAddress: SocketAddress) extends Product with Serializable

    Servers

  64. abstract class Service[-Req, +Rep] extends (Req) ⇒ Future[Rep] with Closable

    A Service is an asynchronous function from Request to Future[Response].

  65. class ServiceClosedException extends Exception with ServiceException

  66. trait ServiceException extends Exception with SourcedException

  67. abstract class ServiceFactory[-Req, +Rep] extends (ClientConnection) ⇒ Future[Service[Req, Rep]] with Closable

  68. abstract class ServiceFactoryProxy[-Req, +Rep] extends ServiceFactory[Req, Rep] with ProxyServiceFactory[Req, Rep]

    A simple proxy ServiceFactory that forwards all calls to another ServiceFactory.

  69. trait ServiceFactoryWrapper extends AnyRef

    A ServiceFactoryWrapper adds behavior to an underlying ServiceFactory.

  70. class ServiceNotAvailableException extends Exception with ServiceException

  71. abstract class ServiceProxy[-Req, +Rep] extends Service[Req, Rep] with Proxy

    A simple proxy Service that forwards all calls to another Service.

  72. class ServiceTimeoutException extends Exception with WriteException with ServiceException with TimeoutException

    Indicates that the connection was not established within the timeouts.

  73. class ShardNotAvailableException extends NotServableException

  74. abstract class SimpleFilter[Req, Rep] extends Filter[Req, Rep, Req, Rep]

  75. trait SourcedException extends Exception

  76. case class SslHandshakeException(underlying: Throwable, remoteAddress: SocketAddress) extends ChannelException with Product with Serializable

  77. case class SslHostVerificationException(principal: String) extends ChannelException with Product with Serializable

  78. class StackBuilder[T] extends AnyRef

    StackBuilders are imperative-style builders for Stacks.

  79. trait Stackable[T] extends AnyRef

    Produce a stack from a T-typed element.

  80. trait TimeoutException extends Exception with SourcedException

  81. class TooManyConcurrentRequestsException extends ApiException

  82. class TooManyWaitersException extends RequestException

  83. class TransportException extends Exception with SourcedException

  84. case class UnknownChannelException(underlying: Throwable, remoteAddress: SocketAddress) extends ChannelException with Product with Serializable

  85. trait WriteException extends Exception with SourcedException

    Marker trait to indicate there was an exception while writing the request.

  86. class WriteTimedOutException extends ChannelException

  87. trait Group[T] extends AnyRef

    A group is a dynamic set of T-typed values.

  88. trait ProxyServiceFactory[-Req, +Rep] extends ServiceFactory[Req, Rep] with Proxy

    Annotations
    @deprecated
    Deprecated

    (Since version 6.7.5) use ServiceFactoryProxy instead

Value Members

  1. object Addr

  2. object Announcer

  3. object BackupRequestLost extends Exception with NoStacktrace

  4. object CanStackFrom

  5. object ChannelException extends Serializable

  6. object ClientConnection

  7. object Codec

  8. object Context

    A context is a piece of serializable metadata managed by a registered handler.

  9. object Dentry extends Serializable

  10. object Dtab extends Serializable

  11. object FailResolver extends Resolver

  12. object Failure extends Serializable

    Defines convenient methods for contructing and extracting failures.

  13. object Filter

  14. object Group

  15. object InetResolver extends Resolver

  16. object Name

  17. object NameTree

    The NameTree object comprises NameTree types as well as binding and evaluation routines.

  18. object Namer

  19. object NegResolver extends Resolver

  20. object NilResolver extends Resolver

  21. object NoStacktrace extends Serializable

  22. object NullServer extends ListeningServer with CloseAwaitably

    An empty ListeningServer that can be used as a placeholder.

  23. object Path extends Serializable

  24. object Resolver

  25. object Service

  26. object ServiceFactory

  27. object ServiceFactoryWrapper

  28. object Stack

  29. object WeightedInetSocketAddress

  30. object WeightedSocketAddress

    A SocketAddress with a weight.

  31. object WriteException extends Serializable

  32. package builder

  33. package channel

  34. package client

  35. package core

  36. package dispatch

  37. package exp

    Package exp contains experimental code.

  38. package factory

  39. package filter

  40. package group

  41. package httpproxy

  42. package jsr166y

  43. package loadbalancer

  44. package netty3

    Package netty3 implements the bottom finagle primitives: {{com.

  45. object param

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

  46. package pool

  47. package server

  48. package service

  49. package socks

  50. package ssl

  51. object stack

  52. package stats

  53. package tracing

  54. package transport

  55. package util

Inherited from AnyRef

Inherited from Any

Ungrouped