-
Notifications
You must be signed in to change notification settings - Fork 0
Design Decisions
Ian Carroll edited this page Oct 30, 2017
·
1 revision
Basics:
- Clean Code and SOLID principles
- Imperative Shell / Functional Core Pattern
- Employing an Observer Pattern using Reactive Programming via JavaRX to handle concurrent requests
- Using dependency injection to construct the server at start-up via a Factory
- Using a config file to handle routing
High-level Flow:
- The Server Starts.
- The Client sends a byte[] request to the Server.
- The Server sends an appropriate byte[] response back to the Client.
More specific Flow:
- Main Function Calls a Factory to construct the server, then calls Server.start
- Factory takes in any command-line args and constructs the server accordingly
- The Config file with routing info is injected at this stage.
- The Server Socket Class spins up with a Client Socket dependency injected.
- The Server socket employs reactive programming to never develop a stack of waiting requests. Concurrency is implemented at this stage.
- When A request event is triggered, the server socket copies a new stream to handle spinning up a client socket to accept the request. This moves the bottleneck from the moment of client socket instantiation to the hardware running the server.
- The request is converted from a byte[] to a String
- The String is parsed and the parts are instantiated as a Request Object.
- The Request Object is sent to the Controller, which uses the Routes config to match the request with an appropriate Response Generator.
- The Response Generator returns a response object to the Controller.
- The Controller sends the response object to be de-parsed back into a string.
- The string is converted into a byte array
- The Client Socket class sends that byte array as a response to the client's request.