I don't really have a good knowledge of EJB components, CDI and stuff. I'm having a lot of trouble with asynchronous EJB. I tried some tutorials but I couldn't understand or make them work adapting to the code I'm maintaining here.
I would like my EJB to return an answer to my Managed Bean when it finishes executing. ManagedBean should listen to it and then do other stuff (in my case I need to update view components, which could be done with a redirect), but it can't block navigation and other actions from user.
So far, this is what I got:
1 - this is my managed Bean:
@Named
@ViewScoped
public class MyManagedBean {
@Inject
private ExecutionService executionService;
public void executeAsyncTask(Suite suite) {
try {
Future<Boolean> result = executionService.executeStuff(suite);
if (result.isDone()) {
// send a redirect if he is in the same page of the button that calls this method. It doesn't work, it's result is always false because execution is not finished and method moves on with his life
}
}
2 - And this is my EJB:
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class ExecutionService extends BaseBean implements Serializable {
//
@Inject private ExecutionDAO execDao;
//
@Asynchronous
public Future<Boolean> executeStuff(Suite suite) throws BusinessException {
Boolean areStiffExecuted = false;
Process process;
try {
process = Runtime.getRuntime().exec(new String[]{ });
// and other crazy stuff that take some time.
} catch (Exception e) {
// log exception and throw it to managed bean
} finally {
// do some stuff like destroying process
return new AsyncResult<>(true);
}
}
}
Do you guys have any idea of how to get what I want?