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 "BESBasicHttpTransmitter.h"
00044 #include "BESReturnManager.h"
00045 #include "BESSyntaxUserError.h"
00046 #include "BESInternalError.h"
00047 #include "BESAggFactory.h"
00048 #include "BESAggregationServer.h"
00049 #include "BESTransmitterNames.h"
00050 #include "BESDataNames.h"
00051 
00058 BESBasicInterface::BESBasicInterface( ostream *strm )
00059     : BESInterface( strm )
00060 {
00061 }
00062 
00063 BESBasicInterface::~BESBasicInterface()
00064 {
00065 }
00066 
00075 int
00076 BESBasicInterface::execute_request( const string &from )
00077 {
00078     return BESInterface::execute_request( from ) ;
00079 }
00080 
00090 void
00091 BESBasicInterface::initialize()
00092 {
00093     // dhi has not been filled in at this point, so let's set a default
00094     // transmitter given the protocol. The transmitter might change after
00095     // parsing a request and given a return manager to use. This is done in
00096     // build_data_plan.
00097     //
00098     // The reason I moved this from the build_data_plan method is because a
00099     // registered initialization routine might throw an exception and we
00100     // will need to transmit the exception info, which needs a transmitter.
00101     // If an exception happens before this then the exception info is just
00102     // printed to cout (see BESInterface::transmit_data()). -- pcw 09/05/06
00103     string protocol = _dhi->transmit_protocol ;
00104     if( protocol != "HTTP" )
00105     {
00106         BESDEBUG( "bes", "Finding " << BASIC_TRANSMITTER << " transmitter ... " << endl )
00107         _transmitter = BESReturnManager::TheManager()->find_transmitter( BASIC_TRANSMITTER ) ;
00108         if( !_transmitter )
00109         {
00110             string s = (string)"Unable to find transmitter "
00111                        + BASIC_TRANSMITTER ;
00112             throw BESInternalError( s, __FILE__, __LINE__ ) ;
00113         }
00114         BESDEBUG( "bes", "OK" << endl )
00115     }
00116     else
00117     {
00118         BESDEBUG( "bes", "Finding " << HTTP_TRANSMITTER << " transmitter ... " << endl )
00119         _transmitter = BESReturnManager::TheManager()->find_transmitter( HTTP_TRANSMITTER ) ;
00120         if( !_transmitter )
00121         {
00122             string s = (string)"Unable to find transmitter "
00123                        + HTTP_TRANSMITTER ;
00124             throw BESInternalError( s, __FILE__, __LINE__ ) ;
00125         }
00126         BESDEBUG( "bes", "OK" << endl )
00127     }
00128 
00129     BESInterface::initialize() ;
00130 }
00131 
00134 void
00135 BESBasicInterface::validate_data_request()
00136 {
00137     BESInterface::validate_data_request() ;
00138 }
00139 
00144 void
00145 BESBasicInterface::build_data_request_plan()
00146 {
00147     // The derived class build_data_request_plan should be run first to
00148     // parse the incoming request. Once parsed we can determine if there is
00149     // a return command
00150 
00151     // The default _transmitter (either basic or http depending on the
00152     // protocol passed) has been set in initialize. If the parsed command
00153     // sets a RETURN_CMD (a different transmitter) then look it up here. If
00154     // it's set but not found then this is an error. If it's not set then
00155     // just use the defaults.
00156     if( _dhi->data[RETURN_CMD] != "" )
00157     {
00158         BESDEBUG( "bes", "Finding transmitter: " << _dhi->data[RETURN_CMD] << " ...  " << endl )
00159         _transmitter = BESReturnManager::TheManager()->find_transmitter( _dhi->data[RETURN_CMD] ) ;
00160         if( !_transmitter )
00161         {
00162             string s = (string)"Unable to find transmitter "
00163                        + _dhi->data[RETURN_CMD] ;
00164             throw BESSyntaxUserError( s, __FILE__, __LINE__ ) ;
00165         }
00166         BESDEBUG( "bes", "OK" << endl )
00167     }
00168 
00169     if( BESDebug::IsSet( "bes" ) ) _dhi->dump( *(BESDebug::GetStrm()) ) ;
00170 }
00171 
00179 void
00180 BESBasicInterface::execute_data_request_plan()
00181 {
00182     if( BESLog::TheLog()->is_verbose() )
00183     {
00184         *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00185                              << " from " << _dhi->data[REQUEST_FROM]
00186                              << " [" << _dhi->data[DATA_REQUEST] << "] executing"
00187                              << endl ;
00188     }
00189     BESInterface::execute_data_request_plan() ;
00190 }
00191 
00199 void
00200 BESBasicInterface::invoke_aggregation()
00201 {
00202     if( _dhi->data[AGG_CMD] == "" )
00203     {
00204         if( BESLog::TheLog()->is_verbose() )
00205         {
00206             *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00207                                  << " from " << _dhi->data[REQUEST_FROM]
00208                                  << " [" << _dhi->data[DATA_REQUEST] << "]"
00209                                  << " not aggregating, command empty"
00210                                  << endl ;
00211         }
00212     }
00213     else
00214     {
00215         BESAggregationServer *agg = BESAggFactory::TheFactory()->find_handler( _dhi->data[AGG_HANDLER] ) ;
00216         if( !agg )
00217         {
00218             if( BESLog::TheLog()->is_verbose() )
00219             {
00220                 *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00221                                      << " from " << _dhi->data[REQUEST_FROM]
00222                                      << " [" << _dhi->data[DATA_REQUEST] << "]"
00223                                      << " not aggregating, no handler"
00224                                      << endl ;
00225             }
00226         }
00227         else
00228         {
00229             if( BESLog::TheLog()->is_verbose() )
00230             {
00231                 *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00232                                      << " from " << _dhi->data[REQUEST_FROM]
00233                                      << " [" << _dhi->data[DATA_REQUEST]
00234                                      << "] aggregating" << endl ;
00235             }
00236         }
00237     }
00238     BESInterface::invoke_aggregation() ;
00239 }
00240 
00248 void
00249 BESBasicInterface::transmit_data()
00250 {
00251     if( BESLog::TheLog()->is_verbose() )
00252     {
00253         *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00254                              << " from " << _dhi->data[REQUEST_FROM]
00255                              << " [" << _dhi->data[DATA_REQUEST]
00256                              << "] transmitting" << endl ;
00257     }
00258     BESInterface::transmit_data() ;
00259 } 
00260 
00265 void
00266 BESBasicInterface::log_status()
00267 {
00268     string result = "completed" ;
00269     if( _dhi->error_info )
00270         result = "failed" ;
00271     if( BESLog::TheLog()->is_verbose() )
00272     {
00273         *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00274                              << " from " << _dhi->data[REQUEST_FROM]
00275                              << " [" << _dhi->data[DATA_REQUEST] << "] "
00276                              << result << endl ;
00277     }
00278 }
00279 
00288 void
00289 BESBasicInterface::clean()
00290 {
00291     BESInterface::clean() ;
00292     if( BESLog::TheLog()->is_verbose() )
00293     {
00294         *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00295                              << " from " << _dhi->data[REQUEST_FROM]
00296                              << " [" << _dhi->data[DATA_REQUEST] << "] cleaning"
00297                              << endl ;
00298     }
00299 }
00300 
00307 void
00308 BESBasicInterface::dump( ostream &strm ) const
00309 {
00310     strm << BESIndent::LMarg << "BESBasicInterface::dump - ("
00311                              << (void *)this << ")" << endl ;
00312     BESIndent::Indent() ;
00313     BESInterface::dump( strm ) ;
00314     BESIndent::UnIndent() ;
00315 
00316 
00317 }
00318 

Generated on Sat Aug 22 06:04:33 2009 for OPeNDAP Hyrax Back End Server (BES) by  doxygen 1.6.0