Centralising vaadin services

Howdy y’all!

I’m currently developing a media player that will be used by all my work colleagues to play music on our media server. At the moment i’ve got the ui code pretty much finished, but my next task is to make the application centralised.

What i mean by this is currently i can start up an instance of the program on my machine, but if i start the program up on another machine, it opens another instance. How do i configure vaadin so there will always just be one instance of the application?


I’m afraid it doesn’t work like that - there’s one instance of the Vaadin application for each HTTP session - that is, per user-using-the-web-application

You can, of course, have a single service shared between multiple sessions in the same web-application - but how you do that really depends on what frameworks/services you’re used to using. In a “proper” large-scale production application, you’d use something like Spring or Guice to create singletons which you’d inject into the Vaadin application. I suspect that’s overkill for this, especially as though it doesn’t sound like you’ve got much experience in this area.

I would suggest and “old-fashioned” simple java singleton. I assume you want to have a single MediaPlayer service, share between all of the users. Here’s an example (not compiled, just typed into my browser, so probably some errors in here somewhere)



 public class MediaPlayer {
   private static MediaPlayer INSTANCE = new MediaPlayer();

  public static getInstance(){
     return INSTANCE;

  // Private Constuctor so that nothing else can create a media player instance
  private MediaPlayer(){

  public void nextTrack(){

  public void previousTrack(){


Thanks for the response!

At the minute i don’t actually have the media player service running. But i’ve created a jukebox which fires events to all listeners when something happens (such as a queue change, or the next track plays etc.). What i’m trying to get it to do is update the ui on all the connected clients when an event is fired.

At the minute if one user were to open the application, they can add items to the queue, but then problems start occuring when more than one client is connected to the service. The second user can’t see anything queued up from before they logged on, but then when the queue changes they both update themselves(sometimes). When the volume is changed by one user the event is fired, but the other clients volumes don’t update. And when a user clicks next, the ui will update itself on the machine that clicks the next button, but not on any of the other clients.

I’ve made the jukebox and library into a singleton (the jukebox handles the firing of all the events, so when a user clicks next, the jukebox removes the first track in the queue and fire the event to notify all listeners that the queue has changed.) so all clients are using the same jukebox and library.

OK : now we’re getting somewhere.

The thing is, Vaadin is a request/response framework - like almost all web applications. The user does a thing in the browser - clicks a button, selects an item in a table - and the browser sends a request to the server, which processes that request and sends a response, and the browser then updates the UI.

In a normal Vaadin application, there is no way to “push” changes from the server to the browser if the user hasn’t done anything - i.e. if there has been no request.

However, there are some addons and techniques you can use : here’s a
sticky thread
. In short, though, and for your application, I would recommend using the



Thanks for the help! The singleton solved it, i’ve been using ICEpush to push the changes onto the application, which seems to work :smiley: