Changeset 2473 for sample


Ignore:
Timestamp:
Feb 23, 2009, 2:21:49 PM (16 years ago)
Author:
Christoph Mayer
Message:

-einige fixes im ablauf des neuen interface
-einige fehlende funktionalität implementiert

Location:
sample/pingpong
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sample/pingpong/PingPong.cpp

    r2432 r2473  
    1 
    21#include "PingPong.h"
    32#include "ariba/utility/configuration/Configuration.h"
     
    1110
    1211// logging
    13 use_logging_cpp( PingPong);
     12use_logging_cpp( PingPong );
    1413
    1514// the service id of the ping pong service
    16 ServiceID PingPong::PINGPONG_ID = ServiceID(111);
     15ServiceID PingPong::PINGPONG_ID = ServiceID( 111 );
    1716
    1817// construction
     
    2726void PingPong::startup() {
    2827
     28        logging_info( "starting up PingPong service ... " );
     29
    2930        // create ariba module
    30         logging_info("Creating ariba underlay module ... ");
     31        logging_debug( "creating ariba underlay module ... " );
    3132        ariba = new AribaModule();
    3233
    33         logging_info("Starting up PingPong service ... ");
    34 
    35         // --- get config ---
     34        // get the configuration object
    3635        Configuration& config = Configuration::instance();
    3736
     
    6665        node->start();
    6766
    68         if (!isInitiator) {
    69                 node->join(spovnetName);
    70         } else {
    71                 node->initiate(spovnetName);
    72         }
     67        // initiate or join the spovnet
     68        if (!isInitiator) node->join(spovnetName);
     69        else node->initiate(spovnetName);
    7370
    7471        // bind communication and node listener
    7572        node->bind(this);
    7673        node->bind(this, PingPong::PINGPONG_ID);
    77 
     74       
    7875        // ping pong started up...
    79         logging_info("PingPong started up");
     76        logging_info( "pingpong started up ");
    8077}
    8178
    8279// implementation of the startup interface
    8380void PingPong::shutdown() {
    84         logging_info("PingPong service starting shutdown sequence ...");
     81
     82        logging_info( "pingpong service starting shutdown sequence ..." );
    8583
    8684        // stop timer
    8785        Timer::stop();
    88 
    89         // leave spovnet
    90         node->leave();
    9186
    9287        // unbind listeners
     
    9489        node->unbind( this, PingPong::PINGPONG_ID );
    9590
     91        // leave spovnet
     92        node->leave();
     93
     94        // stop the ariba module
    9695        ariba->stop();
     96
     97        // delete node and ariba module
    9798        delete node;
    9899        delete ariba;
    99100
    100         logging_info("PingPong service shut down!");
     101        // now we are completely shut down
     102        logging_info( "pingpong service shut down" );
    101103}
    102104
    103105// node listener interface
    104106void PingPong::onJoinCompleted( const SpoVNetID& vid ) {
    105         logging_info("PingPong node join completed, spovnetid=" << vid.toString() );
     107        logging_info( "pingpong node join completed, spovnetid=" << vid.toString() );
     108
     109        // start the timer to ping every second
     110        Timer::setInterval( 1000 );
     111        Timer::start();
    106112}
    107113
    108114void PingPong::onJoinFailed( const SpoVNetID& vid ) {
    109         logging_info("PingPong node join failed, spovnetid=" << vid.toString() );
     115        logging_error(" pingpong node join failed, spovnetid=" << vid.toString() );
    110116}
    111117
     
    115121}
    116122
    117 void PingPong::onMessage(Message* msg, const NodeID& remote, const LinkID& lnk =
    118                 LinkID::UNSPECIFIED) {
    119         PingPongMessage* incoming = msg->decapsulate<PingPongMessage> ();
     123void PingPong::onMessage(Message* msg, const NodeID& remote,
     124                const LinkID& lnk = LinkID::UNSPECIFIED) {
    120125
    121         logging_info("received ping message on link " << lnk.toString()
    122                         << " from node with id " << (int) incoming->getid());
     126        PingPongMessage* pingmsg = msg->decapsulate<PingPongMessage> ();
     127
     128        logging_info( "received ping message on link " << lnk.toString()
     129                        << " from node " << remote.toString()
     130                        << ": " << pingmsg->toString() );
    123131}
    124132
    125133// timer event
    126134void PingPong::eventFunction() {
     135       
     136        // we ping all nodes that are known in the overlay structure
     137        // this can be all nodes (OneHop) overlay or just some neighbors
     138        // in case of a Chord or Kademlia structure
     139       
     140        logging_info( "pinging overlay neighbors with ping id " << ++pingId );
     141
     142        PingPongMessage pingmsg( pingId );
     143        node->sendBroadcastMessage( pingmsg, PingPong::PINGPONG_ID );
     144
    127145}
    128146
  • sample/pingpong/PingPong.h

    r2413 r2473  
    44#include "ariba/ariba.h"
    55#include "PingPongMessage.h"
     6#include "ariba/utility/system/StartupInterface.h"
     7#include "ariba/utility/system/Timer.h"
    68
    79using namespace ariba;
    8 
    9 #include "ariba/utility/system/StartupInterface.h"
    10 #include "ariba/utility/system/Timer.h"
    1110using ariba::utility::StartupInterface;
    1211using ariba::utility::Timer;
     
    5554        Node* node;
    5655
    57         // flag, wheter this node is the initiator of this spovnet
     56        // flag, wheter this node initiates or just joins the spovnet
    5857        bool isInitiator;
    5958
     
    6564};
    6665
    67 //ARIBA_SIMULATION_SERVICE(PingPong);
     66// needed for simulation support
     67ARIBA_SIMULATION_SERVICE(PingPong);
    6868
    6969}}} // namespace ariba, application, pingpong
Note: See TracChangeset for help on using the changeset viewer.