The design of this app was broken into four main pieces, as indicated by the package names in the source repo.
The three classes Main, PackageServer and ConnectionHandler are responsible for the bare bones of the multi-threaded server code, and don't implement any application-specific logic.
This class manages the state of the application, i.e. it stores all package information and contains a thread-safe API for querying the repository. The Repository class synchronizes all access to the repository HashMap data store to ensure consistency in reads/writes to the data store. It is possible to reduce lock contention and increase throughput if required, depending on the performance requirements of the repository server. For now I have implemented it in a simple way.
The classes in this package are responsible for parsing and validating all messages received by the server. The main handler is the MessageParser class.
The MessageHandler class is responsible for liasing between the MessageParser and Repository, it takes the result of MessageParser and either invokes the corect Repository method and returns OK/FAIL or returns ERROR to the server thread which then outputs the result to the client.
Java JDK Version 8 download here
To run the server:
- Execute
java -jar bin/package-server-jar.jar
- this will start the server on port 8080, which you can then make requests to.
Run this command from the directory containing the Dockerfile file:
docker build -t package-server .
Execute this:
docker run -d -p 8080:8080 package-server
This depends on where you're running the image. If you're running it on OSX, you'll need to find the IP of docker-machine using:
docker-machine ls
, then connect to the server running in the container using that ip and port 8080.
Java JDK Version 8 download here Apache Maven Version 3+ [download here] (https://maven.apache.org/download.cgi)
To build the executable jar:
- Change to the top level directory
- Run
mvn package
- this will run all the tests and produce an executable jar in the./target/
directory. - Now to start the server, run
java -jar target/package-server-1.0-SNAPSHOT-jar.jar