what-the-bank/sources/com/google/common/util/concurrent/AbstractExecutionThreadServ...

180 lines
6.3 KiB
Java

package com.google.common.util.concurrent;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.Service;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
/* loaded from: classes2.dex */
public abstract class AbstractExecutionThreadService implements Service {
private static final Logger logger = Logger.getLogger(AbstractExecutionThreadService.class.getName());
private final Service delegate = new AnonymousClass1(this);
protected abstract void run() throws Exception;
protected void shutDown() throws Exception {
}
protected void startUp() throws Exception {
}
protected void triggerShutdown() {
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: com.google.common.util.concurrent.AbstractExecutionThreadService$1, reason: invalid class name */
/* loaded from: classes2.dex */
public class AnonymousClass1 extends AbstractService {
final AbstractExecutionThreadService this$0;
AnonymousClass1(AbstractExecutionThreadService abstractExecutionThreadService) {
this.this$0 = abstractExecutionThreadService;
}
@Override // com.google.common.util.concurrent.AbstractService
protected final void doStart() {
MoreExecutors.renamingDecorator(this.this$0.executor(), new Supplier<String>(this) { // from class: com.google.common.util.concurrent.AbstractExecutionThreadService.1.1
final AnonymousClass1 this$1;
{
this.this$1 = this;
}
@Override // com.google.common.base.Supplier
public String get() {
return this.this$1.this$0.serviceName();
}
}).execute(new Runnable(this) { // from class: com.google.common.util.concurrent.AbstractExecutionThreadService.1.2
final AnonymousClass1 this$1;
{
this.this$1 = this;
}
@Override // java.lang.Runnable
public void run() {
try {
this.this$1.this$0.startUp();
this.this$1.notifyStarted();
if (this.this$1.isRunning()) {
try {
this.this$1.this$0.run();
} catch (Throwable th) {
try {
this.this$1.this$0.shutDown();
} catch (Exception e) {
AbstractExecutionThreadService.logger.log(Level.WARNING, "Error while attempting to shut down the service after failure.", (Throwable) e);
}
this.this$1.notifyFailed(th);
return;
}
}
this.this$1.this$0.shutDown();
this.this$1.notifyStopped();
} catch (Throwable th2) {
this.this$1.notifyFailed(th2);
}
}
});
}
@Override // com.google.common.util.concurrent.AbstractService
protected void doStop() {
this.this$0.triggerShutdown();
}
@Override // com.google.common.util.concurrent.AbstractService
public String toString() {
return this.this$0.toString();
}
}
protected AbstractExecutionThreadService() {
}
protected Executor executor() {
return new Executor(this) { // from class: com.google.common.util.concurrent.AbstractExecutionThreadService.2
final AbstractExecutionThreadService this$0;
{
this.this$0 = this;
}
@Override // java.util.concurrent.Executor
public void execute(Runnable runnable) {
MoreExecutors.newThread(this.this$0.serviceName(), runnable).start();
}
};
}
public String toString() {
String serviceName = serviceName();
String valueOf = String.valueOf(state());
StringBuilder sb = new StringBuilder(String.valueOf(serviceName).length() + 3 + String.valueOf(valueOf).length());
sb.append(serviceName);
sb.append(" [");
sb.append(valueOf);
sb.append("]");
return sb.toString();
}
@Override // com.google.common.util.concurrent.Service
public final boolean isRunning() {
return this.delegate.isRunning();
}
@Override // com.google.common.util.concurrent.Service
public final Service.State state() {
return this.delegate.state();
}
@Override // com.google.common.util.concurrent.Service
public final void addListener(Service.Listener listener, Executor executor) {
this.delegate.addListener(listener, executor);
}
@Override // com.google.common.util.concurrent.Service
public final Throwable failureCause() {
return this.delegate.failureCause();
}
@Override // com.google.common.util.concurrent.Service
public final Service startAsync() {
this.delegate.startAsync();
return this;
}
@Override // com.google.common.util.concurrent.Service
public final Service stopAsync() {
this.delegate.stopAsync();
return this;
}
@Override // com.google.common.util.concurrent.Service
public final void awaitRunning() {
this.delegate.awaitRunning();
}
@Override // com.google.common.util.concurrent.Service
public final void awaitRunning(long j, TimeUnit timeUnit) throws TimeoutException {
this.delegate.awaitRunning(j, timeUnit);
}
@Override // com.google.common.util.concurrent.Service
public final void awaitTerminated() {
this.delegate.awaitTerminated();
}
@Override // com.google.common.util.concurrent.Service
public final void awaitTerminated(long j, TimeUnit timeUnit) throws TimeoutException {
this.delegate.awaitTerminated(j, timeUnit);
}
protected String serviceName() {
return getClass().getSimpleName();
}
}