CSCE 412 - Project 3 Load Balancer
Loading...
Searching...
No Matches
LoadBalancer Class Reference

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.
 
WebServergetNextServer ()
 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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ LoadBalancer()

LoadBalancer::LoadBalancer ( LogManager & logger)

Constructs a LoadBalancer with a specified LogManager for logging.

Parameters
loggerReference to a LogManager object used for logging activities.

Member Function Documentation

◆ addRequest()

void LoadBalancer::addRequest ( const Request & r)

Adds a request to the request queue.

Parameters
rThe 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.

Parameters
rThe Request object to be added to the queue.

◆ allocateServer()

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.

◆ deallocateServer()

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.

◆ getActiveServers()

int LoadBalancer::getActiveServers ( ) const

Gets the total number of active servers.

Returns
The count of active servers as an integer.

◆ getInactiveServers()

int LoadBalancer::getInactiveServers ( ) const

Gets the total number of inactive servers.

Returns
The count of inactive servers as an integer.

◆ getNextServer()

WebServer & LoadBalancer::getNextServer ( )

Retrieves the next available server for processing requests.

Returns
A reference to the next WebServer object.

◆ getProcessedRequests()

int LoadBalancer::getProcessedRequests ( ) const

Gets the total number of processed requests.

Returns
The count of processed requests as an integer.

◆ getRejectedRequests()

int LoadBalancer::getRejectedRequests ( ) const

Gets the total number of rejected requests.

Returns
The count of rejected requests as an integer.

◆ getRequest()

Request LoadBalancer::getRequest ( )

Retrieves and removes the next request from the request queue.

Returns
The next Request object in the queue.

◆ getRequestQueueSize()

size_t LoadBalancer::getRequestQueueSize ( ) const

Gets the size of the request queue.

Returns
The number of requests in the queue.

◆ getTime()

int LoadBalancer::getTime ( ) const

Gets the current simulation time.

Returns
The current time as an integer.

◆ incrementProcessedRequests()

void LoadBalancer::incrementProcessedRequests ( )

Increments the count of processed requests by one.

◆ incTime()

void LoadBalancer::incTime ( )

Increments the current simulation time by one unit.

◆ isIpBlocked()

bool LoadBalancer::isIpBlocked ( const std::string & ip) const

Checks if a given IP address is blocked.

Parameters
ipThe IP address to check.
Returns
True if the IP address is blocked, false otherwise.

◆ isRequestQueueEmpty()

bool LoadBalancer::isRequestQueueEmpty ( ) const

Checks if the request queue is empty.

Returns
True if the request queue is empty, false otherwise.

◆ setTotalServers()

void LoadBalancer::setTotalServers ( int total)

Sets the total number of servers managed by the LoadBalancer.

Parameters
totalThe total number of servers to set.

The documentation for this class was generated from the following files: