Changes between Version 31 and Version 32 of Documentation/Tutorial/PingPong
- Timestamp:
- Apr 28, 2009, 4:49:09 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Documentation/Tutorial/PingPong
v31 v32 169 169 To shut a service down after its usage, every service provides a method ''shutdown'' which is automatically called upon finishing. In here, we stop the timer, leave the instance, unbind all bindings and finally stop the node and ''Ariba''. Don't forget to delete yopur objects to prevent from memory leaks. 170 170 171 {{{172 80 void PingPong::onNodeJoin( const NodeID& nodeid, const SpoVNetID& spovnetid ){173 81174 82 if( !startping ){175 83176 84 logging_info( "establishing link to node " << nodeid.toString() );177 85 const LinkID link = overlay->establishLink( nodeid, PingPong::PINGPONG_ID );178 86179 87 logging_info( "adding node to registered nodes in pingpong: " << nodeid.toString() );180 88 remoteNodes.insert( make_pair(nodeid,link) );181 89182 90 Timer::setInterval( 2000 );183 91 Timer::start();184 92 }185 93 }186 }}}187 188 171 So far, the node is up and running, created or joined a SpoVNet instance. As very node starts a timer as soon as it has joined, we now inspect what happens when the timer is triggered. 189 172 … … 221 204 }}} 222 205 223 Everytime the timer 'fires', ''eventFunction'' is called on a node. In this example, every node sends a message to every node that is part of the network at this point in time. To accomplish this, it iterates through all established links (line 20-23), builts a message for every link and finally sends the message using the Base Overlay in ''Ariba'' (line 123). Sending messages is done by passing the message object to ''Ariba'', together with the target link to use. . We will now take a short look at how such a message is composed in the ping pong example.206 Everytime the timer 'fires', ''eventFunction'' is called on a node. In this example, every node sends a message to every node that is part of the network at this point in time. To accomplish this, it builds a message (line 15) and iterates through all neighboring nodes (line 20-23). To each of this nodes, it sends the message. Sending messages is simply done by passing the message object to ''Ariba'', together with the target node ID. . We will now take a short look at how such a message is composed in the ping pong example. 224 207 225 208 {{{ … … 277 260 278 261 Node leaves in our case only lead to deletion of links we had stored before, for we don't need them anymore (line 102). 262 263 {{{ 264 80 void PingPong::onNodeJoin( const NodeID& nodeid, const SpoVNetID& spovnetid ){ 265 81 266 82 if( !startping ){ 267 83 268 84 logging_info( "establishing link to node " << nodeid.toString() ); 269 85 const LinkID link = overlay->establishLink( nodeid, PingPong::PINGPONG_ID ); 270 86 271 87 logging_info( "adding node to registered nodes in pingpong: " << nodeid.toString() ); 272 88 remoteNodes.insert( make_pair(nodeid,link) ); 273 89 274 90 Timer::setInterval( 2000 ); 275 91 Timer::start(); 276 92 } 277 93 } 278 }}}