Changes between Version 31 and Version 32 of Documentation/Tutorial/PingPong


Ignore:
Timestamp:
Apr 28, 2009, 4:49:09 PM (16 years ago)
Author:
huebsch
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/Tutorial/PingPong

    v31 v32  
    169169To 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.
    170170
    171 {{{
    172 80 void PingPong::onNodeJoin( const NodeID& nodeid, const SpoVNetID& spovnetid ){
    173 81
    174 82      if( !startping ){
    175 83             
    176 84              logging_info( "establishing link to node " << nodeid.toString() );
    177 85              const LinkID link = overlay->establishLink( nodeid, PingPong::PINGPONG_ID );
    178 86
    179 87              logging_info( "adding node to registered nodes in pingpong: " << nodeid.toString() );
    180 88              remoteNodes.insert( make_pair(nodeid,link) );
    181 89             
    182 90              Timer::setInterval( 2000 );
    183 91              Timer::start();
    184 92      }
    185 93 }
    186 }}}
    187 
    188171So 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.
    189172
     
    221204}}}
    222205
    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.
     206Everytime 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.
    224207
    225208{{{
     
    277260
    278261Node 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{{{
     26480 void PingPong::onNodeJoin( const NodeID& nodeid, const SpoVNetID& spovnetid ){
     26581
     26682      if( !startping ){
     26783             
     26884              logging_info( "establishing link to node " << nodeid.toString() );
     26985              const LinkID link = overlay->establishLink( nodeid, PingPong::PINGPONG_ID );
     27086
     27187              logging_info( "adding node to registered nodes in pingpong: " << nodeid.toString() );
     27288              remoteNodes.insert( make_pair(nodeid,link) );
     27389             
     27490              Timer::setInterval( 2000 );
     27591              Timer::start();
     27692      }
     27793 }
     278}}}