47#include "BESStreamResponseHandler.h"
48#include "BESRequestHandlerList.h"
49#include "BESForbiddenError.h"
50#include "BESNotFoundError.h"
51#include "BESInternalError.h"
52#include "BESDataNames.h"
53#include "BESContainer.h"
54#include "BESDataHandlerInterface.h"
56#include "RequestServiceTimer.h"
58#define BES_STREAM_BUFFER_SIZE 4096
61#define prolog std::string("BESStreamResponseHandler::").append(__func__).append("() - ")
63BESStreamResponseHandler::BESStreamResponseHandler(
const string &name) :
68BESStreamResponseHandler::~BESStreamResponseHandler()
86 d_response_object = 0;
97 if (bes_timeout != 0) {
116 if (dhi.containers.size() != 1) {
117 string err = (string)
"Unable to stream file: " +
"no container specified";
123 string filename = container->
access();
124 if (filename.empty()) {
125 string err = (string)
"Unable to stream file: " +
"filename not specified";
131 os.open(filename.c_str(), ios::in);
134 string serr = (string)
"Unable to stream file because it cannot be opened. file: '" + filename +
"' msg: ";
135 char *err = strerror(myerrno);
139 serr +=
"Unknown error";
144 if (myerrno == ENOENT || myerrno == ENOTDIR) {
153 char block[BES_STREAM_BUFFER_SIZE];
154 os.read(block,
sizeof block);
155 nbytes = os.gcount();
158 dhi.get_output_stream().write((
char*) block, nbytes);
160 os.read(block,
sizeof block);
161 nbytes = os.gcount();
188 strm << BESIndent::LMarg <<
"BESStreamResponseHandler::dump - (" << (
void *)
this <<
")" << endl;
191 BESIndent::UnIndent();
195BESStreamResponseHandler::BESStreamResponseBuilder(
const string &name)
A container is something that holds data. E.G., a netcdf file or a database entry.
virtual std::string access()=0
returns the true name of this container
Structure storing information used by the BES to handle the request.
void first_container()
set the container pointer to the first container in the containers list
BESContainer * container
pointer to current container in this interface
error thrown if the BES is not allowed to access the resource requested
exception thrown if internal error encountered
error thrown if the resource requested cannot be found
handler object that knows how to create a specific response object
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &r)
transmit the file, streaming it back to the client
virtual void execute(BESDataHandlerInterface &r)
executes the command 'get file <filename>;' by streaming the specified file
static void conditional_timeout_cancel()
Checks if the timeout alarm should be canceled based on the value of the BES key BES....
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...