Event Notification in C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #1

    Event Notification in C++

    Hi there,

    I am working on a distributed service detection project, written in C/C++
    Platform is Linux. Each system under network has mysql database for general storage. If first node queries to second node and if request gets satisfied, First node will put these results in its local cache table. So whenever same query gets fired on first node, it would just return the results from its cache table.
    The problem arises when second node changes his database table.
    First node should get notified that its cache has got dirty.
    This is the classical problem of "Dirty Cache Detection".
    One solution would be, Each node will store the information of the system whom did he serve. And whenever local database changes, it'd send the message to the other system, notifying that you can clear your cache.
    There will be thousands of nodes and above solution will increase the network traffic terribly.
    Give me some algorithm or any existing library for this event notification(mu st be efficient).

    NOTE:My English is weak. So let me know if you don't understand the problem.

    Regards,
    Ash
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    This is the classic Observer design pattern.

    This pattern is based on a Notify/Publish scenario where an object (your second node) has to notify interested observers (your first node) that the state of the database has changed. The first node then publishes new results by doing a re-query.

    If there are many observers, then a Mediator becomes involved where the Mediator is notified and it int turn notitifes all of the observers.

    Check out Design Patterns by Eric Gamma, et al. ISBN0-201-63361-2 page 293. All the examples are in C++.

    Comment

    Working...