Пример #1
0
bool CAgentThread::connect_center()
{
    if (parse_domainname_or_iplist())
    {
        CCenterHost* host = choose_center_host();
        if (NULL == host)
        {
            AGENT_LOG_FATAL("No hosts chosen.\n");
            return false;
        }

        _connector.set_peer_ip(host->get_ip().c_str());
        _connector.set_peer_port(host->get_port());
        
        try
        {
            _connector.timed_connect();
            enable_connector_write();
            host->reset_reconn_times();
            AGENT_LOG_DEBUG("%s successfully.\n", _connector.to_string().c_str());   
            return true;
        }
        catch (sys::CSyscallException& ex)
        {
            host->inc_reconn_times();
            AGENT_LOG_ERROR("%s failed: %s.\n", _connector.to_string().c_str(), ex.to_string().c_str());
            do_millisleep(_connector.get_connect_timeout_milliseconds());
        }
    }
    
    return false;
}
Пример #2
0
void CObserverThread::run()
{
#if ENABLE_SET_OBSERVER_THREAD_NAME==1 
    sys::CUtil::set_process_name("ob-thread");
#endif // ENABLE_SET_OBSERVER_THREAD_NAME

	while (!is_stop())
	{
        do_millisleep(_observer_context->get_report_frequency_seconds());
		_observer_context->collect();
	}
}
Пример #3
0
	virtual void run()
	{
		// 在这个函数里实现需要池线程干的事
		if (_number_printed++ < 3)
		{
			// 只打印三次,以便观察效率
			printf("thread %u say hello.\n", get_thread_id());
		}

        // do_millisleep是由CPoolThread提供给子类睡眠用的,
        // 可以通过调用wakeup中断睡眠
		do_millisleep(1000);
	}
Пример #4
0
void CPoolThread::CPoolThreadHelper::run()
{
	// wait用于和主线程同步
	do_millisleep(-1);

    if (!is_stop())
    {
        if (_pool_thread->before_run())
        {
            while (!is_stop())
            {
                _pool_thread->run();
            }

            _pool_thread->after_run();
        }
    }
}
Пример #5
0
void CPoolThread::CPoolThreadHelper::millisleep(int milliseconds)
{
    do_millisleep(milliseconds);
}