Aggie Student Toolkit — Load Balancer CSCE 412 Project 4
Arnav Fotedar · Fall 2026 · C++ load balancer simulation
Loading...
Searching...
No Matches
WebServer.h
Go to the documentation of this file.
1
6
7#ifndef WEBSERVER_H
8#define WEBSERVER_H
9
10#include <optional>
11
12#include "Request.h"
13
26class WebServer {
27public:
33 explicit WebServer(unsigned int id, unsigned long createdCycle = 0);
34
36 unsigned int id() const;
37
39 bool isIdle() const;
40
42 bool isRetiring() const;
43
48 void setRetiring(bool retiring);
49
60 void assign(const Request& request, unsigned long cycle);
61
66 bool tick();
67
69 const std::optional<Request>& current() const;
70
72 const Request& lastCompleted() const;
73
75 unsigned int remainingCycles() const;
76
78 unsigned long completedCount() const;
79
81 unsigned long busyCycles() const;
82
84 unsigned long createdCycle() const;
85
86private:
87 unsigned int id_;
88 unsigned long createdCycle_;
89 std::optional<Request> current_;
90 Request lastCompleted_;
91 unsigned int remainingCycles_ = 0;
92 unsigned long completedCount_ = 0;
93 unsigned long busyCycles_ = 0;
94 bool retiring_ = false;
95};
96
97#endif
Defines the Request structure and its JobType that flow through the load balancer.
void assign(const Request &request, unsigned long cycle)
Starts processing a request.
Definition WebServer.cpp:30
unsigned int remainingCycles() const
Definition WebServer.cpp:67
bool isIdle() const
Definition WebServer.cpp:18
WebServer(unsigned int id, unsigned long createdCycle=0)
Creates an idle server.
Definition WebServer.cpp:11
unsigned long busyCycles() const
Definition WebServer.cpp:75
const Request & lastCompleted() const
Definition WebServer.cpp:63
void setRetiring(bool retiring)
Marks or unmarks the server for retirement.
Definition WebServer.cpp:26
bool isRetiring() const
Definition WebServer.cpp:22
const std::optional< Request > & current() const
Definition WebServer.cpp:59
unsigned long completedCount() const
Definition WebServer.cpp:71
unsigned long createdCycle() const
Definition WebServer.cpp:79
bool tick()
Advances the server by one clock cycle.
Definition WebServer.cpp:44
unsigned int id() const
Definition WebServer.cpp:14
A single web request waiting for, or receiving, service.
Definition Request.h:41