CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

stor::EventServerProxy< RegInfo > Class Template Reference

#include <EventServerProxy.h>

List of all members.

Public Member Functions

 EventServerProxy (edm::ParameterSet const &)
bool getEventMaybe (CurlInterface::Content &data)
template<>
void getInitMsg (CurlInterface::Content &data)
void getInitMsg (CurlInterface::Content &data)
void getOneEvent (CurlInterface::Content &data)
void reconnect ()
virtual ~EventServerProxy ()

Private Member Functions

void checkEvent (CurlInterface::Content &)
void checkInitMsg (CurlInterface::Content &)
template<>
void checkInitMsg (CurlInterface::Content &data)
void connectToEventServer (CurlInterface::Content &)
bool extractConsumerId (CurlInterface::Content &)
template<>
void getInitMsgFromEventServer (CurlInterface::Content &data)
void getInitMsgFromEventServer (CurlInterface::Content &)
void getOneEventFromEventServer (CurlInterface::Content &)
void registerWithEventServer ()

Private Attributes

bool alreadySaidHalted_
bool alreadySaidWaiting_
unsigned int consumerId_
unsigned int failedAttemptsToGetData_
const stor::utils::Duration_t minEventRequestInterval_
stor::utils::TimePoint_t nextRequestTime_
const RegInfo regInfo_

Detailed Description

template<typename RegInfo>
class stor::EventServerProxy< RegInfo >

Retrieve events from the Storage Manager event server.

This does uses a HTTP get using the CURL library. The Storage Manager event server responses with a binary octet-stream. The init message is also obtained through a HTTP get.

Author:
mommsen
Revision:
1.8
Date:
2012/04/23 08:41:27

Definition at line 36 of file EventServerProxy.h.


Constructor & Destructor Documentation

template<typename RegInfo>
stor::EventServerProxy< RegInfo >::EventServerProxy ( edm::ParameterSet const &  )
template<typename RegInfo>
virtual stor::EventServerProxy< RegInfo >::~EventServerProxy ( ) [inline, virtual]

Definition at line 42 of file EventServerProxy.h.

{};

Member Function Documentation

template<typename RegInfo>
void stor::EventServerProxy< RegInfo >::checkEvent ( CurlInterface::Content ) [private]
template<typename RegInfo>
void stor::EventServerProxy< RegInfo >::checkInitMsg ( CurlInterface::Content ) [private]
template<>
void stor::EventServerProxy< EventConsumerRegistrationInfo >::checkInitMsg ( CurlInterface::Content data) [inline, private]

Definition at line 144 of file EventServerProxy.h.

References HeaderView::code(), hcal_timing_source_file_cfg::dump, Exception, and Header::INIT.

  {
    try {
      HeaderView hdrView(&data[0]);
      if (hdrView.code() != Header::INIT) {
        throw cms::Exception("EventServerProxy", "readHeader");
      }
    }
    catch (cms::Exception excpt) {
      const unsigned int MAX_DUMP_LENGTH = 1000;
      std::ostringstream dump;
      dump << "========================================" << std::endl;
      dump << "* Exception decoding the getregdata response from the event server!" << std::endl;
      if (data.size() <= MAX_DUMP_LENGTH)
      {
        dump << "* Here is the raw text that was returned:" << std::endl;
        dump << std::string(&data[0]) << std::endl;
      }
      else
      {
        dump << "* Here are the first " << MAX_DUMP_LENGTH <<
          " characters of the raw text that was returned:" << std::endl;
        dump << std::string(&data[0], MAX_DUMP_LENGTH) << std::endl;
      }
      dump << "========================================" << std::endl;
      edm::LogError("EventServerProxy") << dump.str();
      throw excpt;
    }
  }
template<typename RegInfo>
void stor::EventServerProxy< RegInfo >::connectToEventServer ( CurlInterface::Content ) [private]
template<typename RegInfo>
bool stor::EventServerProxy< RegInfo >::extractConsumerId ( CurlInterface::Content ) [private]
template<typename RegInfo>
bool stor::EventServerProxy< RegInfo >::getEventMaybe ( CurlInterface::Content data)

Try to get one event from the event server. If succesful, returns true.

template<typename RegInfo>
void stor::EventServerProxy< RegInfo >::getInitMsg ( CurlInterface::Content data)

Get the init message from the the event server.

Referenced by edm::EventStreamHttpReader::readHeader().

template<>
void stor::EventServerProxy< EventConsumerRegistrationInfo >::getInitMsg ( CurlInterface::Content data) [inline]

Definition at line 177 of file EventServerProxy.h.

References Exception, and edm::shutdown_flag.

  {
    do
    {
      data.clear();
      getInitMsgFromEventServer(data);
    }
    while ( !edm::shutdown_flag && data.empty() );
    
    if (edm::shutdown_flag) {
      throw cms::Exception("readHeader","EventServerProxy")
        << "The header read was aborted by a shutdown request.\n";
    }
    
    checkInitMsg(data);
  }
template<typename RegInfo>
void stor::EventServerProxy< RegInfo >::getInitMsgFromEventServer ( CurlInterface::Content ) [private]
template<>
void stor::EventServerProxy< EventConsumerRegistrationInfo >::getInitMsgFromEventServer ( CurlInterface::Content data) [inline, private]

Definition at line 95 of file EventServerProxy.h.

References lhef::cc::convert(), data, stor::CurlInterface::getInterface(), Header::HEADER_REQUEST, OtherMessageBuilder::msgBody(), query::result, OtherMessageBuilder::size(), stor::utils::sleep(), and OtherMessageBuilder::startAddress().

  {
    // build the header request message to send to the event server
    char msgBuff[100];
    OtherMessageBuilder requestMessage(
      &msgBuff[0],
      Header::HEADER_REQUEST,
      sizeof(char_uint32)
    );
    uint8 *bodyPtr = requestMessage.msgBody();
    convert(consumerId_, bodyPtr);
    
    // send the header request
    stor::CurlInterfacePtr curl = stor::CurlInterface::getInterface();
    CURLcode result = curl->postBinaryMessage(
      regInfo_.sourceURL() + "/getregdata",
      requestMessage.startAddress(),
      requestMessage.size(),
      data
    );
    
    if ( result != CURLE_OK )
    {
      // connection failed: try to reconnect
      edm::LogError("EventServerProxy") << "curl perform failed for header:"
        << std::string(&data[0]) << std::endl
        << ". Trying to reconnect.";
      data.clear();
      registerWithEventServer();
    }
    
    if( data.empty() )
    {
      if(!alreadySaidWaiting_) {
        edm::LogInfo("EventServerProxy") << "...waiting for header from event server...";
        alreadySaidWaiting_ = true;
      }
      // sleep for desired amount of time
      ::sleep(regInfo_.headerRetryInterval());
    }
    else
    {
      alreadySaidWaiting_ = false;
    }
  }
template<typename RegInfo>
void stor::EventServerProxy< RegInfo >::getOneEvent ( CurlInterface::Content data)

Get one event from the event server.

Referenced by edm::EventStreamHttpReader::read(), and edm::DQMHttpSource::readOneEvent().

template<typename RegInfo>
void stor::EventServerProxy< RegInfo >::getOneEventFromEventServer ( CurlInterface::Content ) [private]
template<typename RegInfo>
void stor::EventServerProxy< RegInfo >::reconnect ( )

Reconnect to the event server

template<typename RegInfo>
void stor::EventServerProxy< RegInfo >::registerWithEventServer ( ) [private]

Member Data Documentation

template<typename RegInfo>
bool stor::EventServerProxy< RegInfo >::alreadySaidHalted_ [private]

Definition at line 81 of file EventServerProxy.h.

template<typename RegInfo>
bool stor::EventServerProxy< RegInfo >::alreadySaidWaiting_ [private]

Definition at line 82 of file EventServerProxy.h.

template<typename RegInfo>
unsigned int stor::EventServerProxy< RegInfo >::consumerId_ [private]

Definition at line 77 of file EventServerProxy.h.

template<typename RegInfo>
unsigned int stor::EventServerProxy< RegInfo >::failedAttemptsToGetData_ [private]

Definition at line 83 of file EventServerProxy.h.

template<typename RegInfo>
const stor::utils::Duration_t stor::EventServerProxy< RegInfo >::minEventRequestInterval_ [private]

Definition at line 79 of file EventServerProxy.h.

template<typename RegInfo>
stor::utils::TimePoint_t stor::EventServerProxy< RegInfo >::nextRequestTime_ [private]

Definition at line 78 of file EventServerProxy.h.

template<typename RegInfo>
const RegInfo stor::EventServerProxy< RegInfo >::regInfo_ [private]

Definition at line 76 of file EventServerProxy.h.