1
0
Fork 0

correct callback jsons

This commit is contained in:
Kaveh Vahedipour 2016-04-12 16:01:00 +02:00
parent c2665a63f8
commit 9bd08b98c4
3 changed files with 11 additions and 77 deletions

View File

@ -145,14 +145,6 @@ Node& Node::operator= (VPackSlice const& slice) {
_children.clear();
_value.reset();
_value.append(reinterpret_cast<char const*>(slice.begin()), slice.byteSize());
/*
notifyObservers(uri());
Node *par = _parent;
while (par != 0) {
_parent->notifyObservers(uri());
par = par->_parent;
}
*/
return *this;
}
@ -167,14 +159,6 @@ Node& Node::operator= (Node const& rhs) {
_node_name = rhs._node_name;
_value = rhs._value;
_children = rhs._children;
/*
notifyObservers(uri());
Node *par = _parent;
while (par != 0) {
_parent->notifyObservers(uri());
par = par->_parent;
}
*/
return *this;
}
@ -300,61 +284,6 @@ bool Node::removeTimeToLive () {
return true;
}
// Add observing url for this node
/*bool Node::addObserver (std::string const& uri) {
auto it = std::find(_observers.begin(), _observers.end(), uri);
if (it==_observers.end()) {
_observers.emplace(uri);
return true;
}
return false;
}*/
/*void Node::notifyObservers (std::string const& origin) const {
for (auto const& i : _observers) {
Builder body;
body.openObject();
body.add(uri(), VPackValue(VPackValueType::Object));
body.add("op",VPackValue("modified"));
body.close();
body.close();
std::stringstream endpoint;
std::string path = "/";
size_t pos = 7;
if (i.find("http://")==0) {
endpoint << "tcp://";
} else if (i.find("https://")==0) {
endpoint << "ssl://";
++pos;
} else {
LOG_TOPIC(WARN,Logger::AGENCY) << "Malformed notification URL " << i;
return;
}
size_t slash_p = i.find("/",pos);
if ((slash_p==std::string::npos)) {
endpoint << i.substr(pos);
} else {
endpoint << i.substr(pos,slash_p-pos);
path = i.substr(slash_p);
}
std::unique_ptr<std::map<std::string, std::string>> headerFields =
std::make_unique<std::map<std::string, std::string> >();
ClusterCommResult res =
arangodb::ClusterComm::instance()->asyncRequest(
"1", 1, endpoint.str(), GeneralRequest::RequestType::POST, path,
std::make_shared<std::string>(body.toString()), headerFields, nullptr,
0.0, true);
}
}*/
inline bool Node::observedBy (std::string const& url) const {
auto ret = root()._observer_table.equal_range(url);
for (auto it = ret.first; it!=ret.second; ++it) {
@ -504,10 +433,9 @@ template<> bool Node::handle<OBSERVE> (VPackSlice const& slice) {
if (!observedBy(url)) {
root()._observer_table.emplace(std::pair<std::string,std::string>(url,uri));
root()._observed_table.emplace(std::pair<std::string,std::string>(uri,url));
// _observers.emplace(url);
return true;
}
return false;
}
@ -520,7 +448,9 @@ template<> bool Node::handle<UNOBSERVE> (VPackSlice const& slice) {
return false;
std::string url (slice.get("url").copyString()),
uri (this->uri());
// delete in both cases a single entry (ensured above)
// breaking the iterators is fine then
auto ret = root()._observer_table.equal_range(url);
for (auto it = ret.first; it!=ret.second; ++it) {
if (it->second == uri) {
@ -750,12 +680,17 @@ std::vector<bool> Store::apply (
for (auto it = ret.first; it!=ret.second; ++it) {
body.add(it->second->key,VPackValue(VPackValueType::Object));
body.add(it->second->modified,VPackValue(VPackValueType::Object));
body.add("op",VPackValue(it->second->oper));
body.close();
body.close();
}
body.close();
std::cout << url << body.toString() << std::endl;
std::string endpoint, path;
if (endpointPathFromUrl (url,endpoint,path)) {

View File

@ -174,8 +174,6 @@ protected:
TimePoint _ttl; /**< @brief my expiry */
Buffer<uint8_t> _value; /**< @brief my value */
// std::unordered_set<std::string> _observers; /**< @brief my observers */
/// @brief Table of expiries in tree (only used in root node)
std::multimap<TimePoint, std::shared_ptr<Node>> _time_table;

View File

@ -155,7 +155,8 @@ HttpHandler::status_t RestAgencyHandler::handleWrite () {
body.close();
if (errors > 0) { // Some/all requests failed
generateResult(GeneralResponse::ResponseCode::PRECONDITION_FAILED, body.slice());
generateResult(GeneralResponse::ResponseCode::PRECONDITION_FAILED,
body.slice());
} else { // All good
generateResult(GeneralResponse::ResponseCode::OK, body.slice());
}