com.twitter

finagle

package finagle

Finagle Introduction

Start with finagle. Both clients and and servers are services Service, which are typically created with the ClientBuilder ClientBuilder and ServerBuilder ServerBuilder class, respectively.

The following example shows how to build a simple HTTP server:

val service: Service[HttpRequest, HttpResponse] = new Service[HttpRequest, HttpResponse] {
  def apply(request: HttpRequest) = Future(new DefaultHttpResponse(HTTP_1_1, OK))
}

val address: SocketAddress = new InetSocketAddress(10000)

val server: Server[HttpRequest, HttpResponse] = ServerBuilder()
  .codec(Http)         // HTTP codec, defined in Netty
  .bindTo(address)     // one or more hosts; localhost:10000 in this example
  .name("HttpServer")  // name of your service
  .build(service)      // build the server

The following example shows how to build a simple HTTP client, which handles asynchronous responses:

val client: Service[HttpRequest, HttpResponse] = ClientBuilder()
   .codec(Http)             // HTTP codec, defined in Netty
   .hosts(address)          // one or more hosts; localhost:10000 in this example
   .hostConnectionLimit(1)  // 1 connection per host
   .build()                 // build the client

// Issue a request, get a response:
val request: HttpRequest = new DefaultHttpRequest(HTTP_1_1, GET, "/")
val responseFuture: Future[HttpResponse] = client(request)           // response to request is a Future, which enables async execution
  onSuccess { response => println("Received response: " + response)  // Finagle calls onSuccess when the response becomes available
                                                                     // onFailure could be defined to catch exceptions
}

For information about the Future class, which is essential for most RPC applications, see the scaladoc for Util.

For exceptions you can catch, see RequestException and ApiException.

For imports and more ideas of how to use Finagle, see the examples.

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. trait Announcement extends Closable

  3. trait Announcer extends AnyRef

  4. class AnnouncerForumInvalid extends Exception

  5. class AnnouncerNotFoundException extends Exception

  6. class ApiException extends Exception

  7. class ApplicationException extends Exception

  8. class CancelledConnectionException extends RequestException

  9. class CancelledReadException extends TransportException

  10. class CancelledRequestException extends RequestException

  11. class CancelledWriteException extends TransportException

  12. class ChannelBufferUsageException extends Exception

  13. class ChannelClosedException extends ChannelException with NoStacktrace

  14. class ChannelException extends Exception with SourcedException

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

    Default implementation for WriteException that wraps an underlying exception.

  16. trait Client[Req, Rep] extends AnyRef

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

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

    Clients

  18. trait ClientConnection extends Closable

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

  19. trait Codec[Req, Rep] extends AnyRef

    Superclass for all codecs.

  20. class CodecException extends Exception

  21. trait CodecFactory[Req, Rep] extends AnyRef

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

  22. class ConnectionFailedException extends ChannelException with NoStacktrace

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

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

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

  26. class FailedFastException extends RequestException

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

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

  28. class GlobalRequestTimeoutException extends RequestTimeoutException

  29. trait Group[T] extends AnyRef

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

  30. class InconsistentStateException extends ChannelException

  31. class IndividualRequestTimeoutException extends RequestTimeoutException

  32. class InvalidPipelineException extends ApiException

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

    Trait ListeningServer represents a bound and listening server.

  34. class MultipleAnnouncersPerSchemeException extends Exception with NoStacktrace

  35. class MultipleResolversPerSchemeException extends Exception with NoStacktrace

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

  37. trait NamedGroup extends AnyRef

    A mixin trait to assign a name to the group.

  38. class NoBrokersAvailableException extends RequestException

  39. trait NoStacktrace extends Exception

  40. class NotServableException extends RequestException

  41. class NotShardableException extends NotServableException

  42. class NotYetConnectedException extends ApiException

  43. trait ProxyAnnouncement extends Announcement with Proxy

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

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

  46. class ReplyCastException extends RequestException

  47. class RequestException extends Exception with NoStacktrace with SourcedException

    Request failures (eg.

  48. class RequestTimeoutException extends RequestException with TimeoutException

  49. trait ResolvedGroup extends Group[SocketAddress] with Proxy with NamedGroup

  50. trait Resolver extends AnyRef

  51. class ResolverNotFoundException extends Exception

  52. class ResolverTargetInvalid extends Exception

  53. class RetryFailureException extends RequestException

  54. trait Server[Req, Rep] extends AnyRef

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

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

    Servers

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

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

  57. class ServiceClosedException extends Exception with ServiceException

  58. trait ServiceException extends Exception with SourcedException

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

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

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

  61. trait ServiceFactoryWrapper extends AnyRef

    A ServiceFactoryWrapper adds behavior to an underlying ServiceFactory.

  62. class ServiceNotAvailableException extends Exception with ServiceException

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

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

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

    Indicates that the connection was not established within the timeouts.

  65. class ShardNotAvailableException extends NotServableException

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

  67. trait SourcedException extends Exception

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

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

  70. trait TimeoutException extends Exception with SourcedException

  71. class TooManyConcurrentRequestsException extends ApiException

  72. class TooManyWaitersException extends RequestException

  73. class TransportException extends Exception with SourcedException

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

  75. trait WriteException extends Exception with SourcedException

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

  76. class WriteTimedOutException extends ChannelException

Value Members

  1. object Announcer extends AnyRef

  2. object BackupRequestLost extends Exception with NoStacktrace

  3. object ChannelException extends Serializable

  4. object ClientConnection extends AnyRef

  5. object Codec extends AnyRef

  6. object Filter extends AnyRef

  7. object Group extends AnyRef

  8. object InetResolver extends Resolver

  9. object NamedGroup extends AnyRef

  10. object NullServer extends ListeningServer with CloseAwaitably

    An empty ListeningServer that can be used as a placeholder.

  11. object Resolver extends AnyRef

  12. object Service extends AnyRef

  13. object ServiceFactory extends AnyRef

  14. object ServiceFactoryWrapper extends AnyRef

  15. object WriteException extends Serializable

  16. package builder

  17. package channel

  18. package client

  19. package core

  20. package dispatch

  21. package factory

  22. package filter

  23. package group

  24. package httpproxy

  25. package loadbalancer

  26. package netty3

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

  27. package pool

  28. package server

  29. package service

  30. package socks

  31. package ssl

  32. package stats

  33. package tracing

  34. package transport

  35. package util