CSCE 412 - Project 3 Load Balancer
Loading...
Searching...
No Matches
loadbalancer.h
Go to the documentation of this file.
1#ifndef LOADBALANCER_H
2#define LOADBALANCER_H
3
4#include "request.h"
5#include "requestqueue.h"
6#include "webserver.h"
7#include "logmanager.h"
8#include <vector>
9#include <string>
10
11 //all doxygen comments are generated with AI assistance
20public:
26 LoadBalancer(LogManager& logger);
27
33 int getTime() const;
34
38 void incTime();
39
40
46 void addRequest(const Request& r);
47
54
60 bool isRequestQueueEmpty() const;
61
67 size_t getRequestQueueSize() const;
68
74 int getProcessedRequests() const;
75
76
81
82
89
93 void allocateServer();
94
98 void deallocateServer();
99
100 // IP blocking
101
108 bool isIpBlocked(const std::string& ip) const; //implemented with the assistance of AI
109
110
116 int getRejectedRequests() const;
117
123 int getActiveServers() const;
124
130 int getInactiveServers() const;
131
137 void setTotalServers(int total);
138
139private:
140 LogManager& logger;
141 int currentTime = 0;
142 RequestQueue requestQueue;
143 int currentServerIndex = 0;
144 int processedRequests = 0;
145 int rejectedRequests = 0;
146 int activeServers = 0;
147 int totalServers = 0;
149 const int maxServers = 50;
150 const int minServers = 1;
151 std::vector<std::string> blockedIpRanges;
152 std::vector<WebServer> servers;
157 void initializeBlockedIpRanges(); //implemented with the assistance of AI
158
164 void logRejectedRequest(const Request& r); //implemented with the assistance of AI
165};
166
167#endif // LOADBALANCER_H
Manages incoming requests and distributes them among a set of web servers.
Definition loadbalancer.h:19
int getInactiveServers() const
Gets the total number of inactive servers.
Definition loadbalancer.cpp:122
int getTime() const
Gets the current simulation time.
Definition loadbalancer.cpp:19
void addRequest(const Request &r)
Adds a request to the request queue.
Definition loadbalancer.cpp:160
int getActiveServers() const
Gets the total number of active servers.
Definition loadbalancer.cpp:113
Request getRequest()
Retrieves and removes the next request from the request queue.
Definition loadbalancer.cpp:35
bool isRequestQueueEmpty() const
Checks if the request queue is empty.
Definition loadbalancer.cpp:44
bool isIpBlocked(const std::string &ip) const
Checks if a given IP address is blocked.
Definition loadbalancer.cpp:90
void allocateServer()
Allocates additional servers if needed.
Definition loadbalancer.cpp:176
void deallocateServer()
Deallocates servers that are no longer active.
Definition loadbalancer.cpp:194
WebServer & getNextServer()
Retrieves the next available server for processing requests.
Definition loadbalancer.cpp:78
LoadBalancer(LogManager &logger)
Constructs a LoadBalancer with a specified LogManager for logging.
Definition loadbalancer.cpp:9
void incrementProcessedRequests()
Increments the count of processed requests by one.
Definition loadbalancer.cpp:69
int getProcessedRequests() const
Gets the total number of processed requests.
Definition loadbalancer.cpp:62
size_t getRequestQueueSize() const
Gets the size of the request queue.
Definition loadbalancer.cpp:53
int getRejectedRequests() const
Gets the total number of rejected requests.
Definition loadbalancer.cpp:104
void setTotalServers(int total)
Sets the total number of servers managed by the LoadBalancer.
Definition loadbalancer.cpp:131
void incTime()
Increments the current simulation time by one unit.
Definition loadbalancer.cpp:26
A class to represent a network request.
Definition request.h:15
A class to represent a queue of requests.
Definition requestqueue.h:16
A class to represent a server that processes a request.
Definition webserver.h:23