Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #143 from zanata/async-fix
Browse files Browse the repository at this point in the history
Async fix
  • Loading branch information
Patrick Huang committed Aug 28, 2013
2 parents e875eea + c0ea381 commit 6cffb1b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Expand Up @@ -29,9 +29,10 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.async.Asynchronous;
import org.jboss.seam.security.Identity;
import org.jboss.seam.security.RunAsOperation;

import lombok.extern.slf4j.Slf4j;

/**
* This class executes a Runnable Process asynchronously. Do not use this class directly.
* Use {@link org.zanata.async.TaskExecutor} instead as this is just a wrapper to make sure
Expand All @@ -43,10 +44,12 @@
@Name("asynchronousTaskExecutor")
@Scope(ScopeType.STATELESS)
@AutoCreate
@Slf4j
public class AsynchronousTaskExecutor
{
@Asynchronous
public <V, H extends AsyncTaskHandle<V>> void runAsynchronously(final AsyncTask<V, H> task, final Identity runAs)
public <V, H extends AsyncTaskHandle<V>> void runAsynchronously(final AsyncTask<V, H> task, final Principal runAsPpal,
final Subject runAsSubject)
{
AsyncUtils.outject(task.getHandle(), ScopeType.EVENT);

Expand All @@ -63,19 +66,20 @@ public void execute()
catch (Exception t)
{
task.getHandle().setException(t);
AsynchronousTaskExecutor.log.error("Exception when executing an asynchronous task.", t);
}
}

@Override
public Principal getPrincipal()
{
return runAs.getPrincipal();
return runAsPpal;
}

@Override
public Subject getSubject()
{
return runAs.getSubject();
return runAsSubject;
}
};

Expand Down
3 changes: 2 additions & 1 deletion zanata-war/src/main/java/org/zanata/async/TaskExecutor.java
Expand Up @@ -57,7 +57,8 @@ public <V, H extends AsyncTaskHandle<V>> AsyncTaskHandle<V> startTask(AsyncTask<
throw new RuntimeException("An Asynchronous task should always return a non-null handle");
}

asynchronousTaskExecutor.runAsynchronously(task, Identity.instance());
Identity identity = Identity.instance();
asynchronousTaskExecutor.runAsynchronously(task, identity.getPrincipal(), identity.getSubject());
return handle;
}

Expand Down
Expand Up @@ -252,11 +252,13 @@ public ProcessStatus getProcessStatus(@PathParam("processId") String processId)
catch (InterruptedException e)
{
// The process was forcefully cancelled
status.setStatusCode(ProcessStatusCode.Failed);
status.setMessages(Lists.newArrayList(e.getMessage()));
}
catch (ExecutionException e)
{
// Exception thrown while running the task
status.setStatusCode(ProcessStatusCode.Failed);
status.setMessages(Lists.newArrayList(e.getCause().getMessage()));
}

Expand Down

0 comments on commit 6cffb1b

Please sign in to comment.