colossus.service

Service

object Service

The Service object is an entry point into the the Service DSL which provide some convenience functions for quickly creating a Server serving responses to requests utilizing a Codec(ie: memcached, http, redis, etc).

One thing to always keep in mind is that code inside the Service.serve is placed inside a Delegator and ConnectionHandler, which means that it directly runs inside of a Worker and its SelectLoop. Be VERY mindful of the code that you place in here, as if there is any blocking code it will block the Worker. Not good.

An example with full typing in place to illustrate :

import colossus.protocols.http._  //imports an implicit codec

implicit val ioSystem : IOSystem = myBootStrappingFunction()

Service.serve[Http]("my-app", 9090) { context : ServiceContext[Http] =>

  //everything in this block happens on delegator initialization, which is on application startup.  One time only.

  context.handle { connection : ConnectionContext[Http] => {
      //This block is for connectionHandler initialization. Happens in the event loop.  Don't block.
      //Note, that a connection can handle multiple requests.
      connection.become {
        //this partial function is what "handles" a request.  Again.. don't block.
        case req @ Get on Text("test") => future(req.ok(someService.getDataFromStore()))
        case req @ Get on Text("path") => req.ok("path")
      }
    }
  }
}
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Service
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def become[T <: CodecDSL](name: String, port: Int, requestTimeout: Duration = 100.milliseconds)(handler: PartialHandler[T])(implicit system: IOSystem, provider: CodecProvider[T]): ServerRef

    Start a simple, stateless service

    Start a simple, stateless service

    Unlike Service.serve, there is no room for per-worker or per-connection initialization. Useful when starting simple services or testing

    T

    the type of codec this service uses

    name

    Name of this Service

    port

    Port on which this Server will accept connections

    handler
    system

    The IOSystem to which this Server will belong

    provider

    CodecProvider

    returns

  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  13. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  14. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  18. def serve[T <: CodecDSL](name: String, port: Int, requestTimeout: Duration = 100.milliseconds)(handler: (ServiceContext[T]) ⇒ (ConnectionContext[T]) ⇒ Unit)(implicit system: IOSystem, provider: CodecProvider[T]): ServerRef

    Quick-start a service, using default settings

    Quick-start a service, using default settings

    name

    The name of the service

    port

    The port to bind the server to

  19. def serve[T <: CodecDSL](serverSettings: ServerSettings, serviceConfig: ServiceConfig)(handler: (ServiceContext[T]) ⇒ (ConnectionContext[T]) ⇒ Unit)(implicit system: IOSystem, provider: CodecProvider[T]): ServerRef

    Start a service with worker and connection initialization

    Start a service with worker and connection initialization

    The basic structure of a service using this method is:

    Service.serve[Http]{ workerContext =>
    //worker initialization
    workerContext.handle { connectionContext =>
      //connection initialization
      connection.become {
        case ...
      }
    }
    }
    T

    The codec to use, eg Http, Redis

    serverSettings

    Settings to provide the underlying server

    serviceConfig

    Config for the service

    handler

    The worker initializer to use for the service

    returns

    A ServerRef for the server.

  20. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  21. def toString(): String

    Definition Classes
    AnyRef → Any
  22. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped