In the very near future, will break event handling into a separate class. However, in order to get a simple test (BasicTest) running, I have added code to ComponentCreator which will add an ActionListener to the JButton that is created. The ActionListener's job is then to push a Click type ChangeEvent onto the Component's event queue (Lines 101 - 105). So far so good. BasicTest adds a jSeamless Event listener to listen for Click type ChangeEvent s. So in theory, when the button is clicked, the action listener will enque the Click type ChangeEvent, which will be handled by BasicTest's event listener.
Well, first off, it should be a standard Event, not a ChangeEvent. ChangeEvents only occur when something is changing and a click doesn't change anything. The fact that there is a "Event" that is instantiatable is a different concept than what you might be used to with Swing.
When adding the button to the Application, Add events are pushed onto the event queue. They are processed in Component.processEvent. Because eventHandlers is a Queue, as a handler to notify is searched for on line 1578 of Component, the listener for the Click type ChangeEvent is popped out of the queue. So as a side-effect of attempting to find a handler for the add event, our ChangeEvent listener is taken out of the queue. Now, when I click on the button, the Click type ChangeEvent is queued, but no listeners exist to react to it.
When using enhanced for-loop as you see in line 1578 of Component it does a peek, not a poll, so that does not remove the handlers, just iterates over them.
So, my question is, why are we using a Queue for EventHandler s? Am I correctly queuing the Click ChangeEvent? What am I missing here?
I use ConcurrentLinkedQueue when possible instead of a standard List or Collection because it is 100% thread-safe and non-blocking. You never have to worry about synchronized blocks, ConcurrentModificationExceptions, or index out of range issues. It is also incredibly fast for most operations.
Coming from my Swing background, I have a predisposition to think of Listeners as things that stick around until they are unregistered. Any light you can shed on this would be appreciated.
This is true in jSeamless as well, but all listeners are wrapped around with an EventHandler that defines additional information about how to process events on an individual listener.