Application architecture question

102 views
Skip to first unread message

Timea

unread,
Jun 11, 2013, 9:34:35 AM6/11/13
to google-we...@googlegroups.com
Hei there,

I have a general wondering about the architecture of GWT applications.
Currently we have a web application which grabs some data from the database, makes some calculations and then displays it on the GUI.
Sounds easy cheesy still because GWT works with RPC and eventbus I can't really know when each event is ready to fill the GUI completely.
My ideea that I saw in some projects is to define States of the application(using state pattern). In the initial state I wait for the data from the DB and I wait also for the calculations and when my data model is complete I change the state and display it on the GUI.
Do you think this is a valid way or are GWT applications designed differently? I want to also mention that it is a mobile application so response time is also important.

Cheers,
Timea

Joseph Lust

unread,
Jun 11, 2013, 1:39:02 PM6/11/13
to google-we...@googlegroups.com
Timea,

Not sure what the implementation trouble is:

  1. User makes some interaction (i.e. button click) so you fire and event (i.e. ShowSomethingEvent(id))
  2. A listener sees the event and fires and RPC with the data from the event
  3. On returning the async handler for the call you just made updates the UI with the desired values.
You could add an extra event (i.e. SomethingDataReadyEvent) and fire it when the RPC comes back, but it is the same as steps 1 & 2.

Sincerely,
Joseph

Jens

unread,
Jun 11, 2013, 3:24:24 PM6/11/13
to google-we...@googlegroups.com
If you have multiple independent RPC requests and you want to update the GUI after all these RPC requests are done, then you could check a number of boolean variables (one per RPC request) to see if all of them are true ( = RPC is done), e.g.

server.rpcMethod1(Callback() {
  onSuccess() {
    rpcMethod1Done = true;
    maybeUpdateUI();
  }
});

server.rpcMethod2(Callback() {
  onSuccess() {
    rpcMethod2Done = true;
    maybeUpdateUI();
  }
});

private void maybeUpdateUI() {
  if(allRpcDone()) { //check all boolean variables.
    //... update ui
  }
}

But as you have a mobile application its probably better to batch your requests, so that your app, as a rule of thumb, only does one request per screen. This saves a lot of network overhead. In this case a command pattern might be useful, as it allows for easy BatchCommands, e.g.

BatchCommand bc = new BatchCommand();
bc.add(new DoStuff1Command());
bc.add(new DoStuff2Command());

server.execute(bc, Calllback<BatchCommandResult>() {
  //in onSuccess iterate over all individual command results contained in the BatchCommandResult and finally update your UI.
}



Otherwise, if you just have a single RPC request somewhere and you make that RPC request because of an event you probably just need an XyzLoadedEvent, e.g. ScoreBoardRequestEvent and ScoreBoardLoadedEvent, just like Joseph has already explained.

-- J.

Juan Pablo Gardella

unread,
Jun 11, 2013, 3:29:13 PM6/11/13
to google-we...@googlegroups.com
To use BatchCommand you can use gwt-dispatch.


2013/6/11 Jens <jens.ne...@gmail.com>

-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Alfredo Quiroga

unread,
Jun 11, 2013, 3:30:36 PM6/11/13
to google-we...@googlegroups.com, google-we...@googlegroups.com
And since the last sentence of the original post if my memory serves me right mentions is for a mobile app I would strongly recommend not to use gwt-rpc in this case.

Sent from my iPhone
--

Imy

unread,
Jun 11, 2013, 3:41:43 PM6/11/13
to google-we...@googlegroups.com
Thank you for the so far posted replies.

For maybe further clarify:
  • I need this to work only at the start up of the application, to wait till my model has all the data and then update the GUI.
  • I am using mGWT, still the architecture is GWT related. I am using mGWT to get it cross-device and GWT to get it cross-browser. (of course with its limitations)
  • let's say I can control the RPC calls, what do I do with all the events? Can I control my application only to move on when all the necessary events are done? 

@Alfredo - if not gwt-rpc, then what?

Cheers,
Timea

--
You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/eZLxnlpixL0/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.

Alfredo Quiroga-Villamil

unread,
Jun 11, 2013, 4:14:23 PM6/11/13
to google-we...@googlegroups.com
@Timea RequestBuilder or RequestFactory.

If you plan on creating a Mobile "Web" App you can def. look at GWT-RPC. However, if you plan on packaging the App to "Native" as part of the dual mode (web-"native"), then avoid if possible GWT-RPC.

Regards,

Alfredo
Alfredo Quiroga-Villamil

AOL/Yahoo/Gmail/MSN IM:  lawwton

Joseph Lust

unread,
Jun 11, 2013, 5:08:31 PM6/11/13
to google-we...@googlegroups.com
Timea,

If you've got the case of waiting on a multiplicity of RPC's to complete before continuing, something like Jen's suggestion is best. I've implemented it before with a multibit latches.

However you get into the issue of syncing. For example, let's say you have N RPC calls for a given event. If someone triggers this event twice quickly (say event A and B) that fires off 2*N RPC calls. You've no guarantee that all of A's RPC's will return before all of B's RPC's. What if B completed first? Should A update the UI too or is it no longer relevant? Essentially all of the thread locking goodness you normally avoid with JS creeps in. That is why when I've run into this pattern, I usually try to find a way to do the grouping server side rather than UI side if possible.

If you must, make sure you:
  • Block all UI interaction until the event's RPC's return
  • Unblock the UI on error for any RPC
  • Have a way to cancel all inflight RPC's if you need to cancel the update from the UI
  • Make sure you reset you latches on error/success
Sincerely,
Joseph

Imy

unread,
Jun 18, 2013, 7:03:00 AM6/18/13
to google-we...@googlegroups.com
Follow up on this matter.

Thanks you for all the inputs, we considered them and decided what is the best solution for our project.

In the end we created an object that models the data that we receive from the database and from the after calculations.
In the HomeActivity class of the HomeView (in case of mGWT) or Presenter class (case of GWT) we create an onModelLoaded event handler which fills the model. We also implemented states and the readyState is only activated when the model is loaded. From the model we also fill the GUI afterwards.

Cheers,
Timea


--
Reply all
Reply to author
Forward
0 new messages