Strategy for saving data project

84 views
Skip to first unread message

Thomas Lefort

unread,
Jul 2, 2012, 3:31:56 AM7/2/12
to google-we...@googlegroups.com
Hi,

I was relying on mayStop to save my user's project when they leave the activity but it seems to work in some cases only, ie when navigating from one activity to another but not when leaving the application or closing the browser... I don't know if it is normal? may be there is "not enough time" to send the last message with all the project's data?

If it is then I need a whole new strategy to make sure data is saved when the user leaves. I would be interested in knowing of any suggestion to solve the issue.
I have planned to save on every change made, but it is quite heavy as there are many frequent updates possible (just moving the map would trigger a save). An optimisation to this would be a combination of a flag for tracking changes and a timer to make periodic saves, eg every minute or so, when the project has changed.
Anyway if anyone has recommendations on how to do this I would be very happy hearing them.

Thanks,

Thomas

Thomas Broyer

unread,
Jul 2, 2012, 4:44:39 AM7/2/12
to google-we...@googlegroups.com

On Monday, July 2, 2012 9:31:56 AM UTC+2, Thomas Lefort wrote:
Hi,

I was relying on mayStop to save my user's project when they leave the activity but it seems to work in some cases only, ie when navigating from one activity to another but not when leaving the application or closing the browser... I don't know if it is normal? may be there is "not enough time" to send the last message with all the project's data?

That's basically what happens yes.
 
If it is then I need a whole new strategy to make sure data is saved when the user leaves. I would be interested in knowing of any suggestion to solve the issue.
I have planned to save on every change made, but it is quite heavy as there are many frequent updates possible (just moving the map would trigger a save). An optimisation to this would be a combination of a flag for tracking changes and a timer to make periodic saves, eg every minute or so, when the project has changed.
Anyway if anyone has recommendations on how to do this I would be very happy hearing them.

Basically: onbeforeunload (which calls mayStop of the activities) exists so that you can tell the user there are unsaved changes and he can cancel the navigation to save them before navigating away again.
With a PlaceChangeRequestEvent you could easily tell an onbeforeunload from an internal navigation (the target place is 'null'), but that isn't exposed to activities (mayStop). I suppose you could workaround this using a PlaceChangeRequestEvent.Handler (or Window.ClosingHandler) and shared state (considering mayStop methods are called first, they would store a flag in the shared state, and the PlaceChangeRequestEvent.Handler would setWarning if the target –place is 'null' –resp. the Window.ClosingHandler would setMessage– when the shared state indicates unsaved changes; but of course, you should also handle the case where the mayStop methods are called *last*); and you'd save data in your activities' onStop(), which are not called onbeforeunload.

Thomas Lefort

unread,
Jul 3, 2012, 4:01:59 AM7/3/12
to google-we...@googlegroups.com
Hi Thomas, thanks for the detailed explanation. I added a window closing handler but I then have the issue of handling mayStop clean up, ie mayStop seems to be called first and does the cleanup, in which case if the user decides to cancel the leave of the activity, the activity is in a cleaned up state and not usable any more, eg no more event handlers.

I will try to add a PlaceChangeRequest.Handler to raise a flag, in the hope that it gets triggered before the mayStop. If it does then I don't need the window closing handler anymore.

I still think this will not cover all cases and the only viable solution is to make (optimised) periodic saves.

Thomas Lefort

unread,
Jul 3, 2012, 4:39:57 AM7/3/12
to google-we...@googlegroups.com
OK, it looks like I might have managed two birds with one stone.

Basically I have a leave flag that I set to true at the creation of the activity. This flag is set to false if there is a PlaceRequestEvent and the new place is not null. In mayStop I first save my workspace and then I check the flag. If the flag is set to false I return a message. If it is set to true then I clean up my activity. The point is I do not need to clean up my activity if I am moving away from the application.
Now I am no MVP guru like you, so if you see a possible flaw in this approach, please let me know.

Thanks again.

Thomas Lefort

unread,
Jul 3, 2012, 11:19:59 AM7/3/12
to google-we...@googlegroups.com
mm  I must come back on what I said... It turns out the PlaceRequestHandler is called after the mayStop (actually during which is plain weird), or at least after the check is done in mayStop, so too late anyway... Is that normal? I have only tested in dev mode and with gwt 2.4.

So I tried something else and implemented it all in PlaceChangeEventRequest and used the setWarning method to popup a message, but the message is never displayed... is that normal too?

Thomas Lefort

unread,
Jul 3, 2012, 12:20:09 PM7/3/12
to google-we...@googlegroups.com
me again... last one I promise.
I ended up using PlaceChangeEventRequest only. The place returned by getNextPlace is not null actually. What I ended up doing is have all my places implement my ow place interface and check if the getNextPlace is of that type. If not, it means we are leaving the page, in which case I use the setWarning (which now works).

Thomas Broyer

unread,
Jul 3, 2012, 12:41:34 PM7/3/12
to google-we...@googlegroups.com


On Tuesday, July 3, 2012 6:20:09 PM UTC+2, Thomas Lefort wrote:
me again... last one I promise.
I ended up using PlaceChangeEventRequest only. The place returned by getNextPlace is not null actually.

Ah yes sorry; I haven't check but from memory it should/could/might be a Place.NOWHERE. 
Reply all
Reply to author
Forward
0 new messages