S
SMMT
Hi,
I'm building and application and I'm trying to build it upon MVC concepts. For this I use quite a
lot listeners and events. I implement the events as classes, the listenrs as interfaces , but the
trigger process is worring me.
I do a code like this
public class EventCreator {
private Collection listeners = new HashSet();
public void addEventListener(EventListener l){
listeners.add(l);
}
private void fireEvent(Event e){
for (Iterator it = listeners.iterator();it.hasNext(){
((EventListener)it.next()).startEvent(e);
}
}
}
I iterate the collection of listeners and call the listenre method for the particular event.
I'm gessing this is not the best way to implement this, so I'm asking for opinions on this.
I wonder if it is a good practice to create a separated thread so I can move to the next listener
without having to wait for the fist to resolve its event handling code. And if so if there are any
API to facilitate the work. Also if storing the listeners in a collection is a good ideia (I see no
other) and if so, witch implementation is the fastest for iterating porposes...
Thank you for your time.
I'm building and application and I'm trying to build it upon MVC concepts. For this I use quite a
lot listeners and events. I implement the events as classes, the listenrs as interfaces , but the
trigger process is worring me.
I do a code like this
public class EventCreator {
private Collection listeners = new HashSet();
public void addEventListener(EventListener l){
listeners.add(l);
}
private void fireEvent(Event e){
for (Iterator it = listeners.iterator();it.hasNext(){
((EventListener)it.next()).startEvent(e);
}
}
}
I iterate the collection of listeners and call the listenre method for the particular event.
I'm gessing this is not the best way to implement this, so I'm asking for opinions on this.
I wonder if it is a good practice to create a separated thread so I can move to the next listener
without having to wait for the fist to resolve its event handling code. And if so if there are any
API to facilitate the work. Also if storing the listeners in a collection is a good ideia (I see no
other) and if so, witch implementation is the fastest for iterating porposes...
Thank you for your time.