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

Commit

Permalink
Add cancel methods to the AsyncTaskHandle.
Browse files Browse the repository at this point in the history
Still not sure about this duplication of cancel methods, but lets see how it goes.
  • Loading branch information
Carlos A. Munoz committed Aug 27, 2013
1 parent 42908c4 commit edff342
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
Expand Up @@ -153,7 +153,7 @@ public void cancelCopyTrans( HProjectIteration iteration )
{
CopyTransProcessKey key = CopyTransProcessKey.getKey(iteration);
CopyTransTaskHandle handle = this.getCopyTransProcessHandle(iteration);
handle.cancel(true);
handle.forceCancel();
handle.setCancelledTime(System.currentTimeMillis());
handle.setCancelledBy(identity.getCredentials().getUsername());
}
Expand Down
Expand Up @@ -81,7 +81,7 @@ public void clearAllFinished()

public void cancel( AsyncTaskHandle handle )
{
handle.cancel(false);
handle.cancel();
}

}
Expand Up @@ -47,7 +47,7 @@ public void prepareIterationZipFile(boolean offlinePo)
if( this.zipFilePrepHandle != null && !this.zipFilePrepHandle.isDone() )
{
// Cancel any other processes for this conversation
this.zipFilePrepHandle.cancel(true);
this.zipFilePrepHandle.forceCancel();
}

// Start a zip file task
Expand All @@ -61,7 +61,7 @@ public void prepareIterationZipFile(boolean offlinePo)
@End
public void cancelFileDownload()
{
this.zipFilePrepHandle.cancel(false);
this.zipFilePrepHandle.cancel();
}

public Object getProjectIteration()
Expand Down
Expand Up @@ -175,7 +175,7 @@ public void reindexDatabase()

public void cancel()
{
reindexAsync.getProcessHandle().cancel(false);
reindexAsync.getProcessHandle().cancel();
}

public boolean isCanceled()
Expand Down
26 changes: 26 additions & 0 deletions zanata-war/src/main/java/org/zanata/async/AsyncTaskHandle.java
Expand Up @@ -61,4 +61,30 @@ public int increaseProgress(int increaseBy)
currentProgress += increaseBy;
return currentProgress;
}

/**
* Cancels the task without trying to forcefully interrupt the task.
* This is equivalent to calling <code>cancel(false)</code>
*
* @see AsyncTaskHandle#cancel(boolean)
* @return false if the task could not be cancelled, typically because it has already completed normally;
* true otherwise
*/
public boolean cancel()
{
return cancel(false);
}

/**
* Cancels the task, forcefully cancelling the task if needed.
* This is equivalent to calling <code>cancel(true)</code>
*
* @see AsyncTaskHandle#cancel(boolean)
* @return false if the task could not be cancelled, typically because it has already completed normally;
* true otherwise
*/
public boolean forceCancel()
{
return cancel(true);
}
}
Expand Up @@ -72,7 +72,7 @@ public DownloadAllFilesResult execute(DownloadAllFilesAction action, ExecutionCo
if (this.zipFilePrepHandle != null && !this.zipFilePrepHandle.isDone())
{
// Cancel any other processes
this.zipFilePrepHandle.cancel(false);
this.zipFilePrepHandle.cancel();
}

// Build a new task
Expand Down

0 comments on commit edff342

Please sign in to comment.