You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Timo Rantalaiho <Ti...@ri.fi> on 2008/02/16 11:39:00 UTC

Generic event mechanism (was: loosely coupled panels: react to model object change)

On Tue, 05 Feb 2008, Igor Vaynberg wrote:
> see https://issues.apache.org/jira/browse/WICKET-1312

Thanks for advertising!-)

Have you or other devs had time to look at the patch, and
what do you think?

It would be excellent to already have this in Wicket 1.3
(such as 1.3.2) to be able to use it in most of our real
Wicket projects. Of course now that the patch is there it
can be easily enough ripped to any project.

The code is all Java 1.4 and it doesn't change any existing
code, just builds on it. So it doesn't break any other
functionality, just adds more code to maintain.

Anyway, good even if it makes it to Wicket 1.4. 


A braver version (suggested by my workmate) would hook event
broadcasting directly to Component so that you could just
call broadcast(ListenerClass, Event) anywhere without need
to create the broadcaster object yourself.


Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

Re: Generic event mechanism (was: loosely coupled panels: react to model object change)

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Tue, 25 Mar 2008, Igor Vaynberg wrote:
> +1 for 1.5
> 
> that way early adapters can provide feedback and we have the freedom
> to tweak things

OK, thanks for the comments. 1.5 it will be then, it's
better to keep 1.4 as close as 1.3 as possible.

There were some that wanted to use it in 1.3 / 1.4 already.
They can still copy the first generation patch code to their
own project, as it doesn't change any existing Wicket
classes but just uses them.

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

Re: Generic event mechanism (was: loosely coupled panels: react to model object change)

Posted by Igor Vaynberg <ig...@gmail.com>.
+1 for 1.5

that way early adapters can provide feedback and we have the freedom
to tweak things

-igor


On Tue, Mar 25, 2008 at 3:32 PM, Johan Compagner <jc...@gmail.com> wrote:
> not in 1.3
>  maybe in 1.4 (but i have to look at it more closely, i think this can result
>  in more and more heavier stuff inside componets)
>
>  1.5 is fine then we can let it evolve in the milestone cycles
>
>  johan
>
>  On Tue, Mar 25, 2008 at 11:02 PM, Timo Rantalaiho <Ti...@ri.fi>
>  wrote:
>
>
>
>  > Devs,
>  >
>  > Have you had time to think about this:
>  >
>  >  https://issues.apache.org/jira/browse/WICKET-1312
>  >
>  > Judging from the interest on this list and in issue
>  > comments, there is demand for an event mechanism in Wicket.
>  > Surely it needs to be developed further from this patch, but
>  > you've got to start from somewhere. (And this is essentially
>  > something that we've used for a few months now with good
>  > results.)
>  >
>  > Would it be a good idea to include the current patch version
>  > already in 1.3.3 (and thus in 1.4), or better let it brew
>  > more?
>  >
>  > Pros:
>  >
>  > - some kind of event mechanism available for 1.3 / 1.4 users
>  >
>  > - possibility to gather feedback on the mechanism to be able
>  >  to make a better one in 1.5 without worrying about
>  >  breaking the API
>  >
>  > Cons:
>  >
>  > - more new code to maintain in 1.3 / 1.4 branch
>  >
>  > - if the API gets deprecated and/or changed dramatically in
>  >  1.5, it makes sad users anyway (even if there is
>  >  "permission" to break the API)
>  >
>  > Best wishes,
>  > Timo
>  >
>  > --
>  > Timo Rantalaiho
>  > Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>  >
>

Re: Generic event mechanism (was: loosely coupled panels: react to model object change)

Posted by Johan Compagner <jc...@gmail.com>.
not in 1.3
maybe in 1.4 (but i have to look at it more closely, i think this can result
in more and more heavier stuff inside componets)

1.5 is fine then we can let it evolve in the milestone cycles

johan

On Tue, Mar 25, 2008 at 11:02 PM, Timo Rantalaiho <Ti...@ri.fi>
wrote:

> Devs,
>
> Have you had time to think about this:
>
>  https://issues.apache.org/jira/browse/WICKET-1312
>
> Judging from the interest on this list and in issue
> comments, there is demand for an event mechanism in Wicket.
> Surely it needs to be developed further from this patch, but
> you've got to start from somewhere. (And this is essentially
> something that we've used for a few months now with good
> results.)
>
> Would it be a good idea to include the current patch version
> already in 1.3.3 (and thus in 1.4), or better let it brew
> more?
>
> Pros:
>
> - some kind of event mechanism available for 1.3 / 1.4 users
>
> - possibility to gather feedback on the mechanism to be able
>  to make a better one in 1.5 without worrying about
>  breaking the API
>
> Cons:
>
> - more new code to maintain in 1.3 / 1.4 branch
>
> - if the API gets deprecated and/or changed dramatically in
>  1.5, it makes sad users anyway (even if there is
>  "permission" to break the API)
>
> Best wishes,
> Timo
>
> --
> Timo Rantalaiho
> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>

Re: Generic event mechanism (was: loosely coupled panels: react to model object change)

Posted by Martijn Dashorst <ma...@gmail.com>.
1.3: no API breaks unless absolutely necessary, no new features
(remember: support stops for 1.3!)
1.4: generics only release.
1.5/2.0: new features, api breaks etc.

So 1.5/2.0 according to my recollection of the meanings of our releases.

Martijn

On 3/25/08, Timo Rantalaiho <Ti...@ri.fi> wrote:
> Devs,
>
>  Have you had time to think about this:
>
>
>   https://issues.apache.org/jira/browse/WICKET-1312
>
>
> Judging from the interest on this list and in issue
>  comments, there is demand for an event mechanism in Wicket.
>  Surely it needs to be developed further from this patch, but
>  you've got to start from somewhere. (And this is essentially
>  something that we've used for a few months now with good
>  results.)
>
>  Would it be a good idea to include the current patch version
>  already in 1.3.3 (and thus in 1.4), or better let it brew
>  more?
>
>  Pros:
>
>  - some kind of event mechanism available for 1.3 / 1.4 users
>
>  - possibility to gather feedback on the mechanism to be able
>   to make a better one in 1.5 without worrying about
>   breaking the API
>
>  Cons:
>
>  - more new code to maintain in 1.3 / 1.4 branch
>
>  - if the API gets deprecated and/or changed dramatically in
>   1.5, it makes sad users anyway (even if there is
>   "permission" to break the API)
>
>
>  Best wishes,
>  Timo
>
>  --
>  Timo Rantalaiho
>  Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>


-- 
Buy Wicket in Action: http://manning.com/dashorst
Apache Wicket 1.3.2 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.2

Re: Generic event mechanism (was: loosely coupled panels: react to model object change)

Posted by Timo Rantalaiho <Ti...@ri.fi>.
Devs,

Have you had time to think about this:

  https://issues.apache.org/jira/browse/WICKET-1312

Judging from the interest on this list and in issue
comments, there is demand for an event mechanism in Wicket.
Surely it needs to be developed further from this patch, but
you've got to start from somewhere. (And this is essentially
something that we've used for a few months now with good
results.)

Would it be a good idea to include the current patch version
already in 1.3.3 (and thus in 1.4), or better let it brew
more?

Pros:

- some kind of event mechanism available for 1.3 / 1.4 users

- possibility to gather feedback on the mechanism to be able
  to make a better one in 1.5 without worrying about
  breaking the API

Cons: 

- more new code to maintain in 1.3 / 1.4 branch

- if the API gets deprecated and/or changed dramatically in 
  1.5, it makes sad users anyway (even if there is
  "permission" to break the API)

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

Re: Generic event mechanism (was: loosely coupled panels: react to model object change)

Posted by Timo Rantalaiho <Ti...@ri.fi>.
Hello Frank,

On Fri, 22 Feb 2008, lankvelt wrote:
> http://www.slideshare.net/nielsvk/wicket-plugin-architecture.  This code is
> available under APL and we would like to share as much as possible with the

I finally got around watching the presentation slides 
(unfortunately Slideshare didn't work on my phone :)).
Your project looks interesting and certainly ambitious!

> phases.  In the "request" phase, the message travels up the hierarchy, where
> each plugin calls its parent plugin until one is found that handles it.  A
> message is handled by turning it into a "notification" and sending it to all
> the children.  Messages themselves consist of a description ("browse" or
> "edit") and a model.

The normal Wicket findParent() and visitChildren() seem to
fit nicely in here, right? And you could use marker
interfaces to denote these components. I suppose that the
current version of the WICKET-1312 event mechanism might
work as well, because all events are broadcasted to
everybody interested in the page. However, something more is
needed if you need to have communication between components
on different pages.

> For the event option, I think your patch provides a useful starting point. 

Thanks!-)

> I would suggest to scope events by providing a separate interface that is
> implemented by components that handle events/messages.  When a component
> wants to broadcast, it uses findParent() to get a broadcaster.  This should
> also give the possibility to override the broadcaster with a more
> specialised version, e.g. to also broadcast to disconnected plugins. 

This might bring up problems with unit testing: in a unit
test, you typically want to test a single component as much
isolated as possible, and making a special parent necessary
for changing the broadcaster to a test double sounds
laborious.

However, I just now made a better version of the patch (and
attached it to the issue

  https://issues.apache.org/jira/browse/WICKET-1312?focusedCommentId=12579082#action_12579082

), where the EventBroadcaster instance is being held in
Application, and created in
Application.newEventBroadcaster(). Now it would be trivial
to override newEventBroadcaster() to return a specialised
broadcaster version, for example one that uses findParent()
to get a special component for dispatching the event
further.

> Separately, I don't really understand why the patch insists on separate
> onEvent() methods for different events.  Wouldn't it be easier to just have
> the one, use marker interfaces to indicate what events to receive and check
> the event type with instanceof?

This is a matter of coding style, I suppose. I wanted to
make the code using the framework as clear and simple as
possible, perhaps with the cost of added complexity inside
the framework, and separate onEvent() methods for different
event types feels clearer and more elegant to me than the
instanceof checks. That way, you can see right away from the
signature of the component class which events it handles.

The reflection stuff within the implementation, and the
magic value "onEvent" are a bit ugly, but in practice they
haven't caused a lot of problems in our project (we use
something like the proposed event mechanism).

Our original version actually used a generified
EventReceiver<T extends Event>, and it would have been the
best solution, but unfortunately it doesn't work for
receivers receiving multiple event types because of the
runtime type erasure of the Java generics implementation :(
(You can have onEvent(Event<Foo>) and onEvent(Event<Bar>) in
the same class in C++, but not in Java.)

> In the "model changed" architecture, a shared model represents the state of
> the application in a simple model.  The model is a map that connects
> descriptions to other models.  Components use these referenced models and
> can repaint when they change.  It should be possible to maintain
> composability by using an indirection between the component internal list of
> model names and the descriptions in the map.  This is a very simple
> communication model but, since we haven't used it so far, it is difficult to
> see whether it is sufficiently powerful in general.

I have found sharing models a very powerful technique in a
"smaller scale", when the components sharing the model are
in all senses close to each other. The pull-style feels more
wickety, but unfortunately the Ajax events and the need to
repaint components don't fit well with it. And if the
interconnected components are far away from each other,
sharing the model gets tedious.

I'm not sure if I understand your version of "model changed"
architecture, maybe it has some improvements over plain
common IModels between componenets.

> If there is an interest in the plugin architecture, we can start working on
> the next revision as a wicket extension.  Ideally, this builds on an
> existing event mechanism so I hope you'll excuse any seemingly ridiculous
> requirements of flexibility.

My original intention with the event mechanism is to provide
something very basic and foolproof, but reusable and
extendable. Let's hope that Wicket ends up with something
that delivers this and helps in your project as well!


Thanks for commenting and please comment more, people! Also
viewpoints from the core devs would be great, for example on
the issue of whether it's unthinkable or a practical
possibility to include some version of the event mechanism
already in the 1.3 branch (1.3.3?).

Also note that the mechanism has very little code and builds
on top of plain Wicket 1.3 -- you can easily copy-paste the
code from the patch to your project to try and see how it
feels in practice (it's under Apache license like Wicket).
I'm grateful for all feedback.


Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

Re: Generic event mechanism (was: loosely coupled panels: react to model object change)

Posted by lankvelt <f....@hippo.nl>.
Hi Timo,

at Hippo, we've been working on a plugin architecture based on panels with
messaging capabilities.  There was a presentation at the last Wicket meetup
in Amsterdam, see
http://www.slideshare.net/nielsvk/wicket-plugin-architecture.  This code is
available under APL and we would like to share as much as possible with the
Wicket community.  Currently, we're restructuring the messaging mechanism to
incorporate the lessons learned so far.  

Let me first summarise our current architecture.  In a nutshell, we want to
achieve the benefits listed in WICKET-1312, and then some.  We want to
- construct plugin (component) trees dynamically
- compose applications by reusing existing, configured, (sub)trees

The scope of messages is limited to achieve composability.  The method that
we're using to achieve this is by separating the message processing in two
phases.  In the "request" phase, the message travels up the hierarchy, where
each plugin calls its parent plugin until one is found that handles it.  A
message is handled by turning it into a "notification" and sending it to all
the children.  Messages themselves consist of a description ("browse" or
"edit") and a model.

A number of conclusions we've been able to draw from our experience:
- the number of models that is used by the plugins is relatively small
- the number of different messages (i.e. events), are relatively numerous
- reusable events are at the application level rather than the model level
- publish/subscribe leads to lifecycle management; this does not fit very
well with Wicket
- ajax responses have to be managed when plugins can be dynamically removed

In the application model that we've been using, all communication is through
parent-child _plugin_ relationships.  So even when a plugin is not reachable
from the Page, e.g. because it is in a tab that is not currently selected,
it does receive messages.  This is used to switch tabs; a plugin in a tab
can send a "focus" request to the TabsPlugin in reponse to another event. 
This is basically the distinction between Wicket components and Plugins. 
With plugins, logic can be distributed in a non top-down fashion; child
plugins are not explicitly managed by their parent but instead can use
simple protocols to invert the control hierarchy.

We're now evaluating our model, having gained some experience with Wicket
and the interaction with the communication mechanism.  The two solutions
that we're imagining are closely related to the "event" and the "model
changed" solutions of yourself and Matt Clark, respectively.  There is
obviously a need for an event mechanism in Wicket, independent of a plugin
architecture.  In the construction of the plugin architecture, it would be
nice to be able to reuse this mechanism.

For the event option, I think your patch provides a useful starting point. 
I would suggest to scope events by providing a separate interface that is
implemented by components that handle events/messages.  When a component
wants to broadcast, it uses findParent() to get a broadcaster.  This should
also give the possibility to override the broadcaster with a more
specialised version, e.g. to also broadcast to disconnected plugins. 
Separately, I don't really understand why the patch insists on separate
onEvent() methods for different events.  Wouldn't it be easier to just have
the one, use marker interfaces to indicate what events to receive and check
the event type with instanceof?

In the "model changed" architecture, a shared model represents the state of
the application in a simple model.  The model is a map that connects
descriptions to other models.  Components use these referenced models and
can repaint when they change.  It should be possible to maintain
composability by using an indirection between the component internal list of
model names and the descriptions in the map.  This is a very simple
communication model but, since we haven't used it so far, it is difficult to
see whether it is sufficiently powerful in general.

If there is an interest in the plugin architecture, we can start working on
the next revision as a wicket extension.  Ideally, this builds on an
existing event mechanism so I hope you'll excuse any seemingly ridiculous
requirements of flexibility.

cheers, Frank


Timo Rantalaiho wrote:
> 
> On Tue, 05 Feb 2008, Igor Vaynberg wrote:
>> see https://issues.apache.org/jira/browse/WICKET-1312
> 
> Thanks for advertising!-)
> 
> Have you or other devs had time to look at the patch, and
> what do you think?
> 
> It would be excellent to already have this in Wicket 1.3
> (such as 1.3.2) to be able to use it in most of our real
> Wicket projects. Of course now that the patch is there it
> can be easily enough ripped to any project.
> 
> The code is all Java 1.4 and it doesn't change any existing
> code, just builds on it. So it doesn't break any other
> functionality, just adds more code to maintain.
> 
> Anyway, good even if it makes it to Wicket 1.4. 
> 
> 
> A braver version (suggested by my workmate) would hook event
> broadcasting directly to Component so that you could just
> call broadcast(ListenerClass, Event) anywhere without need
> to create the broadcaster object yourself.
> 
> 
> Best wishes,
> Timo
> 
> -- 
> Timo Rantalaiho           
> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
> 
> 

-- 
View this message in context: http://www.nabble.com/Generic-event-mechanism-%28was%3A-loosely-coupled-panels%3A-react-to-model-object-change%29-tp15516909p15632889.html
Sent from the Wicket - Dev mailing list archive at Nabble.com.


Re: Generic event mechanism (was: loosely coupled panels: react to model object change)

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Sat, 16 Feb 2008, Igor Vaynberg wrote:
> havent really had a chance to take a detailed look yet. also we havent
> discussed it as a team and agree on what the api should look like. i
> would also like broadcast to be on component...

OK, I made another version of the patch where the broadcast 
method is directly in Component

  https://issues.apache.org/jira/browse/WICKET-1312?focusedCommentId=12569657#action_12569657

For me it would have been cleaner design to just make an
EventBroadcaster field in Component, use it to implement the
method, and inject the field with a mock of something for
testing. But I thought that you want to guard against any
additional fields in all Component objects for memory
optimisation. So I prematurely optimised the method in
Component to delegate to a static method in
EventBroadcaster.

Testability must be ensured somehow and the current way is 
maybe not the most eloquent in the world, but it works.

Looking forward to your comments and critique!

Best wishes,
Timo

-- 
Timo Rantalaiho
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

Re: Generic event mechanism (was: loosely coupled panels: react to model object change)

Posted by Igor Vaynberg <ig...@gmail.com>.
hi timo,
havent really had a chance to take a detailed look yet. also we havent
discussed it as a team and agree on what the api should look like. i
would also like broadcast to be on component...

-igor


On Feb 16, 2008 2:39 AM, Timo Rantalaiho <Ti...@ri.fi> wrote:
> On Tue, 05 Feb 2008, Igor Vaynberg wrote:
> > see https://issues.apache.org/jira/browse/WICKET-1312
>
> Thanks for advertising!-)
>
> Have you or other devs had time to look at the patch, and
> what do you think?
>
> It would be excellent to already have this in Wicket 1.3
> (such as 1.3.2) to be able to use it in most of our real
> Wicket projects. Of course now that the patch is there it
> can be easily enough ripped to any project.
>
> The code is all Java 1.4 and it doesn't change any existing
> code, just builds on it. So it doesn't break any other
> functionality, just adds more code to maintain.
>
> Anyway, good even if it makes it to Wicket 1.4.
>
>
> A braver version (suggested by my workmate) would hook event
> broadcasting directly to Component so that you could just
> call broadcast(ListenerClass, Event) anywhere without need
> to create the broadcaster object yourself.
>
>
> Best wishes,
> Timo
>
> --
> Timo Rantalaiho
> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>