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. class ApiException extends Exception

  3. class ApplicationException extends Exception

  4. class CancelledConnectionException extends RequestException

  5. class CancelledReadException extends TransportException

  6. class CancelledRequestException extends RequestException

  7. class CancelledWriteException extends TransportException

  8. class ChannelBufferUsageException extends Exception

  9. class ChannelClosedException extends ChannelException with NoStacktrace

  10. class ChannelException extends Exception with SourcedException

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

    Clients

  12. trait ClientConnection extends Closable

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

  13. trait Codec[Req, Rep] extends AnyRef

    Superclass for all codecs.

  14. class CodecException extends Exception

  15. trait CodecFactory[Req, Rep] extends AnyRef

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

  16. class ConnectionFailedException extends ChannelException with NoStacktrace

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

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

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

  20. class FailedFastException extends RequestException

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

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

  22. class GlobalRequestTimeoutException extends RequestTimeoutException

  23. trait Group[T] extends AnyRef

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

  24. class GroupDestinationInvalid extends Exception

  25. trait GroupResolver extends (String) ⇒ Group[SocketAddress]

  26. class GroupResolverNotFoundException extends Exception

  27. class InconsistentStateException extends ChannelException

  28. class IndividualRequestTimeoutException extends RequestTimeoutException

  29. class InvalidPipelineException extends ApiException

  30. trait ListeningServer extends Closable

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

  32. class NoBrokersAvailableException extends RequestException

  33. trait NoStacktrace extends Exception

  34. class NotServableException extends RequestException

  35. class NotShardableException extends NotServableException

  36. class NotYetConnectedException extends ApiException

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

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

  39. class ReplyCastException extends RequestException

  40. class RequestException extends Exception with NoStacktrace with SourcedException

    Request failures (eg.

  41. class RequestTimeoutException extends RequestException with TimeoutException

  42. class RetryFailureException extends RequestException

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

    Servers

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

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

  45. class ServiceClosedException extends Exception with ServiceException

  46. trait ServiceException extends Exception with SourcedException

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

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

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

  49. trait ServiceFactoryWrapper extends AnyRef

    A ServiceFactoryWrapper adds behavior to an underlying ServiceFactory.

  50. class ServiceNotAvailableException extends Exception with ServiceException

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

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

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

    Indicates that the connection was not established within the timeouts.

  53. class ShardNotAvailableException extends NotServableException

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

  55. trait SourcedException extends Exception

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

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

  58. trait TimeoutException extends Exception with SourcedException

  59. class TooManyConcurrentRequestsException extends ApiException

  60. class TooManyWaitersException extends RequestException

  61. class TransportException extends Exception with SourcedException

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

  63. trait WriteException extends Exception with SourcedException

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

  64. class WriteTimedOutException extends ChannelException

Value Members

  1. object ChannelException extends Serializable

  2. object ClientConnection extends AnyRef

  3. object Codec extends AnyRef

  4. object Filter extends AnyRef

  5. object Group extends AnyRef

  6. object InetGroupResolver extends GroupResolver

  7. object Service extends AnyRef

  8. object ServiceFactory extends AnyRef

  9. object ServiceFactoryWrapper extends AnyRef

  10. object WriteException extends Serializable

  11. package builder

  12. package channel

  13. package client

  14. package core

  15. package dispatch

  16. package exp

    Package exp contains experimental code.

  17. package factory

  18. package filter

  19. package loadbalancer

  20. package netty3

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

  21. package pool

  22. package server

  23. package service

  24. package socks

  25. package ssl

  26. package stats

  27. package tracing

  28. package transport

  29. package util

    Disposable represents a live resource that must be disposed after use.