-
Notifications
You must be signed in to change notification settings - Fork 3
/
BrokerTasks.h
61 lines (48 loc) · 1.5 KB
/
BrokerTasks.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once
#include <map>
#include "Ensure.h"
#include "Except.h"
#include "WorkerPool.h"
#include "ZMQIdentity.h"
struct BrokerTasks
{
using WorkerIterator = WorkerPool::WorkerSeq::iterator;
struct TaskInfo
{
WorkerIterator workerIterator_;
ZMQIdentity clientIdentity_;
TaskInfo(WorkerIterator workerIterator, ZMQIdentity clientIdentity):
workerIterator_{workerIterator},
clientIdentity_{clientIdentity}
{}
TaskInfo(const TaskInfo &) = delete;
TaskInfo &operator= (const TaskInfo &) = delete;
TaskInfo(TaskInfo &&) = default;
TaskInfo &operator= (TaskInfo &&) = default;
};
using TaskInfoMap = std::map<ZMQIdentity, TaskInfo>;
private:
TaskInfoMap taskInfoMap_;
public:
bool valid(const ZMQIdentity &identity) const
{
return taskInfoMap_.count(identity);
}
void append(WorkerIterator workerIterator, ZMQIdentity clientIdentity)
{
ENSURE(0 == taskInfoMap_.count(workerIterator->identity_), WorkerDuplicate);
taskInfoMap_.emplace(
std::make_pair(
workerIterator->identity_,
TaskInfo{workerIterator, clientIdentity}));
}
void remove(const ZMQIdentity &workerIdentity)
{
taskInfoMap_.erase(workerIdentity);
}
const TaskInfo &taskInfo(const ZMQIdentity &workerIdentity) const
{
ENSURE(valid(workerIdentity), IdentityInvalid);
return taskInfoMap_.at(workerIdentity);
}
};