|
CSCE 412 - Project 3 Load Balancer
|
Manages incoming requests and distributes them among a set of web servers. More...
#include <loadbalancer.h>
Public Member Functions | |
| LoadBalancer (LogManager &logger) | |
| Constructs a LoadBalancer with a specified LogManager for logging. | |
| int | getTime () const |
| Gets the current simulation time. | |
| void | incTime () |
| Increments the current simulation time by one unit. | |
| void | addRequest (const Request &r) |
| Adds a request to the request queue. | |
| Request | getRequest () |
| Retrieves and removes the next request from the request queue. | |
| bool | isRequestQueueEmpty () const |
| Checks if the request queue is empty. | |
| size_t | getRequestQueueSize () const |
| Gets the size of the request queue. | |
| int | getProcessedRequests () const |
| Gets the total number of processed requests. | |
| void | incrementProcessedRequests () |
| Increments the count of processed requests by one. | |
| WebServer & | getNextServer () |
| Retrieves the next available server for processing requests. | |
| void | allocateServer () |
| Allocates additional servers if needed. | |
| void | deallocateServer () |
| Deallocates servers that are no longer active. | |
| bool | isIpBlocked (const std::string &ip) const |
| Checks if a given IP address is blocked. | |
| int | getRejectedRequests () const |
| Gets the total number of rejected requests. | |
| int | getActiveServers () const |
| Gets the total number of active servers. | |
| int | getInactiveServers () const |
| Gets the total number of inactive servers. | |
| void | setTotalServers (int total) |
| Sets the total number of servers managed by the LoadBalancer. | |
Manages incoming requests and distributes them among a set of web servers.
The LoadBalancer is responsible for queuing incoming requests, managing server allocation, monitoring server statuses, and logging information about processed and rejected requests.
| LoadBalancer::LoadBalancer | ( | LogManager & | logger | ) |
Constructs a LoadBalancer with a specified LogManager for logging.
| logger | Reference to a LogManager object used for logging activities. |
| void LoadBalancer::addRequest | ( | const Request & | r | ) |
Adds a request to the request queue.
| r | The Request object to be added to the queue. |
This function checks if the IP of the request is blocked. If it is not blocked, the request is added to the queue, and the processed request count is updated. If the IP is blocked, the request is rejected, and the rejection is logged.
| r | The Request object to be added to the queue. |
| void LoadBalancer::allocateServer | ( | ) |
Allocates additional servers if needed.
Allocates additional servers if needed based on the current request queue size.
A new server is allocated if the queue size exceeds five times the number of servers and the total number of servers is below the maximum allowed.
| void LoadBalancer::deallocateServer | ( | ) |
Deallocates servers that are no longer active.
Deallocates servers that are no longer active based on the current request queue size.
A server is deallocated if the queue size is less than two times the number of servers and the total number of servers is above the minimum required.
| int LoadBalancer::getActiveServers | ( | ) | const |
Gets the total number of active servers.
| int LoadBalancer::getInactiveServers | ( | ) | const |
Gets the total number of inactive servers.
| WebServer & LoadBalancer::getNextServer | ( | ) |
Retrieves the next available server for processing requests.
| int LoadBalancer::getProcessedRequests | ( | ) | const |
Gets the total number of processed requests.
| int LoadBalancer::getRejectedRequests | ( | ) | const |
Gets the total number of rejected requests.
| Request LoadBalancer::getRequest | ( | ) |
Retrieves and removes the next request from the request queue.
| size_t LoadBalancer::getRequestQueueSize | ( | ) | const |
Gets the size of the request queue.
| int LoadBalancer::getTime | ( | ) | const |
Gets the current simulation time.
| void LoadBalancer::incrementProcessedRequests | ( | ) |
Increments the count of processed requests by one.
| void LoadBalancer::incTime | ( | ) |
Increments the current simulation time by one unit.
| bool LoadBalancer::isIpBlocked | ( | const std::string & | ip | ) | const |
Checks if a given IP address is blocked.
| ip | The IP address to check. |
| bool LoadBalancer::isRequestQueueEmpty | ( | ) | const |
Checks if the request queue is empty.
| void LoadBalancer::setTotalServers | ( | int | total | ) |
Sets the total number of servers managed by the LoadBalancer.
| total | The total number of servers to set. |