1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
11 #include <anna/core/mt/Guard.hpp>
12 #include <anna/core/functions.hpp>
13 #include <anna/core/tracing/Logger.hpp>
15 #include <anna/comm/ClientSocket.hpp>
16 #include <anna/comm/CongestionController.hpp>
18 #include <anna/test/Communicator.hpp>
23 bool test::Communicator::canContinue (const comm::ClientSocket& clientSocket)
24 throw (RuntimeException)
26 Guard guard (this, "test::Communicator::canContinue");
29 a_initTime = anna::functions::millisecond ();
31 if (a_messageCounter > 0)
32 if (a_messageCounter == a_maxMessage && hasRequestedStop () == false) {
37 using namespace anna::comm;
39 CongestionController& congestionController = CongestionController::instantiate ();
43 if (congestionController.getAdvice (clientSocket) == CongestionController::Advice::Discard)
51 void test::Communicator::delay ()
52 throw (RuntimeException)
55 int random = (a_delay > 10) ? (rand () % (a_delay / 10)): 0;
56 int sign = rand () % 2;
61 const Microsecond init = anna::functions::hardwareClock ();
63 anna::functions::sleep (a_delay + (Millisecond)random);
66 Guard guard (this, "test::Communicator::delay");
67 a_avgDelay += anna::functions::hardwareClock () - init;
72 void test::Communicator::terminate ()
75 if (hasRequestedStop () == true)
80 const Millisecond serviceTime = anna::functions::millisecond () - a_initTime;
83 const int workload = (serviceTime == 0) ? 0: a_messageCounter * 1000 / serviceTime;
84 string msg (anna::functions::asText ("Tiempo de servicio: ", (int) serviceTime));
85 msg += anna::functions::asText (" ms | Carga: ", workload);
86 msg += anna::functions::asText (" msg/seg | Mensajes recibidos: ", a_messageCounter);
87 msg += anna::functions::asText (" | Mensajes tratados: ", a_successCounter);
88 Logger::notice (msg, ANNA_FILE_LOCATION);
89 cout << msg << endl << endl;
91 msg = "Retardo medio (us) | ";
92 msg += a_avgDelay.asString ();
93 Logger::notice (msg, ANNA_FILE_LOCATION);
94 cout << msg << endl << endl;
98 //----------------------------------------------------------------------------------------
99 // (1) Dos handlers, uno el ServerSocket y otro el ClientSocket que va a cerran =>
101 //----------------------------------------------------------------------------------------
102 void test::Communicator::eventOverQuota (const comm::ClientSocket&)
107 for (handler_iterator ii = handler_begin (), maxii = handler_end (); ii != maxii; ii ++)
111 Logger::notice (anna::functions::asText ("Handlers: ", counter), ANNA_FILE_LOCATION);
114 if (counter == 2) // (1)