From fc8de8185ba4fe0e0fef890fd5f3e58fd2587e12 Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Testillano Date: Thu, 24 Jul 2014 22:05:11 +0200 Subject: [PATCH] Add clock for counters recorder in launcher example --- example/diameter/launcher/main.cpp | 61 ++++++++++++++++++++---------- include/anna/core/core.hpp | 1 - source/core/oam/Module.cpp | 6 +-- 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/example/diameter/launcher/main.cpp b/example/diameter/launcher/main.cpp index 1f5a2e0..af22f85 100644 --- a/example/diameter/launcher/main.cpp +++ b/example/diameter/launcher/main.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -105,6 +106,32 @@ reacting_answers_container G_reactingAnswers2C, G_reactingAnswers2E; +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// COUNTERS RECORD PROCEDURE ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +class MyCounterRecorderClock : public anna::timex::Clock { + public: + MyCounterRecorderClock(const char *clockName, const anna::Millisecond & timeout) : + anna::timex::Clock(clockName, timeout) {;} + //virtual ~MyCounterRecorderClock(); + + virtual bool tick() throw (RuntimeException) { + anna::diameter::comm::OamModule::instantiate().recordCounters(); + anna::diameter::codec::OamModule::instantiate().recordCounters(); + return true; + } +}; + +class MyCounterRecorder : public anna::oam::CounterRecorder { + + // pure virtual definitions: + void open() throw(anna::RuntimeException) {;} + void apply(const anna::oam::Counter& counter) throw(anna::RuntimeException) {;} + void close() throw() {;} + std::string asString() const throw() { return "Physical dump not implemented: see memory accumulations writting context (kill -10 )"; } +}; +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + class MyDiameterEntity : public anna::diameter::comm::Entity { void eventResponse(const anna::diameter::comm::Response&) throw(anna::RuntimeException); @@ -181,18 +208,6 @@ private: void eventBreakConnection(Server* server) throw(); }; - -/* -class MyCounterRecorder : public anna::oam::CounterRecorder { - - // pure virtual definitions: - void open() throw(anna::RuntimeException) {;} - void apply(const anna::oam::Counter& counter) throw(anna::RuntimeException) {;} - void close() throw() {;} - std::string asString() const throw() { return "Physical dump not implemented: see memory accumulations writting context (kill -10 )"; } -}; -*/ - class Launcher : public anna::comm::Application { MyCommunicator *a_communicator; @@ -203,7 +218,8 @@ class Launcher : public anna::comm::Application { bool a_splitLog, a_detailedLog; anna::time::Date a_start_time; anna::timex::Engine* a_timeEngine; - //MyCounterRecorder *a_counterRecorder; + MyCounterRecorder *a_counterRecorder; + MyCounterRecorderClock *a_counterRecorderClock; std::string a_cerPathfile; std::string a_dwrPathfile; @@ -904,7 +920,8 @@ Launcher::Launcher() : anna::comm::Application("launcher", "DiameterLauncher", " a_splitLog = false; a_detailedLog = false; a_timeEngine = NULL; - //a_counterRecorder = NULL; + a_counterRecorder = NULL; + a_counterRecorderClock = NULL; a_entity = NULL; a_diameterLocalServer = NULL; a_cerPathfile = "cer.xml"; @@ -1178,7 +1195,9 @@ throw(anna::RuntimeException) { // workMode = anna::comm::Communicator::WorkMode::Clone; a_communicator = new MyCommunicator(workMode); a_timeEngine = new anna::timex::Engine((anna::Millisecond)300000, (anna::Millisecond)150); - //a_counterRecorder = new MyCounterRecorder(); + a_counterRecorder = new MyCounterRecorder(); + a_counterRecorderClock = new MyCounterRecorderClock("Counters record procedure clock", Millisecond(10000)); + //a_counterRecorderClock = new MyCounterRecorderClock("Counters record procedure clock", Millisecond(300000)); } void Launcher::run() @@ -1196,6 +1215,7 @@ throw(anna::RuntimeException) { oamDiameterComm.initializeCounterScope(1); // 1000 - 1999 anna::diameter::codec::OamModule & oamDiameterCodec = anna::diameter::codec::OamModule::instantiate(); oamDiameterCodec.initializeCounterScope(2); // 2000 - 2999 + ///////////////// // COMM MODULE // ///////////////// @@ -1293,10 +1313,13 @@ throw(anna::RuntimeException) { oamDiameterCodec.registerCounter(anna::diameter::codec::OamModule::Counter::LevelValidation__FailedRuleForCardinalityMoreThanNeeded, "", 17 /*2017*/); oamDiameterCodec.registerCounter(anna::diameter::codec::OamModule::Counter::LevelValidation__FailedGenericAvpRuleForCardinalityFoundDisregardedItem, "", 18 /*2018*/); oamDiameterCodec.registerCounter(anna::diameter::codec::OamModule::Counter::LevelValidation__FoundDisregardedItemsAndGenericAVPWasNotSpecified, "", 19 /*2019*/); - //anna::oam::CounterManager& cm = anna::oam::CounterManager::instantiate(); - //cm.setEngine(a_timeEngine); - //cm.setRecordPeriod(Millisecond(300000)); - ////cm.setCounterRecorder(static_cast(a_counterRecorder)); ... will be NULL + + ///////////////////////////////// + // Counter recorder associated // + ///////////////////////////////// + oamDiameterComm.setCounterRecorder(a_counterRecorder); + oamDiameterCodec.setCounterRecorder(a_counterRecorder); + a_timeEngine->activate(a_counterRecorderClock); // start clock // Checking command line parameters if (cl.exists("sessionBasedModelsClientSocketSelection")) { diff --git a/include/anna/core/core.hpp b/include/anna/core/core.hpp index 80a7acc..e36d191 100644 --- a/include/anna/core/core.hpp +++ b/include/anna/core/core.hpp @@ -79,7 +79,6 @@ namespace anna {} #include #include #include -#include #include #include #include diff --git a/source/core/oam/Module.cpp b/source/core/oam/Module.cpp index 99b47c9..d45ba9f 100644 --- a/source/core/oam/Module.cpp +++ b/source/core/oam/Module.cpp @@ -527,7 +527,7 @@ void anna::oam::Module::recordCounters() throw(anna::RuntimeException) { LOGMETHOD(anna::TraceMethod tttm("anna::oam::Module", "recordCounters", ANNA_FILE_LOCATION)); if(a_counterRecorder == NULL) - throw RuntimeException("anna::oam::CounterManager has no counter recorder associated", ANNA_FILE_LOCATION); + throw RuntimeException("anna::oam::Module has no counter recorder associated", ANNA_FILE_LOCATION); LOGDEBUG( std::string msg("Recording counters | "); @@ -545,9 +545,7 @@ void anna::oam::Module::recordCounters() throw(anna::RuntimeException) { cscope = scope(scope_it); if(cscope == NULL) continue; - //CounterScope& counterScope(*scope); - //Guard csGuard(counterScope, "oam::CounterScope from oam::CounterManager::record"); - Guard csGuard(cscope, "oam::CounterScope from oam::CounterManager::record"); + Guard csGuard(cscope, "oam::CounterScope from oam::Module::record"); for(register int icounter = 0; icounter < CounterScope::MaxCounter; icounter ++) { Counter* counter = cscope->a_counters [icounter]; -- 2.20.1