137 | 137 | After definitions for construction und destruction (the first also setting a timer to 5 seconds), we come to the ''startup'' method. |
138 | 138 | The ''startup'' method (lines 20 ff.) is called from the !StartupWrapper, jolting the operation of the ping pong service. Here, we first create an AribaModule object, serving as our port to ''Ariba'' (line 33). Then, we give our network instance a specific name (being ''spovnet'' in the example), before we collect some configurational parameters (lines 46-56). Those parameters are defined in the config file, they serve e.g. in giving IP adresses and port numbers to ariba instances. In line 56, we start ''Ariba''. Also, we need a ''Node'' object, reflecting our application running over ''Ariba'' (more than one could possibly be using one Ariba). This is created in line 62 and the bound to the ariba object with its specific ServiceID. After this bnind operation, the ''Node'' is able to receive signals and messages from ''Ariba''. After this, we start the node object and either initiate or join the network instance (depending on the role of the actual node, wich could be initiator or joiner). |
143 | | 60 void PingPong::shutdown(){ |
144 | | 61 logging_info( "shutting down PingPong service ..." ); |
145 | | 62 |
146 | | 63 overlay->unbind( this, PingPong::PINGPONG_ID ); |
147 | | 64 Timer::stop(); |
148 | | 65 |
149 | | 66 if( !startping ) abstraction->destroySpoVNet( context ); |
150 | | 67 else abstraction->leaveSpoVNet( context ); |
151 | | 68 |
152 | | 69 logging_info( "PingPong service shut down" ); |
153 | | 70 } |
154 | | }}} |
155 | | |
156 | | To shut a service down after its usage, every service provides a method ''shutdown'' which is automatically called upon finishing (lines 60-70). In here, we unbind the service, stop any timers (mentioned later) and finally leave leave or destroy the SpoVNet instance, depending on the specific node's role. |
157 | | |
| 143 | 01 void PingPong::shutdown() { |
| 144 | 02 |
| 145 | 03 logging_info( "pingpong service starting shutdown sequence ..." ); |
| 146 | 04 |
| 147 | 05 // stop timer |
| 148 | 06 Timer::stop(); |
| 149 | 07 |
| 150 | 08 // leave spovnet |
| 151 | 09 node->leave(); |
| 152 | 10 |
| 153 | 11 // unbind communication and node listener |
| 154 | 12 node->unbind( this ); /*NodeListener*/ |
| 155 | 13 node->unbind( this, PingPong::PINGPONG_SERVICEID ); /*CommunicationListener*/ |
| 156 | 14 |
| 157 | 15 // stop the ariba module |
| 158 | 16 ariba->stop(); |
| 159 | 17 |
| 160 | 18 // delete node and ariba module |
| 161 | 19 delete node; |
| 162 | 20 delete ariba; |
| 163 | 21 |
| 164 | 22 // now we are completely shut down |
| 165 | 23 logging_info( "pingpong service shut down" ); |
| 166 | 24} |
| 167 | }}} |
| 168 | |
| 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. |