#include <AlarmHandler.h>
Public Types | |
enum | ALARM_LEVEL { OKAY, WARNING, ERROR, FATAL } |
Public Member Functions | |
AlarmHandler () | |
AlarmHandler (xdaq::Application *) | |
void | clearAllAlarms () |
Logger & | getLogger () const |
virtual void | notifySentinel (const ALARM_LEVEL, xcept::Exception &) |
virtual void | raiseAlarm (const std::string name, const ALARM_LEVEL, xcept::Exception &) |
virtual void | revokeAlarm (const std::string name) |
virtual | ~AlarmHandler () |
Private Member Functions | |
bool | raiseAlarm (const std::string name, const std::string level, xcept::Exception &) |
Private Attributes | |
xdata::InfoSpace * | alarmInfoSpace_ |
xdaq::Application * | app_ |
boost::mutex | mutex_ |
Helper class to handle sentinel alarming
Definition at line 27 of file AlarmHandler.h.
stor::AlarmHandler::AlarmHandler | ( | ) | [inline] |
Definition at line 34 of file AlarmHandler.h.
{};
stor::AlarmHandler::AlarmHandler | ( | xdaq::Application * | app | ) | [explicit] |
Definition at line 16 of file AlarmHandler.cc.
References alarmInfoSpace_, and Exception.
: app_(app) { try { alarmInfoSpace_ = xdata::getInfoSpaceFactory()->get("urn:xdaq-sentinel:alarms"); } catch(xdata::exception::Exception) { // sentinel is not available alarmInfoSpace_ = 0; } }
virtual stor::AlarmHandler::~AlarmHandler | ( | ) | [inline, virtual] |
Definition at line 37 of file AlarmHandler.h.
{};
void stor::AlarmHandler::clearAllAlarms | ( | ) |
Revokes all sentinel alarms
Definition at line 164 of file AlarmHandler.cc.
References alarmInfoSpace_, app_, and mutex_.
{ if (!alarmInfoSpace_) return; boost::mutex::scoped_lock sl( mutex_ ); typedef std::map<std::string, xdata::Serializable*, std::less<std::string> > alarmList; alarmList alarms = alarmInfoSpace_->match(".*"); for (alarmList::const_iterator it = alarms.begin(), itEnd = alarms.end(); it != itEnd; ++it) { sentinel::utils::Alarm* alarm = dynamic_cast<sentinel::utils::Alarm*>(it->second); alarmInfoSpace_->fireItemRevoked(it->first, app_); delete alarm; } }
Logger& stor::AlarmHandler::getLogger | ( | ) | const [inline] |
Return the application logger
Definition at line 71 of file AlarmHandler.h.
References app_.
{ return app_->getApplicationLogger(); }
void stor::AlarmHandler::notifySentinel | ( | const ALARM_LEVEL | level, |
xcept::Exception & | exception | ||
) | [virtual] |
Notifies the sentinel
Definition at line 71 of file AlarmHandler.cc.
References dqm::qstatus::ERROR, and dqm::qstatus::WARNING.
{ switch( level ) { case OKAY: LOG4CPLUS_INFO(app_->getApplicationLogger(), xcept::stdformat_exception_history(exception)); break; case WARNING: LOG4CPLUS_WARN(app_->getApplicationLogger(), xcept::stdformat_exception_history(exception)); app_->notifyQualified("warning", exception); break; case ERROR: LOG4CPLUS_ERROR(app_->getApplicationLogger(), xcept::stdformat_exception_history(exception)); app_->notifyQualified("error", exception); break; case FATAL: LOG4CPLUS_FATAL(app_->getApplicationLogger(), xcept::stdformat_exception_history(exception)); app_->notifyQualified("fatal", exception); break; default: LOG4CPLUS_WARN(app_->getApplicationLogger(), "Unknown alarm level received for exception: " << xcept::stdformat_exception_history(exception)); } }
void stor::AlarmHandler::raiseAlarm | ( | const std::string | name, |
const ALARM_LEVEL | level, | ||
xcept::Exception & | exception | ||
) | [virtual] |
Raises a sentinel alarm
Definition at line 32 of file AlarmHandler.cc.
References dqm::qstatus::ERROR, and dqm::qstatus::WARNING.
{ switch( level ) { case OKAY: revokeAlarm(name); break; case WARNING: if ( raiseAlarm(name, "warning", exception) ) LOG4CPLUS_WARN(app_->getApplicationLogger(), "Raising warning alarm " << name << ": " << exception.message()); break; case ERROR: if ( raiseAlarm(name, "error", exception) ) LOG4CPLUS_ERROR(app_->getApplicationLogger(), "Raising error alarm " << name << ": " << exception.message()); break; case FATAL: if ( raiseAlarm(name, "fatal", exception) ) LOG4CPLUS_FATAL(app_->getApplicationLogger(), "Raising fatal alarm " << name << ": " << exception.message()); break; default: LOG4CPLUS_WARN(app_->getApplicationLogger(), "Unknown alarm level received for " << name << ": " << exception.message()); } }
bool stor::AlarmHandler::raiseAlarm | ( | const std::string | name, |
const std::string | level, | ||
xcept::Exception & | exception | ||
) | [private] |
Definition at line 111 of file AlarmHandler.cc.
References Exception.
{ if (!alarmInfoSpace_) return false; boost::mutex::scoped_lock sl( mutex_ ); sentinel::utils::Alarm *alarm = new sentinel::utils::Alarm(level, exception, app_); try { alarmInfoSpace_->fireItemAvailable(name, alarm); } catch(xdata::exception::Exception) { // Alarm is already set or sentinel not available return false; } return true; }
void stor::AlarmHandler::revokeAlarm | ( | const std::string | name | ) | [virtual] |
Revokes a sentinel alarm
Definition at line 138 of file AlarmHandler.cc.
References Exception, and AlCaRecoCosmics_cfg::name.
{ if (!alarmInfoSpace_) return; boost::mutex::scoped_lock sl( mutex_ ); sentinel::utils::Alarm *alarm; try { alarm = dynamic_cast<sentinel::utils::Alarm*>( alarmInfoSpace_->find( name ) ); } catch(xdata::exception::Exception) { // Alarm has not been set or sentinel not available return; } LOG4CPLUS_INFO(app_->getApplicationLogger(), "Revoking alarm " << name); alarmInfoSpace_->fireItemRevoked(name, app_); delete alarm; }
xdata::InfoSpace* stor::AlarmHandler::alarmInfoSpace_ [private] |
Definition at line 85 of file AlarmHandler.h.
Referenced by AlarmHandler(), and clearAllAlarms().
xdaq::Application* stor::AlarmHandler::app_ [private] |
Definition at line 84 of file AlarmHandler.h.
Referenced by clearAllAlarms(), and getLogger().
boost::mutex stor::AlarmHandler::mutex_ [mutable, private] |
Definition at line 87 of file AlarmHandler.h.
Referenced by clearAllAlarms().