Object

colossus.service

Service

Related Doc: package service

Permalink

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
Visibility
  1. Public
  2. All

Value Members

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

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

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

    Permalink

    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

    system

    The IOSystem to which this Server will belong

    provider

    CodecProvider

  6. def clone(): AnyRef

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

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

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

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
  14. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. def serve[T <: CodecDSL](name: String, port: Int, requestTimeout: Duration = 100.milliseconds)(handler: Initializer[T])(implicit system: IOSystem, provider: CodecProvider[T]): ServerRef

    Permalink

    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

  17. def serve[T <: CodecDSL](serverSettings: ServerSettings, serviceConfig: ServiceConfig[Service.serve.T.Input, Service.serve.T.Output])(handler: Initializer[T])(implicit system: IOSystem, provider: CodecProvider[T]): ServerRef

    Permalink

    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.

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

    Permalink
    Definition Classes
    AnyRef
  19. def toString(): String

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

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped