Load Balancer Simulation
A simulation of a load balancer with dynamic server scaling in C++
Loading...
Searching...
No Matches
WebServer.cpp
Go to the documentation of this file.
1
5
6#include "WebServer.h"
7
9WebServer::WebServer(int id) : id_(id), busy_(false), remainingTime_(0) {}
10
13 currentRequest_ = req;
15 busy_ = true;
16}
17
20 if (busy_ && remainingTime_ > 0) {
22 }
23}
24
26bool WebServer::isBusy() const {
27 return busy_;
28}
29
32 busy_ = false;
34}
35
38 return busy_ && remainingTime_ <= 0;
39}
Defines the WebServer class for processing requests.
int remainingTime_
Definition WebServer.h:60
void clear()
Clear the current request and mark server as idle.
Definition WebServer.cpp:31
Request currentRequest_
Definition WebServer.h:61
bool isFinished() const
Check if the current request has finished processing.
Definition WebServer.cpp:37
void assignRequest(const Request &req)
Assign a request to this server for processing.
Definition WebServer.cpp:12
WebServer(int id)
Construct a web server with the given ID.
Definition WebServer.cpp:9
void process()
Advance processing by one clock cycle (decrements remaining time).
Definition WebServer.cpp:19
bool isBusy() const
Check if the server is currently processing a request.
Definition WebServer.cpp:26
bool busy_
Definition WebServer.h:59
Represents a single request/job in the load balancer simulation.
Definition Request.h:15
int timeRequired
Definition Request.h:18