Vaadin Push with Views and EJB Async Methods

Hello everyone from Accra Ghana,

I’m working on a Vaadin 7.4 CDI powered project that has a UI with a number of views. Now I’ve a long running task that I’ve implemented with Java EE7 stateless EJB in an Asynchronous method. What I want to do is call this async method from one of the views, and then show an indeterminate progress bar for as long as the Future object returned from the async method returns false.

As soon as it returns true, I’d like to show a humanized notification to the user that the task is done. I’ve read the Vaadin Push tutorials a number of times, but I’m stumped as to how to implement my situation.

I tried doing the “traditional” way of simply calling the EJB method and using a simple while loop to check, but the app just hanged when I click the button to call the EJB method.

Is Vaadin Push the answer? If yes, how do I please go about it? If no, then what is your recommended approach to solving my problem at hand. Thank you very much for your time.

Anyone? Please?

==================== INTERFACE - CLIENT =================================
@Local
public interface UserServiceLocal {
public static final String JNDI_NAME = “java:global/ejb_1.0.0.SNAPSHOT/UserService!br.com.vaadin.osgi.services.UserServiceLocal”;
public User findUser(String login, String password) throws Exception;
}
==================== INTERFACE - CLIENT =================================

====================EJB-IMPL===================================
@Stateless
@LocalBean
@EJB(name = UserServiceLocal.JNDI_NAME, beanInterface = UserServiceLocal.class)
public class UserService implements UserServiceLocal {

@Asynchronous
 public User findUser(String login, String password) throws Exception{
     return null;
 }

}
====================EJB-IMPL===================================

========================WEB-CLIENT===================================

    UserServiceLocal ejb = new JndiLookupHelper<UserServiceLocal>().lookup(UserServiceLocal.JNDI_NAME);

=======================WEB-CLIENT===================================

===============================================================
public class JndiLookupHelper {

private T remoteObject;

@SuppressWarnings("unchecked")
public T lookup(String name) {
    try {
        remoteObject = (T) InitialContext.doLookup(name);
    } catch (NamingException ne) {
        ne.printStackTrace();
    }
    return remoteObject;
}

}

I’m not sure if my question wasn’t clear. But what i mean is I’m using CDI for injections and all that, no manual lookups. What I want to do is call an asyc ejb method from a View class and update it when the method completes

Hello Seeraj,

You cannot wait for the Future completion in a while loop since that will block the UI thread (your ui hangs). The push won’t help you there either.

Since you are on EE7, you could try to put the async logic in a runnable and use the ManagedExecutorService to do the task. As a final task in your runnable you could then update the UI using ui.access(…) method described in the push tutorials.

Hope this helps,
Matti