OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESBasicInterface.cc
Go to the documentation of this file.
1 // BESBasicInterface.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) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include <iostream>
34 #include <sstream>
35 
36 using std::endl ;
37 using std::stringstream ;
38 
39 #include "BESBasicInterface.h"
40 #include "BESInterface.h"
41 #include "BESLog.h"
42 #include "BESDebug.h"
43 #include "BESReturnManager.h"
44 #include "BESSyntaxUserError.h"
45 #include "BESInternalError.h"
46 #include "BESAggFactory.h"
47 #include "BESAggregationServer.h"
48 #include "BESTransmitterNames.h"
49 #include "BESDataNames.h"
50 
58  : BESInterface( strm )
59 {
60 }
61 
63 {
64 }
65 
74 int
76 {
77  return BESInterface::execute_request( from ) ;
78 }
79 
89 void
91 {
92  // dhi has not been filled in at this point, so let's set a default
93  // transmitter given the protocol. The transmitter might change after
94  // parsing a request and given a return manager to use. This is done in
95  // build_data_plan.
96  //
97  // The reason I moved this from the build_data_plan method is because a
98  // registered initialization routine might throw an exception and we
99  // will need to transmit the exception info, which needs a transmitter.
100  // If an exception happens before this then the exception info is just
101  // printed to cout (see BESInterface::transmit_data()). -- pcw 09/05/06
102  BESDEBUG( "bes", "Finding " << BASIC_TRANSMITTER << " transmitter ... " << endl ) ;
104  if( !_transmitter )
105  {
106  string s = (string)"Unable to find transmitter "
108  throw BESInternalError( s, __FILE__, __LINE__ ) ;
109  }
110  BESDEBUG( "bes", "OK" << endl ) ;
111 
113 }
114 
117 void
119 {
121 }
122 
127 void
129 {
130  // The derived class build_data_request_plan should be run first to
131  // parse the incoming request. Once parsed we can determine if there is
132  // a return command
133 
134  // The default _transmitter (either basic or http depending on the
135  // protocol passed) has been set in initialize. If the parsed command
136  // sets a RETURN_CMD (a different transmitter) then look it up here. If
137  // it's set but not found then this is an error. If it's not set then
138  // just use the defaults.
139  if( _dhi->data[RETURN_CMD] != "" )
140  {
141  BESDEBUG( "bes", "Finding transmitter: " << _dhi->data[RETURN_CMD] << " ... " << endl ) ;
143  if( !_transmitter )
144  {
145  string s = (string)"Unable to find transmitter "
146  + _dhi->data[RETURN_CMD] ;
147  throw BESSyntaxUserError( s, __FILE__, __LINE__ ) ;
148  }
149  BESDEBUG( "bes", "OK" << endl ) ;
150  }
151 }
152 
160 void
162 {
163  if( BESLog::TheLog()->is_verbose() )
164  {
166  << " from " << _dhi->data[REQUEST_FROM]
167  << " [" << _dhi->data[DATA_REQUEST] << "] executing"
168  << endl ;
169  }
171 }
172 
180 void
182 {
183  if( _dhi->data[AGG_CMD] == "" )
184  {
185  if( BESLog::TheLog()->is_verbose() )
186  {
188  << " from " << _dhi->data[REQUEST_FROM]
189  << " [" << _dhi->data[DATA_REQUEST] << "]"
190  << " not aggregating, command empty"
191  << endl ;
192  }
193  }
194  else
195  {
197  if( !agg )
198  {
199  if( BESLog::TheLog()->is_verbose() )
200  {
202  << " from " << _dhi->data[REQUEST_FROM]
203  << " [" << _dhi->data[DATA_REQUEST] << "]"
204  << " not aggregating, no handler"
205  << endl ;
206  }
207  }
208  else
209  {
210  if( BESLog::TheLog()->is_verbose() )
211  {
213  << " from " << _dhi->data[REQUEST_FROM]
214  << " [" << _dhi->data[DATA_REQUEST]
215  << "] aggregating" << endl ;
216  }
217  }
218  }
220 }
221 
229 void
231 {
232  if( BESLog::TheLog()->is_verbose() )
233  {
235  << " from " << _dhi->data[REQUEST_FROM]
236  << " [" << _dhi->data[DATA_REQUEST]
237  << "] transmitting" << endl ;
238  }
240 }
241 
246 void
248 {
249  string result = "completed" ;
250  if( _dhi->error_info )
251  result = "failed" ;
252  if( BESLog::TheLog()->is_verbose() )
253  {
255  << " from " << _dhi->data[REQUEST_FROM]
256  << " [" << _dhi->data[DATA_REQUEST] << "] "
257  << result << endl ;
258  }
259 }
260 
269 void
271 {
273  if( BESLog::TheLog()->is_verbose() )
274  {
276  << " from " << _dhi->data[REQUEST_FROM]
277  << " [" << _dhi->data[DATA_REQUEST] << "] cleaning"
278  << endl ;
279  }
280 }
281 
288 void
289 BESBasicInterface::dump( ostream &strm ) const
290 {
291  strm << BESIndent::LMarg << "BESBasicInterface::dump - ("
292  << (void *)this << ")" << endl ;
294  BESInterface::dump( strm ) ;
296 
297 
298 }
299 
virtual BESTransmitter * find_transmitter(const string &name)
#define DATA_REQUEST
Definition: BESDataNames.h:36
exception thrown if inernal error encountered
static BESAggFactory * TheFactory()
virtual void initialize()
Initialize the BES object.
#define SERVER_PID
Definition: BESDataNames.h:51
bool is_verbose()
Returns true if verbose logging is requested.
Definition: BESLog.h:162
#define AGG_CMD
Definition: BESDataNames.h:40
virtual void transmit_data()
Transmit the resulting response object.
#define RETURN_CMD
Definition: BESDataNames.h:45
BESTransmitter * _transmitter
Definition: BESInterface.h:137
virtual void transmit_data()
Transmit the response object.
#define BASIC_TRANSMITTER
macros representing the default transmitter objects
static void Indent()
Definition: BESIndent.cc:38
virtual void build_data_request_plan()
Build the data request plan using the BESCmdParser.
error thrown if there is a user syntax error in the request or any other user error ...
virtual ~BESBasicInterface()
static BESReturnManager * TheManager()
BESBasicInterface(ostream *strm)
Instantiate a BESBasicInterface object given an output stream for the response object.
virtual void log_status()
Log the status of the request to the BESLog file.
Entry point into BES, building responses to given requests.
Definition: BESInterface.h:123
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
virtual BESAggregationServer * find_handler(string handler_name)
returns the aggregation handler with the given name in the list
virtual void invoke_aggregation()
Invoke the aggregation server, if there is one.
#define AGG_HANDLER
Definition: BESDataNames.h:41
virtual void validate_data_request()
Validate the incoming request information.
virtual void clean()
Clean up after the request.
#define REQUEST_FROM
Definition: BESDataNames.h:38
virtual void invoke_aggregation()
Aggregate the resulting response object.
map< string, string > data
the map of string data that will be required for the current request.
virtual void dump(ostream &strm) const
dumps information about this object
static BESLog * TheLog()
Definition: BESLog.cc:347
virtual void validate_data_request()
Validate the incoming request information.
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
BESInfo * error_info
error information object
virtual void execute_data_request_plan()
Execute the data request plan.
static void UnIndent()
Definition: BESIndent.cc:44
Abstraction representing mechanism for aggregating data.
virtual void execute_data_request_plan()
Execute the data request plan.
virtual int execute_request(const string &from)
Executes the given request to generate a specified response object.
BESDataHandlerInterface * _dhi
Definition: BESInterface.h:136
virtual void initialize()
Initialize the BES.
virtual void clean()
Clean up after the request is completed.
virtual int execute_request(const string &from)
Override execute_request in order to register memory pool.
virtual void dump(ostream &strm) const
dumps information about this object