Proper design / architecture for a servlet-wide lobby and messaging?

First of all, I must say that Vaadin looks to be one of the best kept secrets on the internet. I can’t believe I didn’t know about this before, and I will be sure to spread its praises around Stackoverflow in the future. :slight_smile:

I was wondering if anyone knew of a design pattern for the ‘proper’ architecture of a global ServletContext ‘lobby’?

What I have so far would work in a single JVM instance: synchronized singleton. It holds a list of references to every user’s ApplicationContexts. We add users on
. We can also add listeners and then broadcast servlet-wide messages, as in the
IT Mill Go Game
. Is this basically a Blackboard Pattern for the entire servlet container?

I don’t want to reinvent the wheel. If JavaEE containers provide
user authentication and management
, and Vaadin can use that, then is a better Java EE 6 way of doing this?

I’m not exactly sure I understand the question, but are you saying that you’d like to store somewhere a list of all the logged-in users? If so, I don’t get how you’re using the ServletContextListener. Instead, I’d imagine you’d implement HttpSessionListener and store the web app context as you go (though I don’t know if it’s been created at that point yet or not). Something like:

public class MySessionListener implements HttpSessionListener {

    // An EJB annotated with @Singleton, but if you're using just a
    // servlet container than you can do a Holder.getInstance() call
    // in the business methods below. Make sure everything is
    // thread safe!
    @EJB SessionHolderBean sessionHolder;

    @Override public void sessionCreated(HttpSessionEvent event) {
        // store session or app context in sessionHolder .... );

    @Override public void sessionDestroyed(HttpSessionEvent event) {
        sessionHolder.remove( .... );

But maybe you’re storing the ServletContext object and you can just get that info directly from there? If so, I should probably know how by now…

If you’re using container-managed authentication, I’m not sure there’s any place in the code to get a list of logged-in users. You might want to ask on the users list for
. Even if you’re not using GF, it’s still the Java EE reference implementation and so the user’s list is appropriate for API-level questions.

You’re probably doing the most expedient thing already, but note that storing these in a singleton bean only works if you’re not doing any clustering.


Thanks Bobby, your posts and blog on Oracle have been a great resource. I am still learning Java EE 6 and Vaadin, so that’s why my question might be a little unclear. Give me a day and I will repost with either a clarification, or a summary of what I’ve found.