You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Mikko Tiihonen <mi...@nitorcreations.com> on 2012/10/22 21:37:16 UTC

Websocket push patch

Hi,

Few weeks ago I created a patch that provides a way to push convert external events into wicket events that allow components to update themselves and push the 
results back to all browsers that have open websocket connection to the wicket application.

I put the first version of the patch here https://issues.apache.org/jira/browse/WICKET-4832

The API is pretty simple:

Pass reference to wicket application to any non-wicket thread:
   WebSocketPushBroadcaster pusher = new WebSocketPushBroadcaster();
   pusher.broadcastAll(applicationRef, new ExternalSourcePush("pass relevant data to components"));
where
   static class ExternalSourcePush implements IWebSocketPushMessage { ... }

The wicket components that have active websocket connections will then receive a normal wicket websocket event:

   public void onEvent(IEvent<?> event) {
     if (event.getPayload() instanceof WebSocketPushPayload) {
       WebSocketPushPayload wsEvent = (WebSocketPushPayload) event.getPayload();
       ExternalSourcePush data = (ExternalSourcePush) wsEvent.getMessage()

       label.setDefaultModelObject(data.message);
       wsEvent.getHandler().add(label);
     }
   }

Alternatively you can just pass a specific wicket websocket ConnectionMessage and use that as a context to send the events to.

---
TODO items:

1) I was trying to add a Class<? extends Page> filter to the broadcastAll first so that I could get only the relevant websocket connections from the registry 
and not all pages need to be touched. In that case websocket registry would need to be updated to keep track of also page classes, not just their pageId, or is 
there a easy way to map from pageId to page class?
Or do you think the broadcastAll that loops through all active websocket connections is not too heavy?

2) testing framework

-Mikko

Re: Websocket push patch

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Thank you for the pull requests !

Unfortunately I cannot apply them.
GitHub says that he example cannot be merged for some reason. I solved this
by cloning your repo and copying it. So far so good.

The next problem is with the Wicket module - we do not have any rights on
the GitHub project (it is just a mirror of Apache Git repo) so there is no
way to merge it there. I've downloaded the patch from
https://github.com/apache/wicket/pull/24.patch but it doesn't apply
cleanly. It seems you used an old version of Wicket. Can you rebase it
against current master ?



On Wed, Dec 5, 2012 at 5:41 PM, Juha Syrjälä <ju...@gmail.com> wrote:

> Hi,
>
> I made an example application for this feature:
>
> https://github.com/martin-g/**blogs/pull/3<https://github.com/martin-g/blogs/pull/3>
>
> The latest version of the feature is here: https://github.com/apache/**
> wicket/pull/24 <https://github.com/apache/wicket/pull/24>
>
> --
> Juha Syrjälä
>
>
>
> On 10/24/2012 11:28 AM, Martin Grigorov wrote:
>
>> Hi,
>>
>> Thanks for your patch!
>> I'll take a look at it soon.
>> In the meantime do you want to provide a Pull Request with a demo of
>> the new functionality for
>> https://github.com/martin-g/**blogs/tree/master/wicket6-**
>> native-websockets<https://github.com/martin-g/blogs/tree/master/wicket6-native-websockets>
>> ?
>>
>> On Mon, Oct 22, 2012 at 10:37 PM, Mikko Tiihonen
>> <mikko.tiihonen@**nitorcreations.com <mi...@nitorcreations.com>>
>> wrote:
>>
>>> Hi,
>>>
>>> Few weeks ago I created a patch that provides a way to push convert
>>> external
>>> events into wicket events that allow components to update themselves and
>>> push the results back to all browsers that have open websocket
>>> connection to
>>> the wicket application.
>>>
>>> I put the first version of the patch here
>>> https://issues.apache.org/**jira/browse/WICKET-4832<https://issues.apache.org/jira/browse/WICKET-4832>
>>>
>>> The API is pretty simple:
>>>
>>> Pass reference to wicket application to any non-wicket thread:
>>>    WebSocketPushBroadcaster pusher = new WebSocketPushBroadcaster();
>>>    pusher.broadcastAll(**applicationRef, new ExternalSourcePush("pass
>>> relevant
>>> data to components"));
>>> where
>>>    static class ExternalSourcePush implements IWebSocketPushMessage {
>>> ... }
>>>
>>> The wicket components that have active websocket connections will then
>>> receive a normal wicket websocket event:
>>>
>>>    public void onEvent(IEvent<?> event) {
>>>      if (event.getPayload() instanceof WebSocketPushPayload) {
>>>        WebSocketPushPayload wsEvent = (WebSocketPushPayload)
>>> event.getPayload();
>>>        ExternalSourcePush data = (ExternalSourcePush)
>>> wsEvent.getMessage()
>>>
>>>        label.setDefaultModelObject(**data.message);
>>>        wsEvent.getHandler().add(**label);
>>>      }
>>>    }
>>>
>>> Alternatively you can just pass a specific wicket websocket
>>> ConnectionMessage and use that as a context to send the events to.
>>>
>>> ---
>>> TODO items:
>>>
>>> 1) I was trying to add a Class<? extends Page> filter to the broadcastAll
>>> first so that I could get only the relevant websocket connections from
>>> the
>>> registry and not all pages need to be touched. In that case websocket
>>> registry would need to be updated to keep track of also page classes, not
>>> just their pageId, or is there a easy way to map from pageId to page
>>> class?
>>> Or do you think the broadcastAll that loops through all active websocket
>>> connections is not too heavy?
>>>
>>> 2) testing framework
>>>
>>> -Mikko
>>>
>>
>>
>>
>>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: Websocket push patch

Posted by Juha Syrjälä <ju...@gmail.com>.
Hi,

I made an example application for this feature:

https://github.com/martin-g/blogs/pull/3

The latest version of the feature is here: 
https://github.com/apache/wicket/pull/24

-- 
Juha Syrjälä


On 10/24/2012 11:28 AM, Martin Grigorov wrote:
> Hi,
>
> Thanks for your patch!
> I'll take a look at it soon.
> In the meantime do you want to provide a Pull Request with a demo of
> the new functionality for
> https://github.com/martin-g/blogs/tree/master/wicket6-native-websockets
> ?
>
> On Mon, Oct 22, 2012 at 10:37 PM, Mikko Tiihonen
> <mi...@nitorcreations.com> wrote:
>> Hi,
>>
>> Few weeks ago I created a patch that provides a way to push convert external
>> events into wicket events that allow components to update themselves and
>> push the results back to all browsers that have open websocket connection to
>> the wicket application.
>>
>> I put the first version of the patch here
>> https://issues.apache.org/jira/browse/WICKET-4832
>>
>> The API is pretty simple:
>>
>> Pass reference to wicket application to any non-wicket thread:
>>    WebSocketPushBroadcaster pusher = new WebSocketPushBroadcaster();
>>    pusher.broadcastAll(applicationRef, new ExternalSourcePush("pass relevant
>> data to components"));
>> where
>>    static class ExternalSourcePush implements IWebSocketPushMessage { ... }
>>
>> The wicket components that have active websocket connections will then
>> receive a normal wicket websocket event:
>>
>>    public void onEvent(IEvent<?> event) {
>>      if (event.getPayload() instanceof WebSocketPushPayload) {
>>        WebSocketPushPayload wsEvent = (WebSocketPushPayload)
>> event.getPayload();
>>        ExternalSourcePush data = (ExternalSourcePush) wsEvent.getMessage()
>>
>>        label.setDefaultModelObject(data.message);
>>        wsEvent.getHandler().add(label);
>>      }
>>    }
>>
>> Alternatively you can just pass a specific wicket websocket
>> ConnectionMessage and use that as a context to send the events to.
>>
>> ---
>> TODO items:
>>
>> 1) I was trying to add a Class<? extends Page> filter to the broadcastAll
>> first so that I could get only the relevant websocket connections from the
>> registry and not all pages need to be touched. In that case websocket
>> registry would need to be updated to keep track of also page classes, not
>> just their pageId, or is there a easy way to map from pageId to page class?
>> Or do you think the broadcastAll that loops through all active websocket
>> connections is not too heavy?
>>
>> 2) testing framework
>>
>> -Mikko
>
>
>


Re: Websocket push patch

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Thanks for your patch!
I'll take a look at it soon.
In the meantime do you want to provide a Pull Request with a demo of
the new functionality for
https://github.com/martin-g/blogs/tree/master/wicket6-native-websockets
?

On Mon, Oct 22, 2012 at 10:37 PM, Mikko Tiihonen
<mi...@nitorcreations.com> wrote:
> Hi,
>
> Few weeks ago I created a patch that provides a way to push convert external
> events into wicket events that allow components to update themselves and
> push the results back to all browsers that have open websocket connection to
> the wicket application.
>
> I put the first version of the patch here
> https://issues.apache.org/jira/browse/WICKET-4832
>
> The API is pretty simple:
>
> Pass reference to wicket application to any non-wicket thread:
>   WebSocketPushBroadcaster pusher = new WebSocketPushBroadcaster();
>   pusher.broadcastAll(applicationRef, new ExternalSourcePush("pass relevant
> data to components"));
> where
>   static class ExternalSourcePush implements IWebSocketPushMessage { ... }
>
> The wicket components that have active websocket connections will then
> receive a normal wicket websocket event:
>
>   public void onEvent(IEvent<?> event) {
>     if (event.getPayload() instanceof WebSocketPushPayload) {
>       WebSocketPushPayload wsEvent = (WebSocketPushPayload)
> event.getPayload();
>       ExternalSourcePush data = (ExternalSourcePush) wsEvent.getMessage()
>
>       label.setDefaultModelObject(data.message);
>       wsEvent.getHandler().add(label);
>     }
>   }
>
> Alternatively you can just pass a specific wicket websocket
> ConnectionMessage and use that as a context to send the events to.
>
> ---
> TODO items:
>
> 1) I was trying to add a Class<? extends Page> filter to the broadcastAll
> first so that I could get only the relevant websocket connections from the
> registry and not all pages need to be touched. In that case websocket
> registry would need to be updated to keep track of also page classes, not
> just their pageId, or is there a easy way to map from pageId to page class?
> Or do you think the broadcastAll that loops through all active websocket
> connections is not too heavy?
>
> 2) testing framework
>
> -Mikko



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com