Internal data exchange through threads with topic
Unsolved
General and Desktop
-
Hello,
I work on an application connect to a server for receive a data feed and transfert to right Widget/Data model for display it on screen.
I wonder if i do it right or not, please evaluate me or give me a better solution.Problem:
- ~500,000feed available on server which can be selected through an subscribing system
- One client actually process ~1000 feed at the same time
- One feed publish rate is around 3ms
- There is three event loop (thread)
- Socket managing and unserialization
- Background data processing
- Main (UI) event loop
- Some QWidget aggregate several feed, some widget only read one feed
My solution:
The main idea is to introduce a FeedProxy class instance per feed
-
Subscribe:
- QWidget retrieve from a singleton invokable FeedRegister the needed FeedProxy
- QWidget connect to
SIGNAL(onNewFeed(FeedType))
on each proxy - FeedProxy catch the connect through connectNotify and send feed subscription to server if not yet done
-
Unsubscribe:
- QWidget disconnect from FeedHandler
- FeedHandler catch disconnectNotify and unsubscribe from server when isSignalConnected return false.
- Emit an
SIGNAL(isOrphan)
to FeedRegister for release FeedHandler instance
-
Good points:
- Use of
INVOKE
andsignal/slot
permit to work in differents threads
- Use of
-
Bad points:
- Maybe need a garbage collector for unconnected feeds
- Use of
connectNotify
,disconnectNotify
andisSignalConnected
violates the object-oriented principle of modularity.
-
Hi,
What about doing the subscription related stuff in your proxy ? Basically two methods:
FeedProxy::subscribe(YouCoolClass *)
FeedProxy::unsubscribe(YouCoolClass *)
No need for any special detection and you know exactly where things are happening.