In this tutorial I will be creating a very basic HTTP Server in Scala. In place of the Threads and ExecutorService I would probably use with core Java I will use the Actor pattern:
A main actor will be responsible for starting the listening server and creating child actors to respond to incoming requests.
The actors communicate by the sending of messages, to start the service I will use a StartListening message. I will implement this in scala as a ‘case class’ which will be an immutable value object to hold the port (to listen on) and the number of child threads to handle incoming clients.
Step 1. A Case class for startup options.
We will use the Actor pattern to create our simple HTTP Server
case class StartListening(port: Int = 8080, numberOfThreads: Int = 1)
The StartListening class demonstrates default parameters with default values – a default port of 8080 and default number of threads of 1.