Add clock for counters recorder in launcher example
authorEduardo Ramos Testillano <eduardo.ramos.testillano@gmail.com>
Thu, 24 Jul 2014 20:05:11 +0000 (22:05 +0200)
committerEduardo Ramos Testillano <eduardo.ramos.testillano@gmail.com>
Thu, 24 Jul 2014 20:05:11 +0000 (22:05 +0200)
example/diameter/launcher/main.cpp
include/anna/core/core.hpp
source/core/oam/Module.cpp

index 1f5a2e0..af22f85 100644 (file)
@@ -52,6 +52,7 @@
 #include <anna/http/functions.hpp>
 #include <anna/comm/functions.hpp>
 #include <anna/timex/Engine.hpp>
+#include <anna/timex/Clock.hpp>
 #include <anna/diameter/stack/Engine.hpp>
 #include <anna/diameter/codec/Engine.hpp>
 #include <anna/diameter.comm/OamModule.hpp>
@@ -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 <pid>)"; }
+};
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
 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 <pid>)"; }
-};
-*/
-
 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<anna::oam::CounterRecorder*>(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")) {
index 80a7acc..e36d191 100644 (file)
@@ -79,7 +79,6 @@ namespace anna {}
 #include <anna/core/oam/Handler.hpp>
 #include <anna/core/oam/Module.hpp>
 #include <anna/core/oam/Counter.hpp>
-#include <anna/core/oam/CounterManager.hpp>
 #include <anna/core/oam/CounterRecorder.hpp>
 #include <anna/core/oam/CounterScope.hpp>
 #include <anna/core/tracing/Configuration.hpp>
index 99b47c9..d45ba9f 100644 (file)
@@ -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];