|
|
|
@ -51,6 +51,7 @@ import java.util.concurrent.Future;
|
|
|
|
|
public abstract class SimpleTask<T> implements LifecycleObserver {
|
|
|
|
|
private boolean log = true;
|
|
|
|
|
private boolean count = true;
|
|
|
|
|
private boolean interruptable = true;
|
|
|
|
|
|
|
|
|
|
private String name;
|
|
|
|
|
private long started;
|
|
|
|
@ -82,6 +83,11 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SimpleTask<T> setInterruptable(boolean interruptable) {
|
|
|
|
|
this.interruptable = interruptable;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SimpleTask<T> setExecutor(ExecutorService executor) {
|
|
|
|
|
this.localExecutor = executor;
|
|
|
|
|
return this;
|
|
|
|
@ -284,7 +290,8 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|
|
|
|
long elapsed = now - task.started;
|
|
|
|
|
if (elapsed > CANCEL_AFTER && !task.interrupted) {
|
|
|
|
|
task.interrupted = true;
|
|
|
|
|
if (task.future != null && !task.future.isDone()) {
|
|
|
|
|
if (task.interruptable &&
|
|
|
|
|
task.future != null && !task.future.isDone()) {
|
|
|
|
|
Log.e("Interrupting task " + task +
|
|
|
|
|
" tasks=" + getCountLocked() + "/" + tasks.size());
|
|
|
|
|
task.future.cancel(true);
|
|
|
|
|