By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,942 Members | 1,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,942 IT Pros & Developers. It's quick & easy.

Event Notification in C++

Expert 100+
P: 542
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(must be efficient).

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

Nov 18 '08 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,197
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++.
Nov 18 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.