示例#1
0
 void bulk_write(std::vector<std::string> bulk, callback_type callback) {
     ES_LOG(log, "requesting 'bulk_write' ...");
     transport.perform(
         actions::bulk_write_t(settings.index, settings.type, std::move(bulk)),
         callback
     );
 }
示例#2
0
 client_t(const settings_t& settings, loop_type& loop, logger_type& log) :
     settings(settings),
     log(log),
     transport(settings, loop, log)
 {
     transport.add_nodes(settings.endpoints);
     if (settings.sniffer.when.start) {
         ES_LOG(log, "sniff.on.start is true - preparing to update nodes list");
         transport.sniff();
     }
 }
示例#3
0
 void perform(Action&& action,
              typename callback<Action>::type callback,
              long timeout) {
     const std::string url = make_url(action.path());
     response_handler_t<
         Action,
         http_connection_t
     > handler(callback, endpoint_, log);
     ES_LOG(log, "requesting '%s' ...", url);
     perform(std::move(action), std::move(handler), url, timeout);
 }
示例#4
0
    void
    operator()(urlfetch::request_t&& request,
               urlfetch::response_t&& response,
               const boost::system::error_code& ec) {
        ES_LOG(log, "response received from '%s' [%s]: %s",
               request.url, ec.value(), response.data
        );

        if (ec) {
            callback(
                result_type(
                    error_t(connection_error_t(endpoint, ec.message()))
                )
            );
            return;
        }

        rapidjson::Document doc;
        doc.Parse<0>(response.data.c_str());
        if (doc.HasParseError()) {
            callback(result_type(error_t(generic_error_t(doc.GetParseError()))));
            return;
        }

        const rapidjson::Value& error = doc["error"];
        if (!error.IsNull()) {
            callback(result_type(
                error_t(generic_error_t(
                    error.IsString() ? error.GetString() : "unknown"))
                )
            );
            return;
        }

        try {
            callback(result_type(extractor_t<response_type>::extract(doc)));
        } catch (const std::exception& err) {
            callback(result_type(error_t(generic_error_t(err.what()))));
        }
    }