Aggie Student Toolkit — Load Balancer CSCE 412 Project 4
Arnav Fotedar · Fall 2026 · C++ load balancer simulation
Loading...
Searching...
No Matches
Switch Class Reference

Routes each request to a processing or a streaming LoadBalancer. More...

#include <Switch.h>

Public Member Functions

 Switch (std::unique_ptr< LoadBalancer > processing, std::unique_ptr< LoadBalancer > streaming)
 Creates a switch that owns both load balancers.
bool route (const Request &request, unsigned long cycle)
 Sends one request to the load balancer for its job type.
void start ()
 Starts both load balancers (records starting queues, dispatches at time 0).
void processCycle (unsigned long cycle, const std::vector< Request > &arrivals)
 Splits this cycle's arrivals by job type and runs one cycle on both load balancers.
LoadBalancer & processing ()
LoadBalancer & streaming ()
unsigned long routedProcessing () const
unsigned long routedStreaming () const

Detailed Description

Routes each request to a processing or a streaming LoadBalancer.

The switch sits in front of two independent load balancers. Requests with JobType::Processing ('P') go to one, requests with JobType::Streaming ('S') go to the other. Each load balancer keeps its own queue and scales its own server pool, so a surge in one kind of traffic does not slow the other.

Definition at line 24 of file Switch.h.

Constructor & Destructor Documentation

◆ Switch()

Switch::Switch ( std::unique_ptr< LoadBalancer > processing,
std::unique_ptr< LoadBalancer > streaming )

Creates a switch that owns both load balancers.

Parameters
processingLoad balancer for 'P' requests.
streamingLoad balancer for 'S' requests.

Definition at line 11 of file Switch.cpp.

Member Function Documentation

◆ route()

bool Switch::route ( const Request & request,
unsigned long cycle )

Sends one request to the load balancer for its job type.

Parameters
requestRequest to route.
cycleCurrent clock cycle.
Returns
True if the receiving load balancer queued the request.

Definition at line 18 of file Switch.cpp.

◆ start()

void Switch::start ( )

Starts both load balancers (records starting queues, dispatches at time 0).

Definition at line 27 of file Switch.cpp.

◆ processCycle()

void Switch::processCycle ( unsigned long cycle,
const std::vector< Request > & arrivals )

Splits this cycle's arrivals by job type and runs one cycle on both load balancers.

Parameters
cycleClock cycle being simulated.
arrivalsRequests generated during this cycle.

Definition at line 32 of file Switch.cpp.

◆ processing()

LoadBalancer & Switch::processing ( )
Returns
Load balancer that handles processing requests.

Definition at line 48 of file Switch.cpp.

◆ streaming()

LoadBalancer & Switch::streaming ( )
Returns
Load balancer that handles streaming requests.

Definition at line 50 of file Switch.cpp.

◆ routedProcessing()

unsigned long Switch::routedProcessing ( ) const
Returns
Requests routed to the processing load balancer.

Definition at line 52 of file Switch.cpp.

◆ routedStreaming()

unsigned long Switch::routedStreaming ( ) const
Returns
Requests routed to the streaming load balancer.

Definition at line 54 of file Switch.cpp.


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