Package

colossus

service

Permalink

package service

Visibility
  1. Public
  2. All

Type Members

  1. trait Async[M[_]] extends AnyRef

    Permalink

    A Typeclass for abstracting over callbacks and futures

  2. trait AsyncBuilder[M[_], E] extends AnyRef

    Permalink

    A Typeclass for building Async instances, used internally by ClientFactory.

    A Typeclass for building Async instances, used internally by ClientFactory. This is needed to get the environment into the Async.

  3. class AsyncHandlerGenerator[C <: Protocol] extends AnyRef

    Permalink

    So we need to take a type-parameterized request object, package it into a monomorphic case class to send to the worker, and have the handler that receives that object able to pattern match out the parameterized object, all without using reflection.

    So we need to take a type-parameterized request object, package it into a monomorphic case class to send to the worker, and have the handler that receives that object able to pattern match out the parameterized object, all without using reflection. We can do that with some nifty path-dependant types

  4. class BasicLiftedClient[C <: Protocol, M[_]] extends LiftedClient[C, M]

    Permalink
  5. sealed trait Callback[+O] extends AnyRef

    Permalink

    A Callback is a Monad for doing in-thread non-blocking operations.

    A Callback is a Monad for doing in-thread non-blocking operations. It is essentially a "function builder" that uses function composition to chain together a callback function that is eventually passed to another function.

    Normally if you have a function that requires a callback, the function looks something like:

    def doSomething(param, param, callBack: result => Unit)

    and then you'd call it like

    doSomething(arg1, arg2, result => println("got the result"))

    This is the well-known continuation pattern, and it something we'd like to avoid due to the common occurrance of deeply nested "callback hell". Instead, the Callback allows us to define out function as

    def doSomething(param1, param2): Callback[Result]

    and call it like

    val c = doSomething(arg1, arg2)
    c.map{ result =>
      println("got the result")
    }.execute()

    Thus, in practice working with Callbacks is very similar to working with Futures. The big differences from a future are:

    1. Callbacks are not thread safe at all. They are entirely intended to stay inside a single worker. Otherwise just use Futures.

    2. The execute() method needs to be called once the callback has been fully built, which unlike futures requires some part of the code to know when a callback is ready to be invoked

    Using Callbacks in Services

    When building services, particularly when working with service clients, you will usually be getting Callbacks back from clients when requests are sent. *Do not call execute yourself!* on these Callbacks. They must be returned as part of request processing, and Colossus will invoke the callback itself.

    Using Callbacks elsewhere

    If you are using Callbacks in some custom situation outside of services, be aware that exceptions thrown inside a map or flatMap are properly caught and can be recovered using recover and recoverWith, however exceptions thrown in the "final" handler passed to execute are not caught. This is because the final block cannot be mapped on (since it is only passed when the callback is executed) and throwing the exception is preferrable to suppressing it.

    Any exception that is thrown in this block is however rethrown as a CallbackExecutionException. Therefore, any "trigger" function you wrap inside a callback should properly catch this exception.

  6. class CallbackExecutionException extends Exception

    Permalink

    This exception is only thrown when there's a uncaught exception in the execution block of a Callback.

    This exception is only thrown when there's a uncaught exception in the execution block of a Callback. For example,

    val c: Callback[Foo] = getCallback()
    c.execute{
      case Success(foo) => throw new Exception("exception")
    }

    will result in a CallbackExecutionException being thrown, however

    c.map{_ => throw new Exception("exception")}.execute()

    will not because the exception can still be recovered

  7. case class CallbackExecutor(context: ExecutionContext, executor: ActorRef) extends Product with Serializable

    Permalink

    A CallbackExecutor represents a scheduler and execution environment for Callbacks and is required when either converting a Future to a Callback or scheduling delayed execution of a Callback.

    A CallbackExecutor represents a scheduler and execution environment for Callbacks and is required when either converting a Future to a Callback or scheduling delayed execution of a Callback. Every Worker provides an CallbackExecutor that can be imported when doing such operations.

  8. class CallbackPromise[T] extends AnyRef

    Permalink

    A CallbackPromise creates a callback which can be eventually filled in with a value.

    A CallbackPromise creates a callback which can be eventually filled in with a value. This works similarly to a scala Promise. CallbackPromises are not thread-safe. For thread-safety, simply use a scala Promise and use Callback.fromFuture on it's corresponding Future.

  9. trait ClientCodecProvider[C <: Protocol] extends AnyRef

    Permalink
  10. case class ClientConfig(address: InetSocketAddress, requestTimeout: Duration, name: MetricAddress, pendingBufferSize: Int = 100, sentBufferSize: Int = 100, failFast: Boolean = false, connectRetry: RetryPolicy = ..., idleTimeout: Duration = Duration.Inf, maxResponseSize: DataSize = 1.MB) extends Product with Serializable

    Permalink

    Configuration used to specify a Client's parameters

    Configuration used to specify a Client's parameters

    address

    The address with which to connect

    requestTimeout

    The request timeout value

    name

    The MetricAddress associated with this client

    pendingBufferSize

    Size of the pending buffer

    sentBufferSize

    Size of the sent buffer

    failFast

    When a failure is detected, immediately fail all pending requests.

    connectRetry

    Retry policy for connections.

    idleTimeout

    How long the connection can remain idle (both sending and receiving data) before it is closed. This should be significantly higher than requestTimeout.

    maxResponseSize

    max allowed response size -- larger responses are dropped

  11. class ClientFactories[C <: Protocol, T[M[_]] <: Sender[C, M[_]]] extends AnyRef

    Permalink

    Mixed into protocols to provide simple methods for creating clients.

  12. trait ClientFactory[C <: Protocol, M[_], T <: Sender[C, M], E] extends AnyRef

    Permalink
  13. trait ClientLifter[C <: Protocol, T[M[_]] <: Sender[C, M[_]]] extends AnyRef

    Permalink

    This has to be implemented per codec in order to lift generic Sender traits to a type-specific trait

    This has to be implemented per codec in order to lift generic Sender traits to a type-specific trait

    For example this is how we go from ServiceClient[HttpRequest, HttpResponse] to HttpClient[Callback]

  14. class ClientOverloadedException extends ServiceClientException

    Permalink

    Thrown when the pending buffer is full

  15. sealed trait ClientState extends AnyRef

    Permalink
  16. trait Codec[Output, Input] extends AnyRef

    Permalink

    A Codec is a stateful object for converting requests/responses to/from DataBuffers.

    A Codec is a stateful object for converting requests/responses to/from DataBuffers. IMPORTANT - when decoding, a codec must be able to handle both partial responses and multiple responses in a single DataBuffer. This is why a codec is stateful and returns a Seq[O]

  17. class CodecClientFactory[C <: Protocol, M[_], B <: Sender[C, M], T[M[_]] <: Sender[C, M[_]], E] extends ClientFactory[C, M, T[M], E]

    Permalink
  18. trait CodecProvider[C <: Protocol] extends AnyRef

    Permalink

    Provide a Codec as well as some convenience functions for usage within in a Service.

    Provide a Codec as well as some convenience functions for usage within in a Service.

    C

    the type of codec this provider will supply

  19. class ConnectionLostException extends ServiceClientException

    Permalink

    Thrown when a request is lost in transit

  20. case class ConstantCallback[O](value: Try[O]) extends Callback[O] with Product with Serializable

    Permalink

    A Callback containing a constant value, usually created as the result of calling Callback.success or Callback.failure.

    A Callback containing a constant value, usually created as the result of calling Callback.success or Callback.failure. See the docs for Callback for more information.

  21. class DataException extends ServiceClientException

    Permalink

    Thrown when there's some kind of data error

  22. sealed trait DecodedResult[+T] extends AnyRef

    Permalink
  23. class DefaultTagDecorator[I, O] extends TagDecorator[I, O]

    Permalink
  24. class DroppedReplyException extends ServiceServerException

    Permalink
  25. class FatalServiceServerException extends ServiceServerException

    Permalink
  26. class FutureAsync extends Async[Future]

    Permalink
  27. trait FutureClient[C <: Protocol] extends Sender[C, Future]

    Permalink
  28. trait FutureClientOps extends AnyRef

    Permalink
  29. case class IrrecoverableError[C](reason: Throwable) extends ProcessingFailure[C] with Product with Serializable

    Permalink
  30. trait LiftedClient[C <: Protocol, M[_]] extends Sender[C, M]

    Permalink
  31. class LoadBalancingClient[P <: Protocol] extends WorkerItem with Sender[P, Callback]

    Permalink

    The LoadBalancingClient will evenly distribute requests across a set of clients.

    The LoadBalancingClient will evenly distribute requests across a set of clients. If one client begins failing, the balancer will retry up to numRetries times across the other clients (with each failover hitting different clients to avoid a cascading pileup

    Note that the balancer will never try the same client twice for a request, so setting maxTries to a very large number will mean that every client will be tried once

    TODO: does this need to actually be a WorkerItem anymore?

  32. class LoadBalancingClientException extends Exception

    Permalink
  33. case class MappedCallback[I, O](trigger: ((Try[I]) ⇒ Unit) ⇒ Unit, handler: (Try[I]) ⇒ Try[O]) extends Callback[O] with Product with Serializable

    Permalink

    A Callback that has been mapped on.

    A Callback that has been mapped on. See the docs for Callback for more information

  34. trait MessageDecoder[T] extends AnyRef

    Permalink
  35. trait MessageEncoder[T] extends AnyRef

    Permalink
  36. class NotConnectedException extends ServiceClientException

    Permalink

    Throw when a request is attempted while not connected

  37. class PermutationGenerator[T] extends Iterator[List[T]]

    Permalink

    The PermutationGenerator creates permutations such that consecutive calls are guaranteed to cycle though all items as the first element.

    The PermutationGenerator creates permutations such that consecutive calls are guaranteed to cycle though all items as the first element.

    This currently doesn't iterate through every possible permutation, but it does evenly distribute 1st and 2nd tries...needs some more work

  38. sealed trait ProcessingFailure[C] extends AnyRef

    Permalink
  39. class PromiseException extends Exception

    Permalink
  40. trait Protocol extends AnyRef

    Permalink
  41. class ProxyWatchdog extends Actor

    Permalink
  42. class ReceiveException extends Exception

    Permalink
  43. case class RecoverableError[C](request: C, reason: Throwable) extends ProcessingFailure[C] with Product with Serializable

    Permalink
  44. class RequestBufferFullException extends ServiceServerException

    Permalink
  45. trait RequestFormatter[I] extends AnyRef

    Permalink
  46. class RequestTimeoutException extends ServiceClientException

    Permalink

    Returned when a request has been pending for too long

  47. class SendFailedException extends Exception

    Permalink
  48. trait Sender[C <: Protocol, M[_]] extends AnyRef

    Permalink

    A Sender is anything that is able to asynchronously send a request and receive a corresponding response

  49. abstract class Service[C <: Protocol] extends ServiceServer[service.Service.C.Input, service.Service.C.Output]

    Permalink
  50. class ServiceClient[P <: Protocol] extends Controller[service.ServiceClient.P.Output, service.ServiceClient.P.Input] with ClientConnectionHandler with Sender[P, Callback] with ManualUnbindHandler

    Permalink

    A ServiceClient is a non-blocking, synchronous interface that handles sending atomic commands on a connection and parsing their replies

    A ServiceClient is a non-blocking, synchronous interface that handles sending atomic commands on a connection and parsing their replies

    Notice - The client will not begin to connect until it is bound to a worker, so when using the default constructor a service client will not connect on it's own. You must either call bind on the client or use the constructor that accepts a worker

    TODO: make underlying output controller data size configurable

  51. class ServiceClientException extends Exception

    Permalink
  52. class ServiceClientPool[T <: Sender[_, Callback]] extends AnyRef

    Permalink

    A ClientPool is a simple container of open connections.

    A ClientPool is a simple container of open connections. It can receive updates and will open/close connections accordingly.

    note that config will be copied for each client, replacing only the address

  53. trait ServiceCodecProvider[C <: Protocol] extends CodecProvider[C]

    Permalink
  54. case class ServiceConfig(requestTimeout: Duration, requestBufferSize: Int, logErrors: Boolean, requestMetrics: Boolean, maxRequestSize: DataSize) extends Product with Serializable

    Permalink

    Configuration class for a Service Server Connection Handler

    Configuration class for a Service Server Connection Handler

    requestTimeout

    how long to wait until we timeout the request

    requestBufferSize

    how many concurrent requests a single connection can be processing

    logErrors

    if true, any uncaught exceptions or service-level errors will be logged

    requestMetrics

    toggle request metrics

    maxRequestSize

    max size allowed for requests TODO: remove name from config, this should be the same as a server's name and pulled from the ServerRef, though this requires giving the ServiceServer access to the ServerRef

  55. class ServiceConfigException extends Exception

    Permalink
  56. abstract class ServiceServer[I, O] extends Controller[I, O] with ServerConnectionHandler

    Permalink

    The ServiceServer provides an interface and basic functionality to create a server that processes requests and returns responses over a codec.

    The ServiceServer provides an interface and basic functionality to create a server that processes requests and returns responses over a codec.

    A Codec is simply the format in which the data is represented. Http, Redis protocol, Memcached protocl are all examples(and natively supported). It is entirely possible to use an additional Codec by creating a Codec to parse the desired protocol.

    Requests can be processed synchronously or asynchronously. The server will ensure that all responses are written back in the order that they are received.

  57. class ServiceServerException extends Exception

    Permalink
  58. class StaleClientException extends Exception

    Permalink

    This is thrown when a Client is manually disconnected, and subsequent attempt is made to reconnect.

    This is thrown when a Client is manually disconnected, and subsequent attempt is made to reconnect. To simplify the internal workings of Clients, instead of trying to reset its internal state, it throws. Create a new Client to reestablish a connection.

  59. trait TagDecorator[I, O] extends AnyRef

    Permalink
  60. class UnhandledRequestException extends Exception

    Permalink
  61. case class UnmappedCallback[I](trigger: ((Try[I]) ⇒ Unit) ⇒ Unit) extends Callback[I] with Product with Serializable

    Permalink

    A Callback that has not been mapped.

    A Callback that has not been mapped. See the docs for Callback for more information

Value Members

  1. object AsyncBuilder

    Permalink
  2. object Callback

    Permalink
  3. object CallbackAsync extends Async[Callback]

    Permalink
  4. object CallbackExecutor extends Serializable

    Permalink
  5. object ClientConfig extends Serializable

    Permalink
  6. object ClientFactory

    Permalink
  7. object ClientState

    Permalink
  8. object Codec

    Permalink
  9. object DecodedResult

    Permalink
  10. object FutureClient extends FutureClientOps

    Permalink
  11. object Protocol

    Permalink
  12. object Service

    Permalink
  13. object ServiceClient

    Permalink
  14. object ServiceConfig extends Serializable

    Permalink
  15. object ServiceServer

    Permalink
  16. object TagDecorator

    Permalink

Deprecated Value Members

  1. object AsyncServiceClient extends FutureClientOps

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 0.8.1) Use FutureClient Instead

Ungrouped