Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring SequentialExecutorService.java #4979

Merged
merged 1 commit into from
Apr 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ private static class AutoExecutor extends SequentialExecutor {
super(executor);
}

protected void execute(final String key, final Deque<Runnable> finalTasks) {
protected void execute(final String key, final Deque<Runnable> tasks) {
executor.execute(
new Runnable() {
@Override
public void run() {
invokeCallbackAndExecuteNext(key, finalTasks);
invokeCallbackAndExecuteNext(key, tasks);
}
});
}

protected void invokeCallbackAndExecuteNext(final String key, final Deque<Runnable> tasks) {
private void invokeCallbackAndExecuteNext(final String key, final Deque<Runnable> tasks) {
invokeCallback(tasks);
synchronized (tasksByKey) {
if (tasks.isEmpty()) {
Expand All @@ -137,13 +137,7 @@ protected void invokeCallbackAndExecuteNext(final String key, final Deque<Runnab
return;
}
}
executor.execute(
new Runnable() {
@Override
public void run() {
invokeCallbackAndExecuteNext(key, tasks);
}
});
execute(key, tasks);
}
}

Expand Down Expand Up @@ -199,18 +193,18 @@ public void cancel(Throwable e) {
return future;
}

protected void execute(final String key, final Deque<Runnable> finalTasks) {
protected void execute(final String key, final Deque<Runnable> tasks) {
executor.execute(
new Runnable() {
@Override
public void run() {
invokeCallback(finalTasks);
invokeCallback(tasks);
}
});
}

/** Executes the next queued task associated with {@code key}. */
void resume(final String key) {
private void resume(String key) {
Deque<Runnable> tasks;
synchronized (tasksByKey) {
tasks = tasksByKey.get(key);
Expand All @@ -222,19 +216,11 @@ void resume(final String key) {
return;
}
}
final Deque<Runnable> finalTasks = tasks;
// Run the next task.
executor.execute(
new Runnable() {
@Override
public void run() {
invokeCallback(finalTasks);
}
});
execute(key, tasks);
}

/** Cancels every task in the queue assoicated with {@code key}. */
void cancelQueuedTasks(final String key, Throwable e) {
private void cancelQueuedTasks(final String key, Throwable e) {
// TODO(kimkyung-goog): Ensure execute() fails once cancelQueueTasks() has been ever invoked,
// so that no more tasks are scheduled.
synchronized (tasksByKey) {
Expand Down