88 lines
3 KiB
Java
88 lines
3 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*/
|
|
package com.google.common.util.concurrent;
|
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import com.google.common.base.Preconditions;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import javax.annotation.Nullable;
|
|
import javax.annotation.concurrent.GuardedBy;
|
|
|
|
public final class ExecutionList {
|
|
@VisibleForTesting
|
|
static final Logger log = Logger.getLogger(ExecutionList.class.getName());
|
|
@GuardedBy(value="this")
|
|
private RunnableExecutorPair runnables;
|
|
@GuardedBy(value="this")
|
|
private boolean executed;
|
|
|
|
/*
|
|
* WARNING - Removed try catching itself - possible behaviour change.
|
|
*/
|
|
public void add(Runnable runnable, Executor executor) {
|
|
Preconditions.checkNotNull(runnable, "Runnable was null.");
|
|
Preconditions.checkNotNull(executor, "Executor was null.");
|
|
ExecutionList executionList = this;
|
|
synchronized (executionList) {
|
|
if (!this.executed) {
|
|
this.runnables = new RunnableExecutorPair(runnable, executor, this.runnables);
|
|
return;
|
|
}
|
|
}
|
|
ExecutionList.executeListener(runnable, executor);
|
|
}
|
|
|
|
/*
|
|
* WARNING - Removed try catching itself - possible behaviour change.
|
|
*/
|
|
public void execute() {
|
|
RunnableExecutorPair list;
|
|
ExecutionList executionList = this;
|
|
synchronized (executionList) {
|
|
if (this.executed) {
|
|
return;
|
|
}
|
|
this.executed = true;
|
|
list = this.runnables;
|
|
this.runnables = null;
|
|
}
|
|
RunnableExecutorPair reversedList = null;
|
|
while (list != null) {
|
|
RunnableExecutorPair tmp = list;
|
|
list = list.next;
|
|
tmp.next = reversedList;
|
|
reversedList = tmp;
|
|
}
|
|
while (reversedList != null) {
|
|
ExecutionList.executeListener(reversedList.runnable, reversedList.executor);
|
|
reversedList = reversedList.next;
|
|
}
|
|
}
|
|
|
|
private static void executeListener(Runnable runnable, Executor executor) {
|
|
try {
|
|
executor.execute(runnable);
|
|
}
|
|
catch (RuntimeException e) {
|
|
String string = String.valueOf(String.valueOf(runnable));
|
|
String string2 = String.valueOf(String.valueOf(executor));
|
|
log.log(Level.SEVERE, new StringBuilder(57 + string.length() + string2.length()).append("RuntimeException while executing runnable ").append(string).append(" with executor ").append(string2).toString(), e);
|
|
}
|
|
}
|
|
|
|
private static final class RunnableExecutorPair {
|
|
final Runnable runnable;
|
|
final Executor executor;
|
|
@Nullable
|
|
RunnableExecutorPair next;
|
|
|
|
RunnableExecutorPair(Runnable runnable, Executor executor, RunnableExecutorPair next) {
|
|
this.runnable = runnable;
|
|
this.executor = executor;
|
|
this.next = next;
|
|
}
|
|
}
|
|
}
|