Aggie Student Toolkit — Load Balancer CSCE 412 Project 4
Arnav Fotedar · Fall 2026 · C++ load balancer simulation
Loading...
Searching...
No Matches
Switch.h
Go to the documentation of this file.
1
6
7#ifndef SWITCH_H
8#define SWITCH_H
9
10#include <memory>
11#include <vector>
12
13#include "LoadBalancer.h"
14#include "Request.h"
15
24class Switch {
25public:
31 Switch(std::unique_ptr<LoadBalancer> processing, std::unique_ptr<LoadBalancer> streaming);
32
39 bool route(const Request& request, unsigned long cycle);
40
42 void start();
43
49 void processCycle(unsigned long cycle, const std::vector<Request>& arrivals);
50
56 unsigned long routedProcessing() const;
58 unsigned long routedStreaming() const;
59
60private:
61 std::unique_ptr<LoadBalancer> processing_;
62 std::unique_ptr<LoadBalancer> streaming_;
63 unsigned long routedProcessing_ = 0;
64 unsigned long routedStreaming_ = 0;
65};
66
67#endif
Declares the LoadBalancer class, which queues requests, dispatches them and scales its server pool.
Defines the Request structure and its JobType that flow through the load balancer.
Distributes queued requests across a dynamically sized pool of WebServer objects.
LoadBalancer & processing()
Definition Switch.cpp:48
unsigned long routedStreaming() const
Definition Switch.cpp:54
Switch(std::unique_ptr< LoadBalancer > processing, std::unique_ptr< LoadBalancer > streaming)
Creates a switch that owns both load balancers.
Definition Switch.cpp:11
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.
Definition Switch.cpp:32
LoadBalancer & streaming()
Definition Switch.cpp:50
unsigned long routedProcessing() const
Definition Switch.cpp:52
void start()
Starts both load balancers (records starting queues, dispatches at time 0).
Definition Switch.cpp:27
bool route(const Request &request, unsigned long cycle)
Sends one request to the load balancer for its job type.
Definition Switch.cpp:18
A single web request waiting for, or receiving, service.
Definition Request.h:41