Load Balancer Simulation
A simulation of a load balancer with dynamic server scaling in C++
Loading...
Searching...
No Matches
WebServer Class Reference

Simulates a single web server that processes one request at a time. More...

#include <WebServer.h>

Public Member Functions

 WebServer (int id)
 Construct a web server with the given ID.
void assignRequest (const Request &req)
 Assign a request to this server for processing.
void process ()
 Advance processing by one clock cycle (decrements remaining time).
void clear ()
 Clear the current request and mark server as idle.
bool isBusy () const
 Check if the server is currently processing a request.
bool isFinished () const
 Check if the current request has finished processing.
int getId () const
 Get the server's unique ID.

Private Attributes

int id_
bool busy_
int remainingTime_
Request currentRequest_

Detailed Description

Simulates a single web server that processes one request at a time.

Definition at line 15 of file WebServer.h.

Constructor & Destructor Documentation

◆ WebServer()

WebServer::WebServer ( int id)
explicit

Construct a web server with the given ID.

Construct web server with given ID.

Parameters
idUnique identifier for this server

Definition at line 9 of file WebServer.cpp.

Member Function Documentation

◆ assignRequest()

void WebServer::assignRequest ( const Request & req)

Assign a request to this server for processing.

Assign a request to this server.

Parameters
reqThe request to process

Definition at line 12 of file WebServer.cpp.

◆ clear()

void WebServer::clear ( )

Clear the current request and mark server as idle.

Clear current request and mark idle.

Definition at line 31 of file WebServer.cpp.

◆ getId()

int WebServer::getId ( ) const
inline

Get the server's unique ID.

Returns
The server identifier

Definition at line 55 of file WebServer.h.

◆ isBusy()

bool WebServer::isBusy ( ) const

Check if the server is currently processing a request.

Check if server is currently processing.

Returns
true if busy, false if idle

Definition at line 26 of file WebServer.cpp.

◆ isFinished()

bool WebServer::isFinished ( ) const

Check if the current request has finished processing.

Check if current request has finished.

Returns
true if request is complete and ready to be cleared

Definition at line 37 of file WebServer.cpp.

◆ process()

void WebServer::process ( )

Advance processing by one clock cycle (decrements remaining time).

Advance processing by one clock cycle.

Definition at line 19 of file WebServer.cpp.

Member Data Documentation

◆ busy_

bool WebServer::busy_
private

Whether the server is currently processing

Definition at line 59 of file WebServer.h.

Referenced by assignRequest(), clear(), isBusy(), isFinished(), process(), and WebServer().

◆ currentRequest_

Request WebServer::currentRequest_
private

The request currently being processed

Definition at line 61 of file WebServer.h.

Referenced by assignRequest().

◆ id_

int WebServer::id_
private

Unique server identifier

Definition at line 58 of file WebServer.h.

Referenced by getId(), and WebServer().

◆ remainingTime_

int WebServer::remainingTime_
private

Clock cycles remaining for current request

Definition at line 60 of file WebServer.h.

Referenced by assignRequest(), clear(), isFinished(), process(), and WebServer().


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