On Mar 19, 10:57 pm, zggame <zgg...@gmail.com> wrote:
> Hi, I am new to gwt also this event-handle programing model.  I am
> trying to use gwt-presenter 1.1.1.  However, I have a few problems
> with the eventbus.  The eventbus in gwt-presenter is actually realized
> by HandlerManager.   I have a event (EventPage) firing for a page,
> within the handling, it calls method B.  Within metod B, it makes an
> AJAX call for some data, I realize it by calling C function, which
> fire another event (EventData) when it receive the data.  Here is the
> idea
>
> eventbus.addHandler(EventPage.Type, new PageHandler(){
>
> .....
> B();}
>
> --------------------------------------------------------------------------- 
> -----
> eventbus.fire(new EventPage())
> --------------------------------------------------------------------------- 
> -------------
> ......
> B(){
> eventbus.addHandler(EventData.Type, new DataHandler(){
> public void processData(EventData event){
> ...populate page with the data and show it.
> ....});
> C();
> }
>
> --------------------------------------------------------------------------
> C(){
> Ajax_call(new callback(){
> ...
> public void onResponseReceived(Request request,
>                                                 Response response) {
> process data,
> eventbus.fire(new EventData())
>
> }
>
> My eventbus is an singleton in type of HandlerManager.  The problem is
> the definition of B() is only accessible after fire EventPage.  In the
> HandlerManager, there is one variable called firingDepth, it is 0 when
> EventPage fires and 1 after.  When it is larger than 0, it always
> quene the handler registration (addHandler(EventData)) and do not
> register until back to firingDepth==0.  So when C() fires EventData(),
> nothing happens because the handler has not registered yet (it will
> not be until C() exits.)
>
> What is the reason to put such a queue into HandlerManager?

That's because (at firingDepth=0) the code is iterating on the
handlers, so any modification would cause a
ConcurrentModificationException.

> Is there
> anyway to get my problem fixed?  Thank you very much.

Try deferring some of the processing (e.g. Scheduler#scheduleDeferred
or Scheduler#scheduleFinally) so it happens after the events have all
been processed; and more generally treat your event bus as if it were
"asynchronous": don't expect handlers to be called back in the same
"event pump" as the one that fires events.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to