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     if( BESDebug::IsSet( "bes" ) ) _dhi->dump( *(BESDebug::GetStrm()) ) ;
00153 }
00154 
00162 void
00163 BESBasicInterface::execute_data_request_plan()
00164 {
00165     if( BESLog::TheLog()->is_verbose() )
00166     {
00167         *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00168                              << " from " << _dhi->data[REQUEST_FROM]
00169                              << " [" << _dhi->data[DATA_REQUEST] << "] executing"
00170                              << endl ;
00171     }
00172     BESInterface::execute_data_request_plan() ;
00173 }
00174 
00182 void
00183 BESBasicInterface::invoke_aggregation()
00184 {
00185     if( _dhi->data[AGG_CMD] == "" )
00186     {
00187         if( BESLog::TheLog()->is_verbose() )
00188         {
00189             *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00190                                  << " from " << _dhi->data[REQUEST_FROM]
00191                                  << " [" << _dhi->data[DATA_REQUEST] << "]"
00192                                  << " not aggregating, command empty"
00193                                  << endl ;
00194         }
00195     }
00196     else
00197     {
00198         BESAggregationServer *agg = BESAggFactory::TheFactory()->find_handler( _dhi->data[AGG_HANDLER] ) ;
00199         if( !agg )
00200         {
00201             if( BESLog::TheLog()->is_verbose() )
00202             {
00203                 *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00204                                      << " from " << _dhi->data[REQUEST_FROM]
00205                                      << " [" << _dhi->data[DATA_REQUEST] << "]"
00206                                      << " not aggregating, no handler"
00207                                      << endl ;
00208             }
00209         }
00210         else
00211         {
00212             if( BESLog::TheLog()->is_verbose() )
00213             {
00214                 *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00215                                      << " from " << _dhi->data[REQUEST_FROM]
00216                                      << " [" << _dhi->data[DATA_REQUEST]
00217                                      << "] aggregating" << endl ;
00218             }
00219         }
00220     }
00221     BESInterface::invoke_aggregation() ;
00222 }
00223 
00231 void
00232 BESBasicInterface::transmit_data()
00233 {
00234     if( BESLog::TheLog()->is_verbose() )
00235     {
00236         *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00237                              << " from " << _dhi->data[REQUEST_FROM]
00238                              << " [" << _dhi->data[DATA_REQUEST]
00239                              << "] transmitting" << endl ;
00240     }
00241     BESInterface::transmit_data() ;
00242 } 
00243 
00248 void
00249 BESBasicInterface::log_status()
00250 {
00251     string result = "completed" ;
00252     if( _dhi->error_info )
00253         result = "failed" ;
00254     if( BESLog::TheLog()->is_verbose() )
00255     {
00256         *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00257                              << " from " << _dhi->data[REQUEST_FROM]
00258                              << " [" << _dhi->data[DATA_REQUEST] << "] "
00259                              << result << endl ;
00260     }
00261 }
00262 
00271 void
00272 BESBasicInterface::clean()
00273 {
00274     BESInterface::clean() ;
00275     if( BESLog::TheLog()->is_verbose() )
00276     {
00277         *(BESLog::TheLog()) << _dhi->data[SERVER_PID]
00278                              << " from " << _dhi->data[REQUEST_FROM]
00279                              << " [" << _dhi->data[DATA_REQUEST] << "] cleaning"
00280                              << endl ;
00281     }
00282 }
00283 
00290 void
00291 BESBasicInterface::dump( ostream &strm ) const
00292 {
00293     strm << BESIndent::LMarg << "BESBasicInterface::dump - ("
00294                              << (void *)this << ")" << endl ;
00295     BESIndent::Indent() ;
00296     BESInterface::dump( strm ) ;
00297     BESIndent::UnIndent() ;
00298 
00299 
00300 }
00301 

Generated on Thu Feb 11 09:13:13 2010 for OPeNDAP Hyrax Back End Server (BES) by  doxygen 1.4.7