+void comm::Engine::do_initialize() throw(RuntimeException) {
+ LOGMETHOD(anna::TraceMethod tttm("diameter::comm::Engine", "do_initialize", ANNA_FILE_LOCATION));
+ LOGDEBUG(anna::Logger::debug("Nothing special done on component initialization", ANNA_FILE_LOCATION));
+}
+
+void comm::Engine::lazyInitialize() throw(RuntimeException) {
+ LOGMETHOD(anna::TraceMethod tttm("diameter::comm::Engine", "lazyInitialize", ANNA_FILE_LOCATION));
+ anna::app::Component::initialize(); // this will invoke do_initialize
+}
+
+// Not tested yet
+const comm::Response* comm::Engine::sendRealmHost(const Message* message, const std::string &destinationRealm, const std::string &destinationHost) throw(anna::RuntimeException) {
+
+ if (destinationRealm == "")
+ throw anna::RuntimeException("Unable to resolve the destination: empty provided Destination-Realm name", ANNA_FILE_LOCATION);
+
+ // Get the server sessions which fulfill the restrictions:
+ dr_dh_server_sessions_it_t drit = a_dr_dh_server_sessions.find(destinationRealm);
+ if (drit == a_dr_dh_server_sessions.end())
+ throw anna::RuntimeException(anna::functions::asString("Unable to resolve the destination: Destination-Realm name is not registered (no remote clients have been connected to '%s')", destinationRealm.c_str()), ANNA_FILE_LOCATION);
+
+ dh_server_sessions_map_t *dhServerSessions = (dh_server_sessions_map_t *)&(drit->second);
+ // randomize between all server sessions for all hosts:
+ dh_server_sessions_nc_it_t dhit;
+ int hostsN = dhServerSessions->size();
+ if (hostsN == 0) // avoids next division by cero (rand() % 0)
+ throw anna::RuntimeException(anna::functions::asString("Unable to resolve the destination: neither Destination-Host currently connected to Destination-Realm '%s'", destinationRealm.c_str()), ANNA_FILE_LOCATION);
+
+ if (destinationHost == "") {
+ // in this case, randomize the host:
+ dhit = dhServerSessions->begin();
+ int randomHostIndx = rand() % hostsN; // number between 0 and the number of hosts - 1
+ std::advance (dhit, randomHostIndx);
+ }
+ else {
+ dhit = dhServerSessions->find(destinationHost);
+ if (dhit == dhServerSessions->end())
+ throw anna::RuntimeException(anna::functions::asString("Unable to resolve the destination: Destination-Host '%s' is not registered for Destination-Realm '%s'", destinationHost.c_str(), destinationRealm.c_str()), ANNA_FILE_LOCATION);
+ }
+
+ // Now, randomize the available server sessions:
+ server_sessions_vector_t *serverSessions = (server_sessions_vector_t *)&(dhit->second);
+ int serverSessionN = serverSessions->size();
+ if (serverSessionN == 0) { // avoids next division by cero (rand() % 0)
+ std::string aux = "";
+ if (destinationHost != "") { aux = "to Destination-Host '"; aux += destinationHost; aux += "'"; }
+ std::string msg = anna::functions::asString("Unable to resolve the destination: neither server session currently connected%s within Destination-Realm '%s'", aux.c_str(), destinationRealm.c_str());
+ throw anna::RuntimeException(msg, ANNA_FILE_LOCATION);
+ }