You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Daniel Stoch (JIRA)" <ji...@apache.org> on 2014/06/12 17:05:04 UTC

[jira] [Commented] (WICKET-4657) Avoid losing events between instantiation and rendering

    [ https://issues.apache.org/jira/browse/WICKET-4657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14029231#comment-14029231 ] 

Daniel Stoch commented on WICKET-4657:
--------------------------------------

{quote}
Currently the atmosphere module subscribes components to the EventBus just before they are rendered. Naturally events sent on the EventBus before component rendering are lost.
{quote}
I think in some cases even after component is rendered events sent on the EventBus will be lost (component does not receive them). This is because a page can receive events only when AtmosphereResource will be created for it and page will be registered in EventBus: this is done by AtmosphereBehavior.onResourceRequested() call. And this call is not performed during rendering phase. It is done by a different RequestCycle. So until AtmosphereBehavior.onResourceRequested() will be called for page all events will be lost (this page and its components do not receive events). Emond - if I'm right?

My conclusion: it does not help much if components will be registered on instantiation.

Let's talk about a two different scenarios:

1. Event is sent (EventBus.post() call) not from a web application but from another system (eg. backend) or another (non-GUI, non-Wicket) thread.
In this scenario user can enter a page so all initalization code will be executed. If then someone sends an event, before page is registered in EventBus (so page will be instantiated, rendered, detached and event will be send simultaneously in the same time) - this page does not receive this event. And you probably cannot do anything with this. Until AtmosphereBehavior.onResourceRequested() call this page does not exists from EventBus point of view.

2. You want to run a long running task when initializing/rendering page (or some component) and you want to this page (component) receives an event. You probably run this code in another thread to not block a GUI (the best place to run it is probably onInitialize/onBeforeRender method). When task is finished it calls EventBus.post.
This scenario is a very similar to the first one, but here you know a page which runs a task. So you can block running this task (or block EventBus.post call from it) until page will be registered in EventBus. You can check does page is already registered by calling AtmosphereBehavior.getUUID(page): if it is not empty, then page has an AtmosphereResource (ok: this is not a 100% safe check because EventBus.registerPage is called later - so maybe a better metod in EventBus to check if page is registerd will be helpful?). Then: if page is registered you can run task immediately, if not you must wait until page will be registered in EventBus.

I have attached a two simple classes to show a possible solution. PageTasksScheduler should be added to EventBus on initialization: addRegistrationListener(new PageTasksScheduler());
To safely run your task when page is registered in EventBus you can use such call (in component onInitialize/onBeforeRender method):
{code}
PageTasksScheduler.schedule(getPage(), new PageTask() {

  @Override
  public void execute(Page page) {
    // do your task here
  }

});
{code}

> Avoid losing events between instantiation and rendering
> -------------------------------------------------------
>
>                 Key: WICKET-4657
>                 URL: https://issues.apache.org/jira/browse/WICKET-4657
>             Project: Wicket
>          Issue Type: Wish
>          Components: wicket-atmosphere
>    Affects Versions: 6.0.0-beta3
>            Reporter: Pouyan Zaxar
>            Assignee: Emond Papegaaij
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> Currently the atmosphere module subscribes components to the EventBus just before they are rendered. Naturally events sent on the EventBus before component rendering are lost. You cannot even save lost events using a BoradcasterCache (https://github.com/Atmosphere/atmosphere/wiki/Understanding-BroadcasterCache).
> It could be advantageous if components are registered on instantiation (just before initialization) and it can be set if the component wants to receive cached events (e.g. @Subscribe(cache=true)) which have been generated between registering and rendering of the component.



--
This message was sent by Atlassian JIRA
(v6.2#6252)