Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
I just released my very first addon. It's called VaadinWorker and its purpose is it to make it easier to let parts of the UI-code execute in background-threads. It consists of a class "VaadinWorker", which exposes the two methods "runInBackground()" and "updateUI()". The runInBackground()-method should be used for executing the long-running logic, whose result can be communicated towards the Client using the updateUI()-method. Proper synchronization on the Application-class will be done by the VaadinWorker-template-class. For in-between-updates you can use a ProgressListener. The updateProgress()-method of that interface will also called in a synchronized-block, so that it is safe to do arbitrary UI-updates from that method. To trigger the ProgressListeners you just need to call VaadinWorker#updateProgress(int,String). The int-Parameter communicates the actual progress in form of a procentual progress, while the String is just a description of the work currently done.
The second important part of the Addon is the BackgroundExecutor-component, which not only communicates the progress towards the User but also keeps the UI updating itself using the "Spinning-ProgressIndicator-Pattern". VaadinWorkers get submitted for execution in background by calling BackgroundExecutor#submit(VaadinWorker). They are then handed over towards an ExecutorService. This ExecutorService is retrieved by an ExecutorServiceProvider. This way you can decide for example to reuse an ExecutorService your ApplicationServer already provides. For Servlet-environments the addon contains a mechanism to register an ExecutorService with the ServletContext and later on retrieving it from there again. I'm not using Portals at home, so I didn't had the chance to build a neat solution for portlets as well, but maybe I will get to do that in my day-job ...
At the moment the Addon is marked as experimental as the documentation is lacking and the code has not been tested in any bigger project so far. Let me know what you think about VaadinWorker!
The VaadinWorker-Wiki now contains some installation- and usage-instructions. Next step will be a reorganization of the project-structure in order to include the Demo-Application and maybe one or two other examples as well in the repository. I also have to complete the documentation and finish my first test of VaadinWorker in the context of a bigger project.
I haven't had a chance to investigate VaadinWorker in any depth, but I've just skimmed over the Javadoc and looked at the wiki, and this looks very cool and useful. Practically, though, I won't be able to use this add-on in any of my work projects because of it's AGPL license.
Anyway, I thought I'd just say it looks great, and it and thanks!
Thanks for your post, I am happy with all the feedback I am getting for VaadinWorker so far.
For the corporate guys I will publish a CVAL2-licensed version once I feel confident enough to leave "experimental"-state.
Ok, I have migrated the project from GitHub to Google-Code (just feeling more familiar with using SVN). During this I also added the source-code of the Demo-App and of the later Tutorial-application to the repository. These should help with understanding usage of VaadinWorker.
The Tutorial-app is also running at http://vaadinworker.javaprovider.net/VaadinWorkerTutorialPart1. I will add some more controls for emphasizing that the UI keeps being usable through the computation. And of course I have to write the actual tutorial and publish it to the wiki. As the Part1 in the app-name already indicates I plan to enhance this application with at least two further steps, demonstrating In-between-updates, localization and view-customization.
Any timetable for portlet support?
Well, the non-portlet-supportive part is only there to handle session-serialization issues. This workaround is only needed if you use a container that actually does serialize its session (often they don't). So actually VaadinWorker is usable with portlets, although it still needs some polishing. But that's why it is still experimental ;) ...
Does this work with a Vaadin/Spring setup? I've been trying to get it to work all day, but I keep getting this error no matter what I try:
java.lang.IllegalStateException: The worker's application and my Application must be the same! de.tobiasdemuth.vaadinworker.ui.BackgroundExecutor.submit(BackgroundExecutor.java:127)
Not sure what else would be helpful, so if there is something specific you would like to look at, please let me know.
Nevermind, I didn't realize I had to add the BackgroundExecutor as a component. From the tutorial code if anyone is interested or runs into the same issue:
From VaadinWorkerTutorialApplication constructor
this.executor = new BackgroundExecutor(new ContextExecutorServiceProvider());
Add executor component to main window
final Window mainWindow = new Window("VaadinWorkerTutorial"); final VerticalLayout rootLayout = new VerticalLayout(); rootLayout.setSpacing(true); rootLayout.setMargin(true); [b]rootLayout.addComponent(executor);[/b]