00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00093
00094
00095
00096
00097
00098
00099
00100
00101
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
00131
00132
00133
00134
00135
00136
00137
00138
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