Skip to content

Instantly share code, notes, and snippets.

@jeffbicca
Last active December 28, 2015 23:59
Show Gist options
  • Select an option

  • Save jeffbicca/7582694 to your computer and use it in GitHub Desktop.

Select an option

Save jeffbicca/7582694 to your computer and use it in GitHub Desktop.

Revisions

  1. jeffbicca revised this gist Dec 2, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions AsyncService.java
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    @Singleton
    @TransactionAttribute(TransactionAttributeType.NEVER) // useful when you need to turn off the EJB transaction control.
    public class AsyncService implements Serializable {

    private Repository repository;
  2. jeffbicca created this gist Nov 21, 2013.
    24 changes: 24 additions & 0 deletions AsyncProcessManager.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    @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();
    }

    }
    30 changes: 30 additions & 0 deletions AsyncService.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    @Singleton
    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);
    }

    }
    3 changes: 3 additions & 0 deletions asyncPoll.xhtml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    <a4j:poll id="poll" interval="5000"
    execute="@this"
    render="@form" enabled="#{not (asyncProcessManager.isDone(selectedProcess))}"/>