void
ConnectionPool::setup_broker_connection(const HostList &brokers) throw(KafkaError) {
    boost::mutex::scoped_lock lock(m_data->m_sockets_mutex);
    for(HostList::const_iterator host = brokers.begin(); host != brokers.end(); ++host ){
        std::ostringstream sout;
        sout<<(*host)->port();
        boost::asio::ip::tcp::resolver::query query(
                                (*host)->host(), sout.str().c_str(),
                                boost::asio::ip::resolver_query_base::numeric_service);
        boost::asio::ip::tcp::resolver resolver(m_io_service);
        boost::system::error_code error = boost::asio::error::host_not_found;
        for(boost::asio::ip::tcp::resolver::iterator i = resolver.resolve(query);
                            i != boost::asio::ip::tcp::resolver::iterator(); ++i) {
            boost::asio::ip::tcp::endpoint end = *i;
            m_meta_channel = Socket( new boost::asio::ip::tcp::socket(m_io_service) );
            m_meta_channel->connect(end, error);
            if(!error) {
                //std::cout<<"BROKER CONNECTION INITIALIZED"<<std::endl;
                break; //Connection established
            }
        }
        if(error) {
            //TODO::Error?
        }
    }
}
Esempio n. 2
0
static void remove_from_list(HostList& hl, HostPList& ht) 
{
    for(HostList_iter hl_iter = hl.begin(); hl_iter != hl.end(); hl_iter++) 
	if(contains(ht, &(*hl_iter)))
	    hl_iter->unused = true;
	
}
Esempio n. 3
0
/**
 * 保持中のホストリストからグループリストを取得する。
 * @retval グループリスト
 */
std::vector<GroupItem>
HostList::GetGroupList()
{
	IPMSG_FUNC_ENTER( "std::vector<GroupItem> HostList::GetGroupList()" );
	std::vector<GroupItem> ret;
	HostList tmp = *this;
	tmp.sort( new IpMsgGetGroupListComparator() );
	std::string hostName = "", encodingName = "";
	for( std::vector<HostListItem>::iterator ixhost = tmp.begin(); ixhost != tmp.end(); ixhost++ ) {
		if ( hostName != ixhost->HostName() || encodingName != ixhost->EncodingName() ){
			GroupItem item;
			item.setGroupName( ixhost->GroupName() );
			item.setEncodingName( ixhost->EncodingName() );
			ret.push_back( item );
		}
		hostName = ixhost->HostName();
		encodingName = ixhost->EncodingName();
	}
	IPMSG_FUNC_RETURN( ret );
}