Last active
December 28, 2015 23:59
-
-
Save jeffbicca/7582694 to your computer and use it in GitHub Desktop.
Keeping a long-running process executing in an asynchronous fashion using CDI, EJB and JSF 2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a4j:poll id="poll" interval="5000" | |
execute="@this" | |
render="@form" enabled="#{not (asyncProcessManager.isDone(selectedProcess))}"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ApplicationScoped | |
public class AsyncProcessManager implements Serializable { | |
private Map<AsyncProcess, Future<Object>> asyncProcesses = new ConcurrentHashMap<AsyncProcess, Future<Object>>(); | |
public void addProcess(AsyncProcess process) { | |
// put the process into the map. | |
} | |
public void removeProcess(AsyncProcess process) { | |
// remove the process from the map. | |
} | |
public boolean existsProcessFor(User user) { | |
// check if there is any process for the user. | |
} | |
public boolean isDone(AsyncProcess process) { | |
Future<Object> theAsyncExecution = findAsyncExecutionFor(process); | |
return theAsyncExecution != null && theAsyncExecution.isDone(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@TransactionAttribute(TransactionAttributeType.NEVER) // useful when you need to turn off the EJB transaction control. | |
public class AsyncService implements Serializable { | |
private Repository repository; | |
@Asynchronous | |
@Lock(LockType.READ) | |
@AccessTimeout(-1) | |
public Future<Object> operation1() { | |
// implementation | |
return new AsyncResult<Object>(null); | |
} | |
@Asynchronous | |
@Lock(LockType.READ) | |
@AccessTimeout(-1) | |
public Future<Object> operation2() { | |
// implementation | |
return new AsyncResult<Object>(null); | |
} | |
@Asynchronous | |
@Lock(LockType.READ) | |
@AccessTimeout(-1) | |
public Future<Object> operationN() { | |
// implementation | |
return new AsyncResult<Object>(null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment