registration and declarations to the hub in a single atomic operation
m.b.taylor at bristol.ac.uk
Wed Feb 18 09:22:25 PST 2009
On Thu, 12 Feb 2009, Yohann Granet wrote:
> 2) a concurrency-safe way to declare a client to the hub!!!
> indeed, in case of several clients registering them and declaring metadatas
> and subscriptions to the hub problems can occur.
> see my example:
> I work on an package manager intended to launch applications and retransmit
> them previously received messages. So my package manager have to listen and
> react to hub events (subscriptions, unregister events) in order to maintain
> its own running clients list, to know if there is already registered client
> having subscribed for every asked MType.
> When launching several applications simultaneously, if a thread (in the hub)
> in charge of registration and declarations for a new client "A" is interrupted
> by another thread in charge of doing the same for a client "B", then when the
> subscription event caused by "B" is launched my package manager refreshes its
> client list and then gets incomplete informations concerning application "A"
> (empty metadatas and/or subscriptions).
I don't think I follow what's going on in this scenario.
However, since you mentioned in an earlier mail that you were using JSAMP:
you can use JSAMP's facilities to keep track of clients and their
attributes for you. If you are working from a GUI context, the easiest
way is to use the ListModel returned by GuiHubConnector.getClientListModel().
The content of this model represents the currently registered
clients along with their declared subscriptions and metadata, and
it is updated as registration, unregistration, and subscription/metadata
notifications are received from the hub.
You can add a listener to this model which will be notified every time
its contents change. Of course if you interrogate the list at any given
point you stand a chance of getting data which is out of date in
the sense that an update notification sent by the hub has not yet
been processed to update the client list, but used properly it's not
what I would call "unsafe".
>From a non-Swing context, the Map returned by HubConnector.getClientMap()
does much the same job, though you can't register listeners on it in
the same way.
Mark Taylor Astronomical Programmer Physics, Bristol University, UK
m.b.taylor at bris.ac.uk +44-117-928-8776 http://www.star.bris.ac.uk/~mbt/
More information about the apps-samp