OPeNDAP Hyrax Back End Server (BES) Updated for version 3.8.3
BESBasicInterface.cc
Go to the documentation of this file.
00001 // BESBasicInterface.cc
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 // 
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact University Corporation for Atmospheric Research at
00024 // 3080 Center Green Drive, Boulder, CO 80301
00025  
00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00028 //
00029 // Authors:
00030 //      pwest       Patrick West <pwest@ucar.edu>
00031 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
00032 
00033 #include <iostream>
00034 #include <sstream>
00035 
00036 using std::endl ;
00037 using std::stringstream ;
00038 
00039 #include "BESBasicInterface.h"
00040 #include "BESInterface.h"
00041 #include "BESLog.h"
00042 #include "BESDebug.h"
00043 #include "BESReturnManager.h"
00044 #include "BESSyntaxUserError.h"
00045 #include "BESInternalError.h"
00046 #include "BESAggFactory.h"
00047 #include "BESAggregationServer.h"
00048 #include "BESTransmitterNames.h"
00049 #include "BESDataNames.h"
00050 
00057 BESBasicInterface::BESBasicInterface( ostream *strm )
00058     : BESInterface( strm )
00059 {
00060 }
00061 
00062 BESBasicInterface::~BESBasicInterface()
00063 {
00064 }
00065 
00074 int
00075 BESBasicInterface::execute_request( const string &from )
00076 {
00077     return BESInterface::execute_request( from ) ;
00078 }
00079 
00089 void
00090 BESBasicInterface::initialize()
00091 {
00092     // dhi has not been filled in at this point, so let's set a default
00093     // transmitter given the protocol. The transmitter might change after
00094     // parsing a request and given a return manager to use. This is done in
00095     // build_data_plan.
00096     //
00097     // The reason I moved this from the build_data_plan method is because a
00098     // registered initialization routine might throw an exception and we
00099     // will need to transmit the exception info, which needs a transmitter.
00100     // If an exception happens before this then the exception info is just
00101     // printed to cout (see BESInterface::transmit_data()). -- pcw 09/05/06
00102     BESDEBUG( "bes", "Finding " << BASIC_TRANSMITTER << " transmitter ... " << endl ) ;
00103     _transmitter = BESReturnManager::TheManager()->find_transmitter( BASIC_TRANSMITTER ) ;
00104     if( !_transmitter )
00105     {
00106         string s = (string)"Unable to find transmitter "
00107                    + BASIC_TRANSMITTER ;
00108         throw BESInternalError( s, __FILE__, __LINE__ ) ;
00109     }
00110     BESDEBUG( "bes", "OK" << endl ) ;
00111 
00112     BESInterface::initialize() ;
00113 }
00114 
00117 void
00118 BESBasicInterface::validate_data_request()
00119 {
00120     BESInterface::validate_data_request() ;
00121 }
00122 
00127 void
00128 BESBasicInterface::build_data_request_plan()
00129 {
00130     // The derived class build_data_request_plan should be run first to
00131     // parse the incoming request. Once parsed we can determine if there is
00132     // a return command
00133 
00134     // The default _transmitter (either basic or http depending on the
00135     // protocol passed) has been set in initialize. If the parsed command
00136     // sets a RETURN_CMD (a different transmitter) then look it up here. If
00137     // it's set but not found then this is an error. If it's not set then
00138     // just use the defaults.
00139     if( _dhi->data[RETURN_CMD] != "" )
00140     {
00141         BESDEBUG( "bes", "Finding transmitter: " << _dhi->data[RETURN_CMD] << " ...  " << endl ) ;
00142         _transmitter = BESReturnManager::TheManager()->find_transmitter( _dhi->data[RETURN_CMD] ) ;
00143         if( !_transmitter )
00144         {
00145             string s = (string)"Unable to find transmitter "
00146                        + _dhi->data[RETURN_CMD] ;
00147             throw BESSyntaxUserError( s, __FILE__, __LINE__ ) ;
00148         }
00149         BESDEBUG( "bes", "OK" << endl ) ;
00150     }
00151 }
00152 
00160 void
00161 BESBasicInterface::execute_data_request_plan()
00162 {
00163     if( BESLog::TheLog()->is_verbose() )
00164     {
00165         *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00166                              << " from " << _dhi->data[REQUEST_FROM]
00167                              << " [" << _dhi->data[DATA_REQUEST] << "] executing"
00168                              << endl ;
00169     }
00170     BESInterface::execute_data_request_plan() ;
00171 }
00172 
00180 void
00181 BESBasicInterface::invoke_aggregation()
00182 {
00183     if( _dhi->data[AGG_CMD] == "" )
00184     {
00185         if( BESLog::TheLog()->is_verbose() )
00186         {
00187             *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00188                                  << " from " << _dhi->data[REQUEST_FROM]
00189                                  << " [" << _dhi->data[DATA_REQUEST] << "]"
00190                                  << " not aggregating, command empty"
00191                                  << endl ;
00192         }
00193     }
00194     else
00195     {
00196         BESAggregationServer *agg = BESAggFactory::TheFactory()->find_handler( _dhi->data[AGG_HANDLER] ) ;
00197         if( !agg )
00198         {
00199             if( BESLog::TheLog()->is_verbose() )
00200             {
00201                 *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00202                                      << " from " << _dhi->data[REQUEST_FROM]
00203                                      << " [" << _dhi->data[DATA_REQUEST] << "]"
00204                                      << " not aggregating, no handler"
00205                                      << endl ;
00206             }
00207         }
00208         else
00209         {
00210             if( BESLog::TheLog()->is_verbose() )
00211             {
00212                 *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00213                                      << " from " << _dhi->data[REQUEST_FROM]
00214                                      << " [" << _dhi->data[DATA_REQUEST]
00215                                      << "] aggregating" << endl ;
00216             }
00217         }
00218     }
00219     BESInterface::invoke_aggregation() ;
00220 }
00221 
00229 void
00230 BESBasicInterface::transmit_data()
00231 {
00232     if( BESLog::TheLog()->is_verbose() )
00233     {
00234         *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00235                              << " from " << _dhi->data[REQUEST_FROM]
00236                              << " [" << _dhi->data[DATA_REQUEST]
00237                              << "] transmitting" << endl ;
00238     }
00239     BESInterface::transmit_data() ;
00240 } 
00241 
00246 void
00247 BESBasicInterface::log_status()
00248 {
00249     string result = "completed" ;
00250     if( _dhi->error_info )
00251         result = "failed" ;
00252     if( BESLog::TheLog()->is_verbose() )
00253     {
00254         *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00255                              << " from " << _dhi->data[REQUEST_FROM]
00256                              << " [" << _dhi->data[DATA_REQUEST] << "] "
00257                              << result << endl ;
00258     }
00259 }
00260 
00269 void
00270 BESBasicInterface::clean()
00271 {
00272     BESInterface::clean() ;
00273     if( BESLog::TheLog()->is_verbose() )
00274     {
00275         *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00276                              << " from " << _dhi->data[REQUEST_FROM]
00277                              << " [" << _dhi->data[DATA_REQUEST] << "] cleaning"
00278                              << endl ;
00279     }
00280 }
00281 
00288 void
00289 BESBasicInterface::dump( ostream &strm ) const
00290 {
00291     strm << BESIndent::LMarg << "BESBasicInterface::dump - ("
00292                              << (void *)this << ")" << endl ;
00293     BESIndent::Indent() ;
00294     BESInterface::dump( strm ) ;
00295     BESIndent::UnIndent() ;
00296 
00297 
00298 }
00299