Changes between Version 4 and Version 5 of Documentation/SystemQueue


Ignore:
Timestamp:
Dec 17, 2008, 1:31:34 PM (16 years ago)
Author:
Christoph Mayer
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/SystemQueue

    v4 v5  
    5454}}}
    5555
     56 4. Next, define a new event type for you in your {{{.cpp}}} file. This event will be scheduled into the !SystemQueue:
     57
     58{{{
     59#!cpp
     60SystemEventType MyEventType("My new event type!");
     61}}}
     62
     63 5. In your functionality where you want to synchronized yourself into the main Ariba thread using the !SystemQueue, create the event and insert it. You can attach additional information as a {{{void*}}} to the event that you can extract (here, called {{{myInfo}}}), once in the event handler function:
     64
     65{{{
     66#!cpp 
     67SystemQueue::instance().scheduleEvent(
     68    SystemEvent( this, MyEventType, myInfo));                                   
     69}}}
     70
     71 6. Your event handler will be called asynchronously and in sync with the Ariba main thread. You can also extract the additional information ({{{myInfo}}}) from the event. In this handler function you are the only event that is currently executed. Therefore, you can be sure that no other code in executing in parallel and need not to take any care of threading issues or mutexes.
     72
     73{{{
     74#!cpp   
     75void MyClass::handleSystemEvent(const SystemEvent& event){
     76    MyInfo* info = event.getData<MyInfo>();
     77    ....
     78}
     79}}}
    5680
    5781== Using Blocking Code ==
    5882
     83There may be times, when you wish you could use blocking functionality in your code. This is possible with the help of the {{{BlockingMethod}}} function provided by Ariba. If you would just block, this would stall the complete Ariba architecture. Therefore, if you need to do blocking functionality, two things have to be taken care of:
     84 
     85 * Switching into a new thread where blocking does not affect the main Ariba thread.
     86 * Synchronizing back into the main Ariba thread to perform notification etc. of other components if needed.
     87 
     88Both of these issues are handled by the {{{BlockingMethod}}} class that you can use to easily implement your blocking functionality. To implement blocking functionality, perform the following steps:
    5989
     90 1. Include the header and using directives for the {{{BlockingMethod}}} in your {{{.h}}} file:
     91 
     92{{{
     93#!cpp   
     94#include spovnet/common/BlockingMethod.h"
     95using spovnet::common::BlockingMethod;
     96}}}
     97
     98 2. Derive a new class from {{{BlockingMethod}}}:
     99 
     100{{{
     101#!cpp   
     102class MyClass : public BlockingMethod {
     103}}}
     104
     105 3. Declare the pure virtual function from {{{BlockingMethod}}} in your new class:
     106 
     107{{{
     108#!cpp   
     109virtual void dispatchFunction();
     110virtual void blockingFunction();
     111}}}
     112
     113 4. Finally, implement those two functions in your {{{.cpp}}} file
     114
     115{{{
     116#!cpp
     117void MyClass::dispatchFunction(){
     118   ...
     119}
     120
     121void MyClass::blockingFunction(){
     122   ...
     123}
     124}}}
     125
     126 5. Write the code that blocks execution into the {{{blockingFunction}}}. Implement code that you want to execute once synchronized with the main thread after the blocking into the {{{dispatchFunction}}}. In the {{{dispatchFunction}}} you can safely call other modules etc. from Ariba, because this function will be executed by the !SystemQueue once in sync with the main thread!
     127 
     128 6. From your {{{blockingFunction}}} you can then call {{{MyClass::dispatch}}} to get synchronized back into the main thread once your blocking functionality is done. This will result in {{{MyClass::dispatchFunction}}} being called asynchronously and in sync with the main thread.
     129 
     130The mechanism works by running the blocking functionality automatically in a new thread, therefore not blocking execution of the main Ariba thread. Once you call {{{dispatch}}} an event is generated that results in calling {{{dispatchFunction}}} from the main thread.