33#include < reactor-cpp/mutations/bank.hh>
44#include < reactor-cpp/mutations/connection.hh>
55
6+ #include " ../../lib/mutation/bank.cc"
7+ #include " ../../lib/mutation/connection.cc"
68#include " ./consumer.hh"
79#include " ./load_balancer.hh"
810#include " ./producer.hh"
9- #include " ../../lib/mutation/bank.cc"
10- #include " ../../lib/mutation/connection.cc"
1111#include < reactor-cpp/reactor-cpp.hh>
1212
1313class Deployment : public Reactor {
1414 std::unique_ptr<Producer> producer_;
1515 std::unique_ptr<LoadBalancer> load_balancer_;
1616 std::vector<std::unique_ptr<Consumer>> consumers_;
1717
18- Reaction scale_bank{" scale_bank" , 1 , this , [this ](){this ->__inner .reaction_1 (this ->scale , this ->consumers_ , load_balancer_->out );}};
18+ Reaction scale_bank{" scale_bank" , 1 , this ,
19+ [this ]() { this ->__inner .reaction_1 (this ->scale , this ->consumers_ , load_balancer_->out ); }};
1920
2021public:
21-
22- class Inner : public MutableScope {
22+ class Inner : public MutableScope {
2323 int state = 0 ;
24- [[maybe_unused]] const Inner& __lf_inner = *this ;
25- public:
24+ const Inner& __lf_inner = *this ;
2625
27- Inner (Reactor* reactor) : MutableScope(reactor) {}
28- void reaction_1 (const Input<unsigned >& scale, std::vector<std::unique_ptr<Consumer>>& reactor_bank, ModifableMultiport<Output<unsigned >>& load_balancer) {
26+ public:
27+ Inner (Reactor* reactor)
28+ : MutableScope(reactor) {}
29+ void reaction_1 (const Input<unsigned >& scale, std::vector<std::unique_ptr<Consumer>>& reactor_bank,
30+ ModifableMultiport<Output<unsigned >>& load_balancer) {
2931 std::size_t new_size = *scale.get ();
3032 std::size_t old_size = reactor_bank.size ();
3133
32- std::function<std::unique_ptr<Consumer>(Reactor*, std:: size_t )> lambda = [](Reactor* reactor, std::size_t index) {
34+ std::function lambda = [](Reactor* reactor, std::size_t index) {
3335 std::string __lf_inst_name = " consumer_" + std::to_string (index);
3436 return std::make_unique<Consumer>(__lf_inst_name, reactor->environment (), index);
3537 };
36- auto change_size = std::make_shared<MutationChangeBankSize<std::unique_ptr<Consumer>>>(&reactor_bank, this ->reactor_ , new_size, lambda);
38+
39+ auto change_size = std::make_shared<MutationChangeBankSize<std::unique_ptr<Consumer>>>(
40+ &reactor_bank, this ->reactor_ , new_size, lambda);
3741
3842 add_to_transaction (change_size);
3943
40- // old topology
4144 commit_transaction ();
42- // new topology
43-
44- if (old_size > new_size) {
4545
46- for (auto i = 0 ; i < old_size - new_size; i++) {
47- }
48- } else {
49- std::cout << " load_balancer size:" << load_balancer.size () << " bank size: " << reactor_bank.size () << std::endl;
46+ if (old_size < new_size) {
5047 for (auto i = 0 ; i < new_size; i++) {
51- auto add_conn = std::make_shared<MutationAddConnection<Output<unsigned >, Input<unsigned >>>(&load_balancer[i], &reactor_bank[i].get ()->in , reactor_);
52- add_to_transaction (add_conn);
48+ auto add_conn = std::make_shared<MutationAddConnection<Output<unsigned >, Input<unsigned >>>(
49+ &load_balancer[i], &reactor_bank[i].get ()->in , reactor_);
50+ add_to_transaction (add_conn);
5351 }
54- commit_transaction (true );
5552 }
5653
57- std::cout << " new bank size: " << reactor_bank. size () << std::endl ;
54+ commit_transaction ( true ) ;
5855 }
5956
6057 friend LoadBalancer;
6158 };
6259
6360 Inner __inner;
6461
65- Deployment (const std::string& name, Environment* env) : Reactor(name, env), __inner(this ),
66- producer_ (std::make_unique<Producer>(" producer" , environment())),
67- load_balancer_(std::make_unique<LoadBalancer>(" load_balancer" , environment())) {
62+ Deployment (const std::string& name, Environment* env)
63+ : Reactor(name, env)
64+ , __inner(this )
65+ , producer_(std::make_unique<Producer>(" producer" , environment()))
66+ , load_balancer_(std::make_unique<LoadBalancer>(" load_balancer" , environment())) {
6867 std::cout << " creating instance of deployment" << std::endl;
6968 consumers_.reserve (4 );
7069 for (size_t __lf_idx = 0 ; __lf_idx < 4 ; __lf_idx++) {
@@ -86,9 +85,8 @@ class Inner: public MutableScope {
8685 }
8786};
8887
89-
9088auto main () -> int {
91- // srand(time(nullptr));
89+ // srand(time(nullptr));
9290 Environment env{4 , true };
9391 auto deployment = std::make_unique<Deployment>(" c1" , &env);
9492 env.optimize ();
0 commit comments