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. abstract class AbstractResolver extends Resolver

    An abstract class version of Resolver for java compatibility.

  3. sealed trait Addr extends AnyRef

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

  4. trait Announcement extends Closable

  5. trait Announcer extends AnyRef

  6. class AnnouncerForumInvalid extends Exception

  7. class AnnouncerNotFoundException extends Exception

  8. class ApiException extends Exception

  9. class ApplicationException extends Exception

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

    A typeclass for "stackable" items.

  11. class CancelledConnectionException extends RequestException

    A Future is satisfied with this exception when the process of establishing a session is interrupted.

  12. class CancelledReadException extends TransportException

  13. class CancelledRequestException extends RequestException

    Cancellation is propagated between a Finagle server and client intra-process when the server is interrupted by an upstream service.

  14. class CancelledWriteException extends TransportException

  15. class ChannelBufferUsageException extends Exception

  16. class ChannelClosedException extends ChannelException with NoStacktrace

  17. class ChannelException extends Exception with SourcedException

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

    Default implementation for WriteException that wraps an underlying exception.

  19. trait Client[Req, Rep] extends AnyRef

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

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

    Clients

  21. trait ClientConnection extends Closable

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

  22. trait Codec[Req, Rep] extends AnyRef

    Superclass for all codecs.

  23. class CodecException extends Exception

  24. trait CodecFactory[Req, Rep] extends AnyRef

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

  25. class ConnectionFailedException extends ChannelException with NoStacktrace

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

  27. trait ContextHandler extends AnyRef

    A ContextHandler is responsible for maintaining a context.

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

    Trait Dentry describes a delegation table entry.

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

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

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

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

  33. class FailedFastException extends RequestException

  34. final class Failure extends Exception with NoStacktrace

    Base exception for all Finagle originated failures.

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

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

  36. class GlobalRequestTimeoutException extends RequestTimeoutException

  37. class InconsistentStateException extends ChannelException

  38. class IndividualRequestTimeoutException extends RequestTimeoutException

  39. class InvalidPipelineException extends ApiException

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

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

    Trait ListeningServer represents a bound and listening server.

  42. class MultipleAnnouncersPerSchemeException extends Exception with NoStacktrace

  43. class MultipleResolversPerSchemeException extends Exception with NoStacktrace

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

  45. sealed trait Name extends AnyRef

    Names identify network locations.

  46. sealed trait NameTree[+T] extends AnyRef

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

  47. trait Namer extends AnyRef

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

  48. class NoBrokersAvailableException extends RequestException

  49. trait NoStacktrace extends Exception

  50. class NotServableException extends RequestException

  51. class NotShardableException extends NotServableException

  52. class NotYetConnectedException extends ApiException

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

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

  54. trait ProxyAnnouncement extends Announcement with Proxy

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

  56. class ReplyCastException extends RequestException

  57. class RequestException extends Exception with NoStacktrace with SourcedException

    Request failures (eg.

  58. class RequestTimeoutException extends RequestException with TimeoutException

  59. trait Resolver extends AnyRef

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

  60. class ResolverAddressInvalid extends Exception

  61. class ResolverNotFoundException extends Exception

  62. class RetryFailureException extends RequestException

  63. trait Server[Req, Rep] extends AnyRef

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

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

    Servers

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

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

  66. class ServiceClosedException extends Exception with ServiceException

  67. trait ServiceException extends Exception with SourcedException

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

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

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

  70. trait ServiceFactoryWrapper extends AnyRef

    A ServiceFactoryWrapper adds behavior to an underlying ServiceFactory.

  71. class ServiceNotAvailableException extends Exception with ServiceException

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

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

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

    Indicates that the connection was not established within the timeouts.

  74. class ShardNotAvailableException extends NotServableException

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

  76. trait SourcedException extends Exception

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

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

  79. class StackBuilder[T] extends AnyRef

    StackBuilders are imperative-style builders for Stacks.

  80. trait Stackable[T] extends Head

    Produce a stack from a T-typed element.

  81. trait TimeoutException extends Exception with SourcedException

  82. class TooManyConcurrentRequestsException extends ApiException

  83. class TooManyWaitersException extends RequestException

  84. class TransportException extends Exception with SourcedException

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

  86. trait WriteException extends Exception with SourcedException

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

  87. class WriteTimedOutException extends ChannelException

  88. trait Group[T] extends AnyRef

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

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

    Object Dtab manages 'base' and 'local' Dtabs.

  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

    Resolver for inet scheme.

  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 WeightedInetSocketAddress

  29. object WeightedSocketAddress

    A SocketAddress with a weight.

  30. object WriteException extends Serializable

  31. package builder

  32. package channel

  33. package client

  34. package core

  35. package dispatch

  36. package exp

    Package exp contains experimental code.

  37. package factory

  38. package filter

  39. package group

  40. package httpproxy

  41. package jsr166y

  42. package loadbalancer

  43. package netty3

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

  44. object param

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

  45. package pool

  46. package server

  47. package service

  48. package socks

  49. package ssl

  50. object stack

  51. package stats

  52. package tracing

  53. package transport

  54. package util

Inherited from AnyRef

Inherited from Any

Ungrouped