DatabaseServer::DatabaseServer(RoleConfig roleconfig) : Role(roleconfig), m_control_channel(control_channel.get_rval(roleconfig)), m_min_id(min_id.get_rval(roleconfig)), m_max_id(max_id.get_rval(roleconfig)), m_broadcast(broadcast_updates.get_rval(roleconfig)) { ConfigNode generate = dbserver_config.get_child_node(generate_config, roleconfig); ConfigNode backend = dbserver_config.get_child_node(db_backend_config, roleconfig); m_db_backend = DBBackendFactory::singleton().instantiate_backend( db_backend_type.get_rval(backend), backend, min_id.get_rval(generate), max_id.get_rval(generate)); // Initialize DatabaseServer log stringstream log_title; log_title << "Database(" << m_control_channel << ")"; m_log = new LogCategory("db", log_title.str()); set_con_name(log_title.str()); // Check to see the backend was instantiated if(!m_db_backend) { m_log->fatal() << "No database backend of type '" << db_backend_type.get_rval(backend) << "' exists." << endl; astron_shutdown(1); } // Listen on control channel subscribe_channel(m_control_channel); subscribe_channel(BCHAN_DBSERVERS); }
ClientAgent::ClientAgent(RoleConfig roleconfig) : Role(roleconfig), m_net_acceptor(nullptr), m_server_version(server_version.get_rval(roleconfig)) { stringstream ss; ss << "Client Agent (" << bind_addr.get_rval(roleconfig) << ")"; m_log = std::unique_ptr<LogCategory>(new LogCategory("clientagent", ss.str())); // We need to get the client type... ConfigNode client = clientagent_config.get_child_node(ca_client_config, roleconfig); m_client_type = ca_client_type.get_rval(client); // ... and also the channel range ... ConfigNode channels = clientagent_config.get_child_node(channels_config, roleconfig); m_ct = ChannelTracker(min_channel.get_rval(channels), max_channel.get_rval(channels)); // ... then store a copy of the client config. m_clientconfig = clientagent_config.get_child_node(ca_client_config, roleconfig); // Calculate the DC hash const uint32_t config_hash = override_hash.get_rval(roleconfig); if(config_hash > 0x0) { m_hash = config_hash; } else { m_hash = dclass::legacy_hash(g_dcf); } // Load tuning parameters. ConfigNode tuning = clientagent_config.get_child_node(tuning_config, roleconfig); m_interest_timeout = interest_timeout.get_rval(tuning); TcpAcceptorCallback callback = std::bind(&ClientAgent::handle_tcp, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4); AcceptorErrorCallback err_callback = std::bind(&ClientAgent::handle_error, this, std::placeholders::_1); m_net_acceptor = std::unique_ptr<TcpAcceptor>(new TcpAcceptor(callback, err_callback)); m_net_acceptor->set_haproxy_mode(behind_haproxy.get_rval(m_roleconfig)); // Begin listening for new Clients m_net_acceptor->bind(bind_addr.get_rval(m_roleconfig), 7198); m_net_acceptor->start(); }
ClientAgent::ClientAgent(RoleConfig roleconfig) : Role(roleconfig), m_acceptor(NULL), m_server_version(server_version.get_rval(roleconfig)) { stringstream ss; ss << "Client Agent (" << bind_addr.get_rval(roleconfig) << ")"; m_log = new LogCategory("clientagent", ss.str()); // We need to get the client type... ConfigNode client = clientagent_config.get_child_node(ca_client_config, roleconfig); m_client_type = ca_client_type.get_rval(client); // ... and also the channel range ... ConfigNode channels = clientagent_config.get_child_node(channels_config, roleconfig); m_ct = ChannelTracker(min_channel.get_rval(channels), max_channel.get_rval(channels)); // ... then store a copy of the client config. m_clientconfig = clientagent_config.get_child_node(ca_client_config, roleconfig); // Calculate the DC hash const uint32_t config_hash = override_hash.get_rval(roleconfig); if(config_hash > 0x0) { m_hash = config_hash; } else { m_hash = dclass::legacy_hash(g_dcf); } //Initialize the network string str_ip = bind_addr.get_rval(m_roleconfig); string str_port = str_ip.substr(str_ip.find(':', 0) + 1, string::npos); str_ip = str_ip.substr(0, str_ip.find(':', 0)); tcp::resolver resolver(io_service); tcp::resolver::query query(str_ip, str_port); tcp::resolver::iterator it = resolver.resolve(query); m_acceptor = new tcp::acceptor(io_service, *it, true); start_accept(); }
DBStateServer::DBStateServer(RoleConfig roleconfig) : StateServer(roleconfig), m_db_channel(database_channel.get_rval(m_roleconfig)), m_next_context(0) { ConfigNode ranges = dbss_config.get_child_node(ranges_config, roleconfig); for(const auto& it : ranges) { channel_t min = range_min.get_rval(it); channel_t max = range_max.get_rval(it); subscribe_range(min, max); } std::stringstream name; name << "DBSS(Database: " << m_db_channel << ")"; m_log = std::unique_ptr<LogCategory>(new LogCategory("dbss", name.str())); set_con_name(name.str()); }
DBStateServer::DBStateServer(RoleConfig roleconfig) : StateServer(roleconfig), m_db_channel(database_channel.get_rval(m_roleconfig)), m_next_context(0) { ConfigNode ranges = dbss_config.get_child_node(ranges_config, roleconfig); for(auto it = ranges.begin(); it != ranges.end(); ++it) { channel_t min = range_min.get_rval(*it); channel_t max = range_max.get_rval(*it); MessageDirector::singleton.subscribe_range(this, min, max); } std::stringstream name; name << "DBSS(Database: " << m_db_channel << ")"; m_log = new LogCategory("dbss", name.str()); set_con_name(name.str()); }