|
Load Balancer Simulation
A simulation of a load balancer with dynamic server scaling in C++
|
Simulates a single web server that processes one request at a time. More...
#include <WebServer.h>
Public Member Functions | |
| WebServer (int id) | |
| Construct a web server with the given ID. | |
| void | assignRequest (const Request &req) |
| Assign a request to this server for processing. | |
| void | process () |
| Advance processing by one clock cycle (decrements remaining time). | |
| void | clear () |
| Clear the current request and mark server as idle. | |
| bool | isBusy () const |
| Check if the server is currently processing a request. | |
| bool | isFinished () const |
| Check if the current request has finished processing. | |
| int | getId () const |
| Get the server's unique ID. | |
Private Attributes | |
| int | id_ |
| bool | busy_ |
| int | remainingTime_ |
| Request | currentRequest_ |
Simulates a single web server that processes one request at a time.
Definition at line 15 of file WebServer.h.
|
explicit |
Construct a web server with the given ID.
Construct web server with given ID.
| id | Unique identifier for this server |
Definition at line 9 of file WebServer.cpp.
| void WebServer::assignRequest | ( | const Request & | req | ) |
Assign a request to this server for processing.
Assign a request to this server.
| req | The request to process |
Definition at line 12 of file WebServer.cpp.
| void WebServer::clear | ( | ) |
Clear the current request and mark server as idle.
Clear current request and mark idle.
Definition at line 31 of file WebServer.cpp.
|
inline |
| bool WebServer::isBusy | ( | ) | const |
Check if the server is currently processing a request.
Check if server is currently processing.
Definition at line 26 of file WebServer.cpp.
| bool WebServer::isFinished | ( | ) | const |
Check if the current request has finished processing.
Check if current request has finished.
Definition at line 37 of file WebServer.cpp.
| void WebServer::process | ( | ) |
Advance processing by one clock cycle (decrements remaining time).
Advance processing by one clock cycle.
Definition at line 19 of file WebServer.cpp.
|
private |
Whether the server is currently processing
Definition at line 59 of file WebServer.h.
Referenced by assignRequest(), clear(), isBusy(), isFinished(), process(), and WebServer().
|
private |
The request currently being processed
Definition at line 61 of file WebServer.h.
Referenced by assignRequest().
|
private |
Unique server identifier
Definition at line 58 of file WebServer.h.
Referenced by getId(), and WebServer().
|
private |
Clock cycles remaining for current request
Definition at line 60 of file WebServer.h.
Referenced by assignRequest(), clear(), isFinished(), process(), and WebServer().