ReCodEx - Task Broker
ReCodEx is complex programmer testing solution, primary targeted to technical universities. It's highly customizable and based on modern technologies.
worker_registry.cpp
1 #include "worker_registry.h"
2 
3 #include <algorithm>
4 
5 
7 {
8 }
9 
11 {
12  workers_.push_back(worker);
13 }
14 
16 {
17  auto it = std::find(std::begin(workers_), std::end(workers_), worker);
18 
19  if (it != std::end(workers_)) {
20  workers_.erase(it);
21  }
22 }
23 
25 {
26  for (auto &worker : workers_) {
27  bool is_worker_suitable = true;
28 
29  for (auto &header : headers) {
30  if (!worker->check_header(header.first, header.second)) {
31  is_worker_suitable = false;
32  break;
33  }
34  }
35 
36  if (is_worker_suitable) {
37  return worker;
38  }
39  }
40 
41  return nullptr;
42 }
43 
45 {
46  for (auto &worker : workers_) {
47  if (worker->identity == identity) {
48  return worker;
49  }
50  }
51 
52  return nullptr;
53 }
54 
56 {
57  auto it = std::find(std::begin(workers_), std::end(workers_), worker);
58 
59  if (it != std::end(workers_) && (it + 1) != std::end(workers_)) {
60  workers_.erase(it);
61  workers_.push_back(worker);
62  }
63 }
64 
65 const std::vector<worker_registry::worker_ptr> &worker_registry::get_workers() const
66 {
67  return workers_;
68 }
virtual bool check_header(const std::string &header, const std::string &value)
Definition: worker.cpp:170
virtual worker_ptr find_worker_by_identity(const std::string &identity)
virtual void add_worker(worker_ptr worker)
virtual void deprioritize_worker(worker_ptr worker)
virtual worker_ptr find_worker(const request::headers_t &headers)
std::shared_ptr< worker > worker_ptr
std::multimap< std::string, std::string > headers_t
Definition: worker.h:80
Definition: worker.h:147
virtual const std::vector< worker_ptr > & get_workers() const
const std::string identity
Definition: worker.h:171
virtual void remove_worker(worker_ptr worker)