org.mashupbots.socko

webserver

package webserver

Socko web server built on top of Netty networking and Akka processing.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. webserver
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. case class HttpConfig(maxLengthInMB: Int = 4, maxInitialLineLength: Int = 4096, maxHeaderSizeInBytes: Int = 8192, maxChunkSizeInBytes: Int = 8192, aggreateChunks: Boolean = true, minCompressibleContentSizeInBytes: Int = 1024, maxCompressibleContentSizeInBytes: Int = 1 * 1024 * 1024, compressibleContentTypes: List[String] = ..., spdyEnabled: Boolean = false) extends Product with Serializable

    HTTP protocol handling configuration

    HTTP protocol handling configuration

    HTTP compression parameters only applies to HTTP request and responses and not web sockets.

    maxLengthInMB

    Maximum size of HTTP request in megabytes. Defaults to 4MB.

    maxInitialLineLength

    Maximum size the initial line. Defaults to 4096 characters.

    maxHeaderSizeInBytes

    Maximum size of HTTP headers. Defaults to 8192 bytes.

    maxChunkSizeInBytes

    Maximum size of HTTP chunks. Defaults to 8192 bytes.

    aggreateChunks

    Flag to indicate if we want to aggregate chunks. If false, your processor actors must be able to handle HttpChunkProcessingContext

    minCompressibleContentSizeInBytes

    Minimum number of bytes before HTTP content will be compressed if requested by the client. Set to -1 to turn off compression for all files; 0 to make all content compressible.

    maxCompressibleContentSizeInBytes

    Maximum number of bytes before HTTP content will be not be compressed if requested by the client. Defaults to 1MB otherwise too much CPU maybe taken up for compression.

    compressibleContentTypes

    List of MIME types of that can be compressed. If not supplied, defaults to HTML, CSS, JSON, XML and Javascript files.

    spdyEnabled

    Support SPDY protocol or not. Defaults to false.

  2. class PipelineFactory extends ChannelInitializer[SocketChannel] with Logger

    Creates a new channel pipeline for each Netty channel (network connection)

  3. class ProtocolNegoitationHandler extends ByteToMessageDecoder with Logger

    Handler used with SPDY that performs protocol negotiation.

    Handler used with SPDY that performs protocol negotiation.

    Once Jetty's NextProtoNego returns the selected protocol, we setup the pipeline accordingly.

    Code ported from post form Jos Dirksen and Netty SpdyOrHttpChooser class

  4. class RequestHandler extends ChannelInboundHandlerAdapter with Logger

    Handles incoming HTTP messages from Netty

  5. case class SslConfig(keyStoreFile: File, keyStorePassword: String, trustStoreFile: Option[File], trustStorePassword: Option[String]) extends Product with Serializable

    SSL Configuration

    SSL Configuration

    keyStoreFile

    Path to server private key store file (server certificates)

    keyStorePassword

    Password to access server private key store file.

    trustStoreFile

    Path to key store file for trusted remote public keys (client certificates). This is optional.

    trustStorePassword

    Password to access the key store for trusted remote public keys (client certificates). This is optional.

  6. class SslManager extends AnyRef

    Manages reading key stores and trust stores for TLS/SSL connections

  7. case class TcpConfig(noDelay: Option[Boolean] = None, sendBufferSize: Option[Int] = None, receiveBufferSize: Option[Int] = None, keepAlive: Option[Boolean] = None, reuseAddress: Option[Boolean] = None, soLinger: Option[Int] = None, trafficClass: Option[Int] = None, acceptBackLog: Option[Int] = None) extends Product with Serializable

    TCP IP configuration as per Netty.

    TCP IP configuration as per Netty.

    See javadoc and netty doc for more information.

    Netty and JVM defaults are used until overriden here.

    noDelay

    Disable Nagle's algorithm. Defaults to true if not supplied.

    sendBufferSize

    Set a hint the size of the underlying buffers for outgoing network I/O.

    receiveBufferSize

    Get the size of the buffer actually used by the platform when receiving in data on this socket.

    keepAlive

    Turn on socket keep-alive. Defaults to false if not supplied.

    reuseAddress

    Enable reuse address for a socket and not throw an "already bind exception" The default value is JVM specific.

    soLinger

    Specify a linger-on-close timeout.

    trafficClass

    Sets the type-of-service or traffic class field in the IP header for a TCP or UDP socket. \ The default value is JVM specific.

    acceptBackLog

    The number of requests that can be queued. Useful in managing sudden bursts in requests. If take an example with a socket server invoker that has max pool set to 300, accept threads is 2, and backlog is 200, will be able to make 502 concurrent client calls. The 503rd client request will get an exception immediately. However, this does not mean all 502 requests will be guaranteed to be processed, only the first 300 (as they have server threads available to do the processing). If 202 of the server threads finish processing their requests from their initial client connections and the connection is released before the timeout for the other 202 that are waiting (200 for backlog and 2 for accept thread), then they will be processed (of course this is a request by request determination).

  8. case class WebLogConfig(customActorPath: Option[String] = None, format: infrastructure.WebLogFormat.Value = WebLogFormat.Common) extends Product with Serializable

    Configuration for web server activity logs.

    Configuration for web server activity logs.

    customActorPath

    Optional path of actor to which org.mashupbots.socko.infrastructure.WebLogEvent will be sent for writing. If this path is not present, org.mashupbots.socko.infrastructure.WebLogWriter will be used.

    format

    Format of the web log. Defaults to Common.

  9. class WebServer extends Logger

    Socko Web Server

    Socko Web Server

    val webServer = new WebServer(myWebServerConfig, actorSystem, { server => new RequestHandler(server, routes) })
    webServer.start()
    ...
    
    webServer.stop()
  10. case class WebServerConfig(serverName: String = "WebServer", hostname: String = "localhost", port: Int = 8888, idleConnectionTimeout: Duration = 0 seconds, logNetworkActivity: Boolean = false, webLog: Option[WebLogConfig] = None, ssl: Option[SslConfig] = None, http: HttpConfig = HttpConfig(), tcp: TcpConfig = TcpConfig()) extends Extension with Product with Serializable

    Web server configuration

    Web server configuration

    The configuration can be optionally loaded from Akka's application.conf file.

    The following example configuration file:

    akka-config-example {
    server-name=AkkaConfigExample
    hostname=localhost
    port=9000
    idle-connection-timeout=0
    log-network-activity=false
    
    # Optional web log. If not supplied, web server activity logging is turned off.
    web-log {
    
      # Optional path of actor to which web log events will be sent for writing. If not specified, the default
      # web log writer will be created
      custom-actor-path = "akka://my-system/user/web-log-writer"
    
      # Optional web log format for the default web log writer: Common, Combined or Extended.
      # If no specified, Common is the default.
      format = Common
    }
    
    # Optional SSL. If not supplied, ssl is turned off.
    ssl {
    
      # Path to key store (server cert.)
      key-store-file=/tmp/ks.dat
    
      # Password to key store
      key-store-password=kspwd
    
      # Optional path to trust store (client cert.)
      trust-store-file=/tmp/ts.dat
    
      # Optional password to trust store
      trust-store-password=tspwd
    }
    
    # Optional HTTP protocol configuration. If not supplied, defaults are used.
    http {
    
      # Maximum size of HTTP request. Defaults to 4MB.
      max-length-in-mb=4
    
      # Maximum length of the HTTP initial line. Defaults to 4096 bytes (4K).
      max-initial-line-length=4096
    
      # Maximum size of HTTP headers. Defaults to 8192 bytes (8K).
      max-header-size-in-bytes=8192
    
      # Maximum size of HTTP chunks. Defaults to 8192 bytes (8K).
      max-chunk-size-in-bytes=8192
    
      # Flag to indicate if HTTP chunk requests should be aggregated and presented
      # as a single HTTP request. Defaults to true.
      aggregate-chunks=true
    
      # Content under this size is not compressed. Defaults to 1024 bytes (1K).
      # Set to -1 to turn off compression; or 0 to compress all content.
      min-compressible-content-size-in-bytes=1024
    
      # Content over this size is not compressed. Defaults to 1MB
      max-compressible-content-size-in-bytes=60
    
      # Only content with the specified MIME type will be compressed
      compressible-content-types=[
        "text/plain", "text/html", "text/xml", "text/css",
        "application/xml", "application/xhtml+xml", "application/rss+xml",
        "application/json", "application/jsonml+json",
        "application/javascript", "application/x-javascript"]
    
      # Enable SPDY protocol or not. Defaults to `false`. If `true`, you must also enable SSL.
      spdy=false
    }
    
    # Optional TCP protocol configuration. If not supplied, defaults are used.
    tcp {
    
      # Disable Nagle's algorithm. Defaults to `true` if not supplied.
      no-delay=
    
      # Set a hint the size of the underlying buffers for outgoing network I/O.
      send-buffer-size=
    
      # Get the size of the buffer actually used by the platform when receiving in data on this socket
      receive-buffer-size=
    
      # Turn on socket keep-alive. `true` or `false`.
      keep-alive=
    
      # Enable reuse address for a socket and not throw an "already bind exception". `true` or `false`.
      reuse-address=
    
      # Specify a linger-on-close timeout.
      so-linger=
    
      # Sets the type-of-service or traffic class field in the IP header for a TCP or UDP socket.
      traffic-class=
    
      # The number of requests that can be queued.
      accept-backlog=
    }
    }

    can be loaded as follows:

    object MyWebServerConfig extends ExtensionId[WebServerConfig] with ExtensionIdProvider {
      override def lookup = MyWebServerConfig
      override def createExtension(system: ExtendedActorSystem) =
        new WebServerConfig(system.settings.config, "akka-config-example")
    }
    
    val myWebServerConfig = MyWebServerConfig(actorSystem)
    val webServer = new WebServer(myWebServerConfig, routes)
    webServer.start()
    serverName

    Human friendly name of this server. Defaults to WebServer.

    hostname

    Hostname or IP address to bind. 0.0.0.0 will bind to all addresses. You can also specify comma separated hostnames/ip address like localhost,192.168.1.1. Defaults to localhost.

    port

    IP port number to bind to. Defaults to 8888.

    idleConnectionTimeout

    If a connection is idle for this duration, it will be closed. The default is 0, which indicates NO timeout and idle connections will NOT be closed.

    logNetworkActivity

    Dumps request and response data to the debug logger. To see the output, you need to set the logging level for io.netty.handler.logging.LoggingHandler to debug. The default is false.

    webLog

    Optional web log configuration. If None, web log events will NOT be generated.

    ssl

    SSL protocol configuration. If None, then SSL will not be turned on. Defaults to None.

    http

    HTTP protocol configuration. Defaults to an instance of org.mashupbots.socko.webserver.HttpConfig with default settings.

    tcp

    TCP IP protocol configuration. Defaults to an instance of org.mashupbots.socko.webserver.TcpConfig with default settings.

  11. class WebSocketConnections extends AnyRef

    Manages all web socket connections

    Manages all web socket connections

    Acts as a wrapper for Netty's channel group. A TODO is to optimize performance by using a hash lookup.

Value Members

  1. object WebServerConfig extends Logger with Serializable

    Methods for reading configuration from Akka.

Inherited from AnyRef

Inherited from Any

Ungrouped