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

Commit

Permalink
Fix manual merge compilation errors.
Browse files Browse the repository at this point in the history
Make sure the translation memory uses of the async classes is working properly.
  • Loading branch information
Carlos A. Munoz committed Aug 27, 2013
1 parent 5848eab commit af938bc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
Expand Up @@ -24,6 +24,7 @@

import java.io.Serializable;
import java.util.List;
import java.util.concurrent.ExecutionException;

import javax.faces.event.ValueChangeEvent;

Expand All @@ -49,6 +50,8 @@
import org.zanata.rest.service.TranslationMemoryResourceService;
import org.zanata.service.SlugEntityService;

import com.google.common.base.Optional;

/**
* Controller class for the Translation Memory UI.
*
Expand Down Expand Up @@ -78,7 +81,7 @@ public class TranslationMemoryAction extends EntityHome<TransMemory>
*/
@In(scope=ScopeType.PAGE, required=false)
@Out(scope=ScopeType.PAGE, required=false)
private ProcessHandle myProcessHandle;
private AsyncTaskHandle myTaskHandle;

/**
* Stores the last process error, but only for the duration of the event.
Expand Down Expand Up @@ -131,7 +134,7 @@ public Void call() throws Exception

private boolean isProcessing()
{
return myProcessHandle != null;
return myTaskHandle != null;
}

public boolean isProcessErrorPollEnabled()
Expand All @@ -148,13 +151,22 @@ public boolean isProcessErrorPollEnabled()
public String getProcessError()
{
if (myProcessError != null) return myProcessError;
if (myProcessHandle != null && myProcessHandle.isFinished())
if (myTaskHandle != null && myTaskHandle.isDone())
{
processManagerServiceImpl.removeIfInactive(myProcessHandle);
Throwable error = myProcessHandle.getError();
// remember the result, just until this event finishes
this.myProcessError = error != null ? error.getMessage() : "";
this.myProcessHandle = null;
try
{
myTaskHandle.get();
}
catch (InterruptedException e)
{
// no error, just interrupted
}
catch (ExecutionException e)
{
// remember the result, just until this event finishes
this.myProcessError = e.getCause() != null ? e.getCause().getMessage() : "";
}
myTaskHandle = null;
return myProcessError;
}
return "";
Expand Down
Expand Up @@ -67,8 +67,6 @@ public interface AsyncTaskManagerService
*/
AsyncTaskHandle getHandleByKey(Serializable key);

AsyncTaskHandle getHandle(String taskId, boolean removeIfFinished);

/**
* @return All handles for all tasks being managed by this service.
*/
Expand Down
Expand Up @@ -87,35 +87,25 @@ public <V, H extends AsyncTaskHandle<V>> void startTask(AsyncTask<V, H> task, Se

@Override
public AsyncTaskHandle getHandle(String taskId)
{
return getHandle(taskId, false);
}

@Override
public AsyncTaskHandle getHandleByKey(Serializable key)
{
return handlesByKey.get(key);
}

@Override
public AsyncTaskHandle getHandle(String taskId, boolean removeIfFinished)
{
try
{
Long taskKey = Long.parseLong(taskId);
AsyncTaskHandle handle = handlesById.getIfPresent(taskKey);
if( removeIfFinished )
{
handlesById.invalidate(taskKey);
}
return handle;
}
catch (NumberFormatException e)
{
return null; // Non-number keys don't exist in this implementation
return null; // Non-number keys are not allowed in this implementation
}
}

@Override
public AsyncTaskHandle getHandleByKey(Serializable key)
{
return handlesByKey.get(key);
}

@Override
public void clearInactive()
{
Expand Down

0 comments on commit af938bc

Please sign in to comment.