On Thursday 26 February 2004 23:40, Berin Loritsch wrote: > Leo Sutic wrote: > >>Not sure. In very 'busy' systems, it becomes a challange to > >>write the 'hub', so that you don't need to synchronize the > >>'addListener' and 'fireEvent' parts, because otherwise it > >>becomes a bottleneck. > > > > Listeners are added and removed comparatively rarely compared > > to the number of fireEvent calls, so a copy-on-write list > > can eliminate much synchronization. > > The GUIApp EventBus is very simple, and it separates out the > need for synchronous and asynchronous events. If you need > synchronous events we use the SwingUtils class to ensure all > those events are fired in one thread. The asynchronous events > can happen in any order. > > It's not hard.
It is harder than you may consider in the first instance... Assuming that your component maintains State and is ThreadSafe, experience tells me that it is NOT possible to fire events within synchronized blocks, which leads to some form of queueing/asynch mechanism. In the case of the EventBus, I agree that one can "throw in more effort" to get these picky details right, once and for all. As for synchronization in firing of events, it boils down to; "Can a Listener recieve an event after it has de-registered?" If the answer is "Yes, that is ok." then synchronization can be minimized. If the answer is "No", one should review that requirement ;o) I am not negative to Events at all. In fact, been depending on them more than most. Niclas --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
