bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
BESDap4ResponseHandler.cc
1// BESDap4ResponseHandler.cc
2
3// This file is part of bes, A C++ back-end server implementation framework
4// for the OPeNDAP Data Access Protocol.
5
6// Copyright (c) 2013 OPeNDAP
7// Author: James Gallagher <jgallagher@opendap.org>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
23#include "config.h"
24
25#include <memory>
26
27#include <libdap/DMR.h>
28
29#include "BESDap4ResponseHandler.h"
30#include "BESDMRResponse.h"
31#include "BESRequestHandlerList.h"
32#include "BESDapNames.h"
33#include "BESDapTransmit.h"
34#include "BESContextManager.h"
35#include "TheBESKeys.h"
36#include "BESDebug.h"
37
38#include "GlobalMetadataStore.h"
39
40using namespace std;
41using namespace bes;
42
43BESDap4ResponseHandler::BESDap4ResponseHandler(const string &name)
44 : BESResponseHandler(name), d_use_dmrpp(false), d_dmrpp_name(DMRPP_DEFAULT_NAME)
45{
46 d_use_dmrpp = TheBESKeys::TheKeys()->read_bool_key(USE_DMRPP_KEY, false); // defined in BESDapNames.h
47 d_dmrpp_name = TheBESKeys::TheKeys()->read_string_key(DMRPP_NAME_KEY, DMRPP_DEFAULT_NAME);
48}
49
50BESDap4ResponseHandler::~BESDap4ResponseHandler()
51{
52}
53
62{
63 dhi.action_name = DAP4DATA_RESPONSE_STR;
64
65 if (d_use_dmrpp) {
67
69 dhi.first_container();
70 if (mds) lock = mds->is_dmrpp_available(*(dhi.container));
71
72 // If we were able to lock the DMR++ it must exist; use it.
73 if (mds && lock()) {
74 BESDEBUG("dmrpp",
75 "In BESDap4ResponseHandler::execute(): Found a DMR++ response for '" << dhi.container->get_relative_name() << "'" << endl);
76
77 // Redirect the request to the DMR++ handler
78 dhi.container->set_container_type(d_dmrpp_name);
79
80 // Add information to the container so the dmrpp handler works
81 // This tells DMR++ handler to look for this in the MDS
82 dhi.container->set_attributes(MDS_HAS_DMRPP);
83 }
84 }
85
86 unique_ptr<DMR> dmr(new DMR());
87
88 bool found;
89 int response_size_limit = BESContextManager::TheManager()->get_context_int("max_response_size", found);
90
91 if (found)
92 dmr->set_response_limit_kb(response_size_limit);
93
94 d_response_object = new BESDMRResponse(dmr.release());
95
96 BESRequestHandlerList::TheList()->execute_each(dhi);
97}
98
112{
113 if (d_response_object) {
114 transmitter->send_response(DAP4DATA_SERVICE, d_response_object, dhi);
115 }
116}
117
124void BESDap4ResponseHandler::dump(ostream &strm) const
125{
126 strm << BESIndent::LMarg << "BESDap4ResponseHandler::dump - (" << (void *) this << ")" << endl;
127 BESIndent::Indent();
129 BESIndent::UnIndent();
130}
131
133BESDap4ResponseHandler::Dap4ResponseBuilder(const string &name)
134{
135 return new BESDap4ResponseHandler(name);
136}
137
void set_container_type(const std::string &type)
set the type of data that this container represents, such as cedar or netcdf.
std::string get_relative_name() const
Get the relative name of the object in this container.
void set_attributes(const std::string &attrs)
set desired attributes for this container
Represents an OPeNDAP DMR DAP4 data object within the BES.
response handler that builds an OPeNDAP Dap4 data response
virtual void execute(BESDataHandlerInterface &dhi)
executes the command 'get dap for def_name;'
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command using the specified transmitter object
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
handler object that knows how to create a specific response object
void dump(std::ostream &strm) const override
dumps information about this object
static TheBESKeys * TheKeys()
Access to the singleton.
Definition TheBESKeys.cc:85
static bool read_bool_key(const std::string &key, bool default_value)
Read a boolean-valued key from the bes.conf file.
static std::string read_string_key(const std::string &key, const std::string &default_value)
Read a string-valued key from the bes.conf file.
Store the DAP metadata responses.
static GlobalMetadataStore * get_instance()
virtual MDSReadLock is_dmrpp_available(const std::string &name)
Is the DMR++ response for.
Unlock and close the MDS item when the ReadLock goes out of scope.