Vaadin + OSGi service

206 views
Skip to first unread message

ctranxuan

unread,
Dec 5, 2011, 2:17:22 PM12/5/11
to Vaadin OSGi Collaboration
Hi all,
Most of the examples Vaadin + OSGi show how to deal with the UI
dynamicity, but I haven't found some that show how to deal with an
OSGi service used as back-end from a Vaadin UI. I am especially
interested in how to manage from Vaadin components, that use an OSGi
service, the fact that this OSGi service can appear and disappear at
any time.
Any recommandations about best practices, feedbacks and experiments
would be appreciated. :)

Thanks in advance.

Olivier NOUGUIER

unread,
Dec 6, 2011, 2:44:49 AM12/6/11
to vaadi...@googlegroups.com
Hi,
  You should take a look at http://www.eclipse.org/gemini/blueprint/ (aka Spring DM). Some of these concern are managed.
HIH
--
"Computers are useless. They can only give you answers."
- Pablo Picasso -

ctranxuan

unread,
Dec 6, 2011, 3:41:14 AM12/6/11
to Vaadin OSGi Collaboration
Thanks. I am already using Spring DM. But I am more interested in
patterns to manage the problem. My main concern is about notifying the
Vaadin components of the arrival and departure of an OSGi service. In
this case, one solution, I could see, would mean that these Vaadin
components be managed by the OSGi container in order to be warned of
these events from the registry. But more or less that would mean
registering in the OSGi registry as many Vaadin components as user
http session. If we take the example of Kai (http://www.toedter.com/
blog/?p=412), Kai uses component factory to create Vaadin
Applications. This means that a Vaadin Application is exposed as an
OSGi component in the OSGi registry. So there are as many as
Applications declared in the OSGi registry as user http sessions. But
the views (Vaadin components added in the Vaadin Applications) are
shared between the different Applications and instanciated as
"singleton". What if the view shouldn't be shared among the
Applications (e.g. a user account which displays user information
provided by an OSGi user service (which can appears and disappears at
any time))?
Thus I am interested whether someone has met this concern and how he/
she manages it.

Note I am also interested in some Spring DM usage with Vaadin. If we
still take the example of Kai, Kai uses component factory to create
Vaadin Applications and expose them as OSGi components instances.
While DS and iPOJO offer the ability to create multiple instances of
OSGi components via factories, I haven't found such features in Spring
DM (which doesn't mean they don't exist :) ). Indeed, what I have
found is that you can create OSGi component instances per bundle
consumer (via <bean ..."scope=bundle"/>) but not at will. Hence, I
guess some code that would mimic what can do DS or iPOJO with
factories to deal with that concern manually.

Thanks in advance.


On Dec 6, 8:44 am, Olivier NOUGUIER <olivier.nougu...@gmail.com>
wrote:

Christopher Brind

unread,
Dec 6, 2011, 3:56:59 AM12/6/11
to vaadi...@googlegroups.com
This statement is a little worrying.  I've just checked his code and it seems you're correct.  It lazily creates views when getView(Application) method is called and then keeps a reference to return to subsequent calls.  

I wouldn't expect this to work with multiple http sessions because afaik you can only add a component to a view hierarchy once in Vaadin (I could be wrong though).  I wonder if Kai tried his app with multiple concurrent http sessions?

Did you get Kai's app running?  (I don't really have time just now.)  If you did perhaps you could try running the app from two different browsers to get two different http sessions and see if it works.  If it does, simply stop one of the bundles that makes a view contribution and see what happens. =)

Cheers,
Chris

ctranxuan

unread,
Dec 6, 2011, 9:02:46 AM12/6/11
to Vaadin OSGi Collaboration
Actually, I did run Kai's app in different browsers. What I have done
is a slight modification: I display a random number in the banner of
the Application and also a random number in one the view (TreeView).
The random numbers are generated in the constructor of each classes.
And then run with different browsers.
From two browsers, we get:

* different numbers displayed in the Application banner
* same number displayed in the view

This means that the Applications are created one per httpsession and
exposed as an OSGi components (I verified in the OSGi console to be
sure :)) while the Views are shared among the application (as you
notice in the code). Note that, in the Kai's application, it's may be
not a problem since his example is tightly bound to the activation or
desactivation of the bundles which expose the views.

My concern is : what about when the views shouldn't be shared and uses
an OSGi service? Should we expose them as OSGi components as Kai's
does with Applications in order to benefit from the OSGi mechanism of
detection of an OSGi service arrival and departure? May be you have
some personal feedback about this concern?

Thanks in advance.

On Dec 6, 9:56 am, Christopher Brind <bri...@brindy.org.uk> wrote:
> This statement is a little worrying.  I've just checked his code and it
> seems you're correct.  It lazily creates views when getView(Application)
> method is called and then keeps a reference to return to subsequent calls.
>
> I wouldn't expect this to work with multiple http sessions because afaik
> you can only add a component to a view hierarchy once in Vaadin (I could be
> wrong though).  I wonder if Kai tried his app with multiple concurrent http
> sessions?
>
> Did you get Kai's app running?  (I don't really have time just now.)  If
> you did perhaps you could try running the app from two different browsers
> to get two different http sessions and see if it works.  If it does, simply
> stop one of the bundles that makes a view contribution and see what
> happens. =)
>
> Cheers,
> Chris
>

Alberto Sarubbi

unread,
Dec 29, 2011, 8:28:29 AM12/29/11
to Vaadin OSGi Collaboration
the view and action contributions in the example behaves as
singletons.
even worse, if you change from one tab to another in one browser the
other browser goes out of sync and vaadin complains aloud.

i'm trying to figure out how to make each application totally isolated
for each HTTP Session with osgi contributions....

ctranxuan ctranxuan

unread,
Dec 31, 2011, 3:22:58 AM12/31/11
to vaadi...@googlegroups.com
I guess we can do something similar as it is done for the applications: use a component factory for the views and actions.
I have also noticed the out of sync with different browsers.

If time, I will also have a look at it.
Thanks.

2011/12/29 Alberto Sarubbi <asar...@gmail.com>

Tiago Stürmer Daitx

unread,
Dec 31, 2011, 3:24:10 PM12/31/11
to vaadi...@googlegroups.com
This is due to the way Vaadin works. By default you can only open a
Vaadin Application in a single browser window/tab. This happens
because Vaadin will create one Application instance per HTTP session
(which are shared by windows/tabs in the browser) and this Application
will always return the same Window instance (together with its
component tree). Given that Vaadin/GWT components have to maintain
client and server side state, when you open multiple windows/tabs and
start interacting with one of those, all the others won't see the
server-side state changing and thus will be out of sync.

The solution is to override the Application.getWindow method. The
Navigator7 addon was the one that implemented the most complete (and
somewhat hacky) Window handling routines that I know of, check
https://vaadin.com/forum/-/message_boards/view_message/247338

Look in the Vaadin forum for more information, there are a bunch of
threads about this bug/feature.

Regards,
Tiago Daitx

--
Tiago Sturmer Daitx
tda...@gmail.com

Reply all
Reply to author
Forward
0 new messages