45#include <libdap/D4Group.h>
46#include <libdap/D4Attributes.h>
47#include <libdap/BaseType.h>
48#include <libdap/escaping.h>
50#include <BESContextManager.h>
51#include <BESDataDDSResponse.h>
52#include <BESDapNames.h>
53#include <BESDataNames.h>
57#include <RequestServiceTimer.h>
61#include <BESInternalFatalError.h>
62#include <BESDapError.h>
63#include "BESDMRResponse.h"
64#include <stringbuffer.h>
66#include "FONcBaseType.h"
67#include "FONcRequestHandler.h"
68#include "FONcTransmitter.h"
69#include "FONcTransform.h"
76#define prolog string("FONcTransmitter::").append(__func__).append("() - ")
122 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl);
126 if (!bdds)
throw BESInternalFatalError(
"Expected a BESDataDDSResponse instance", __FILE__, __LINE__);
127 auto dds = bdds->get_dds();
129 string base_name = dds->filename().substr(dds->filename().find_last_of(
"/\\") + 1);
133 string temp_file_name = temp_file.
create(FONcRequestHandler::temp_dir,
"dap2_nc_"+base_name);
135 BESDEBUG(MODULE, prolog <<
"Building response file " << temp_file_name << endl);
137 ostream &strm = dhi.get_output_stream();
138 if (!strm)
throw BESInternalError(
"Output stream is not set, can not return as", __FILE__, __LINE__);
140 BESDEBUG(MODULE, prolog <<
"Transmitting temp file " << temp_file_name << endl);
149 atomic<bool> file_write_done(
false);
156 std::future<uint64_t> result = task.get_future();
157 task(temp_file.
get_name(), file_write_done, strm);
173 std::ref(file_write_done), std::ref(strm));
178 file_write_done =
true;
179 uint64_t tcount = result.get();
192 std::future<uint64_t> result = task.get_future();
193 task(temp_file.
get_name(), file_write_done, strm);
194 uint64_t tcount = result.get();
199 throw BESDapError(
"Failed to read data: " + e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
204 catch (std::exception &e) {
205 throw BESInternalError(
"Failed to read data: STL Error: " +
string(e.what()), __FILE__, __LINE__);
208 throw BESInternalError(
"Failed to get read data: Unknown exception caught", __FILE__, __LINE__);
211 BESDEBUG(MODULE, prolog <<
"END Transmitted as netcdf" << endl);
233 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl);
239 auto dmr = bdmr->get_dmr();
241 string base_name = dmr->filename().substr(dmr->filename().find_last_of(
"/\\") + 1);
245 string temp_file_name = temp_file.
create(FONcRequestHandler::temp_dir,
"dap4_nc_"+base_name);
247 BESDEBUG(MODULE, prolog <<
"Building response file " << temp_file_name << endl);
256 ostream &strm = dhi.get_output_stream();
260 msg << prolog <<
"Using ostream: " << (
void *) &strm << endl;
261 BESDEBUG(MODULE, msg.str());
262 INFO_LOG( msg.str());
265 if (!strm)
throw BESInternalError(
"Output stream is not set, can not return as", __FILE__, __LINE__);
271 BESDEBUG(MODULE, prolog <<
"Transmitting temp file " << temp_file_name << endl);
277 throw BESDapError(
"Failed to read data: " + e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
282 catch (std::exception &e) {
283 throw BESInternalError(
"Failed to read data: STL Error: " +
string(e.what()), __FILE__, __LINE__);
286 throw BESInternalError(
"Failed to get read data: Unknown exception caught", __FILE__, __LINE__);
289 BESDEBUG(MODULE, prolog <<
"END Transmitted as netcdf" << endl);
Represents an OPeNDAP DMR DAP4 data object within the BES.
error object created from libdap error objects and can handle those errors
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
Structure storing information used by the BES to handle the request.
std::map< std::string, std::string > data
the map of string data that will be required for the current request.
Base exception class for the BES with basic string message.
exception thrown if internal error encountered
exception thrown if an internal error is found and is fatal to the BES
Abstract base class representing a specific set of information in response to a request to the BES.
static uint64_t file_to_stream_task(const std::string &file_name, std::atomic< bool > &file_write_done, std::ostream &o_strm)
static void conditional_timeout_cancel()
Checks if the timeout alarm should be canceled based on the value of the BES key BES....
static void file_to_stream(const std::string &file_name, std::ostream &o_strm)
Copies the contents of the file identified by file_name to the stream o_strm.
static void send_dap4_data(BESResponseObject *obj, BESDataHandlerInterface &dhi)
The static method registered to transmit OPeNDAP data objects as a netcdf file.
static void send_dap2_data(BESResponseObject *obj, BESDataHandlerInterface &dhi)
The static method registered to transmit OPeNDAP data objects as a netcdf file.
FONcTransmitter()
Construct the FONcTransmitter, adding it with name netcdf to be able to transmit a data response.
static RequestServiceTimer * TheTimer()
Return a pointer to a singleton timer instance. If an instance does not exist it will create and init...
void throw_if_timeout_expired(const std::string &message, const std::string &file, const int line)
Checks the RequestServiceTimer to determine if the time spent servicing the request at this point has...
Get a new temporary file.
std::string get_name() const
std::string create(const std::string &dir_name="/tmp/hyrax_tmp", const std::string &path_template="opendap")
Create a new temporary file.