31 const int NodeAdvertiser::g_initial_interval = 1000;
32 const int NodeAdvertiser::g_maximal_interval = 30 * 1000;
34 NodeAdvertiser::NodeAdvertiser(
int port,
bool verbose,
QObject *parent)
35 :
QObject(parent), m_port(port), m_verbose(verbose),
36 m_resend_timer(new QTimer(this)), m_socket(new QUdpSocket(this))
38 connect(m_resend_timer, SIGNAL(timeout()),
this, SLOT(SendAdvertisement()));
46 void NodeAdvertiser::BackoffTimer()
48 if (m_resend_timer->interval() < g_maximal_interval) {
49 int newInterval = m_resend_timer->interval() * 2;
50 if (newInterval >= g_maximal_interval) {
52 newInterval = g_maximal_interval;
53 m_resend_timer->setSingleShot(
false);
55 m_resend_timer->start(newInterval);
59 void NodeAdvertiser::SendAdvertisement()
62 cout <<
"Trying to find server, time passed since last tick: "
63 << m_resend_timer->interval() <<
"msec." << endl;
66 if (m_exploration ==
"") {
67 datagram =
"Job Application" + QByteArray(
" ") + QByteArray::number(m_server_port);
69 datagram =
"Server Discovery" + QByteArray(
" ")
70 + QByteArray::number(m_task_id) + QByteArray(
" ")
71 + QByteArray::number(m_server_port) + QByteArray(
" ")
72 + QByteArray(m_exploration.c_str());
74 m_socket->writeDatagram(datagram, QHostAddress::Broadcast, m_port);
80 m_resend_timer->stop();
81 m_server_port = serverPort;
83 m_resend_timer->setSingleShot(
true);
84 m_resend_timer->start(g_initial_interval);
89 m_resend_timer->stop();
90 m_server_port = serverPort;
91 m_exploration = exploration;
93 m_resend_timer->setSingleShot(
true);
94 m_resend_timer->start(g_initial_interval);
99 m_resend_timer->stop();
Interface for the NodeAdvertiser.
void Start(int serverPort)
Start finding a server to do work for.
void Stop()
Stop finding a server.
virtual ~NodeAdvertiser()
Destructor.
Namespace for SimPT parameter explorer package.
see the online Qt documentation