Advise on how to go about this

I have a server application that monitors many temperature sensors. Currently I have a swing application that uses sockets to connect to the server, it regularly requests an object that contains all of the temperature sensor objects and then iterates through them calling getCurrentReading() and updates the user interface. The server also has jetty installed and I’ve created custom handlers that generates/serves html to be able to check on the temperature readings from a web browser.

My question is how do I go about moving this to Vaadin? I’m not understanding how I go from getting those sensor readings in the server to having a vaadin app get the readings and update the user interface? I know how to make the jetty start a war file/servlet but I don’t understand how/where the vaadin app will get the data from the server? Do I make custom jetty handlers that the vaadin app will connect to to get the data? Maybe json or xml? I also have a database where the temperature readings up stored but I don’t write to the database everytime I get a new reading…although I could. Any insight or suggestions will be greatly appreciated.

[Caveat: I am a Vaadin newbie, so take my advice with a grain of salt.]

As a general rule, In Vaadin, think more like Swing and less like YAWAF (Yet Another Web App Framework).

Seems your question is really two:
• How to get the sensors into the Vaadin app
• Automatically and regularly update the user interface with current readings from the sensors

The first is easy - do it just like Swing.
The second is not easy - Vaadin 6 lacks a built-in mechanism to “push” server-side generated data and events to the client. But you can add such a facility.

In a Swing app, you would spawn a thread that regularly:
• Makes a socket connection to the lab’s server.
• Ask that socket for a fresh set of sensor objects.
• Calls “getCurrentReading()” on each sensor.
• Communicates those latest readings to the GUI thread (“EDT” Event Dispatch Thread in Swing).

You can do the same in Vaadin. In the “init()” method of your app (your subclass of Vaadin’s Application class), spawn the same kind of sensor-reading thread as you would in Swing.

Beware of concurrency. One of the few differences between Swing and Vaadin: Swing has only a single user, whereas Vaadin has multiple users. Anything static in your Application-subclass affects all your users, while each instance of your Application-subclass affects a single user. For example, you might be tempted to keep a single socket connection as a static object on your Application-subclass; if so, you must protect that socket object during concurrent access by all the instances of your app. Each of those instances is running in their own thread.

While getting the sensor readings is easy, automatically updating the user interface is not. You’ll need to extend Vaadin to “push” the generated data to the UI. I’ve not done this yet, but I’ve heard of two Vaadin add-ons:



You do not need your Jetty handlers that server HTML. A Vaadin app instance stays up and running during a work session, staying alive longer than a single request-response cycle. So your Vaadin app instance can do the work of talking to the sensors, if that’s the way you want to do it.

By the way, the future Vaadin 7 may include “push” features.

–Basil Bourque

this thread
for more information on pull and push solutions and the synchronization requirements for UI updates from background threads (synchronizing to the Application instance).

If you already have a process running somewhere (outside the Vaadin application) that constantly polls the sensors and stores the readings to your database, that same process could also notify the Vaadin application via some message queue or similar solution so that the Vaadin application would not need to poll all the sensors.