Repository navigation
Expand file tree
/
Copy pathPatternMatchingQueryProxy.cc
More file actions
91 lines (73 loc) · 3.15 KB
/
Copy pathPatternMatchingQueryProxy.cc
File metadata and controls
91 lines (73 loc) · 3.15 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "PatternMatchingQueryProxy.h"
#include "ServiceBus.h"
#define LOG_LEVEL INFO_LEVEL
#include "Logger.h"
using namespace query_engine;
// -------------------------------------------------------------------------------------------------
// Constructors, destructors and initialization
string PatternMatchingQueryProxy::COUNT = "count";
string PatternMatchingQueryProxy::POSITIVE_IMPORTANCE_FLAG = "positive_importance_flag";
string PatternMatchingQueryProxy::UNIQUE_VALUE_FLAG = "unique_value_flag";
string PatternMatchingQueryProxy::COUNT_FLAG = "count_flag";
PatternMatchingQueryProxy::PatternMatchingQueryProxy() {
// constructor typically used in processor
lock_guard<mutex> semaphore(this->api_mutex);
set_default_parameters();
}
PatternMatchingQueryProxy::PatternMatchingQueryProxy(const vector<string>& tokens, const string& context)
: BaseQueryProxy(tokens, context) {
// constructor typically used in requestor
lock_guard<mutex> semaphore(this->api_mutex);
set_default_parameters();
this->command = ServiceBus::PATTERN_MATCHING_QUERY;
}
void PatternMatchingQueryProxy::set_default_parameters() {
this->parameters[POSITIVE_IMPORTANCE_FLAG] = false;
this->parameters[UNIQUE_VALUE_FLAG] = false;
this->parameters[COUNT_FLAG] = false;
}
PatternMatchingQueryProxy::~PatternMatchingQueryProxy() {}
// -------------------------------------------------------------------------------------------------
// Client-side API
shared_ptr<QueryAnswer> PatternMatchingQueryProxy::pop() {
lock_guard<mutex> semaphore(this->api_mutex);
if (this->parameters.get<bool>(COUNT_FLAG)) {
Utils::error("Can't pop QueryAnswers from count_only queries.");
return shared_ptr<QueryAnswer>(NULL);
} else {
return BaseQueryProxy::pop();
}
}
// -------------------------------------------------------------------------------------------------
// Server-side API
void PatternMatchingQueryProxy::pack_command_line_args() { tokenize(this->args); }
// ---------------------------------------------------------------------------------------------
// Virtual superclass API and the piggyback methods called by it
bool PatternMatchingQueryProxy::from_remote_peer(const string& command, const vector<string>& args) {
LOG_DEBUG("Proxy command: <" << command << "> from " << this->peer_id() << " received in "
<< this->my_id());
if (BaseQueryProxy::from_remote_peer(command, args)) {
return true;
} else {
if (command == COUNT) {
count_answer(args);
return true;
} else {
Utils::error("Invalid proxy command: <" + command + ">");
return false;
}
}
}
void PatternMatchingQueryProxy::count_answer(const vector<string>& args) {
lock_guard<mutex> semaphore(this->api_mutex);
if (!this->is_aborting()) {
if (args.size() != 1) {
Utils::error("Invalid args for count command");
}
if (!this->parameters.get<bool>(COUNT_FLAG)) {
Utils::error("Invalid count command. Query is not count_only.");
} else {
this->set_count(stoi(args[0]));
}
}
}