181 lines
6.1 KiB
Java
181 lines
6.1 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;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public abstract class AbstractIdleService implements Service {
|
||
|
private final Service delegate;
|
||
|
private final Supplier<String> threadNameSupplier;
|
||
|
|
||
|
protected abstract void shutDown() throws Exception;
|
||
|
|
||
|
protected abstract void startUp() throws Exception;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
final class ThreadNameSupplier implements Supplier<String> {
|
||
|
final AbstractIdleService this$0;
|
||
|
|
||
|
private ThreadNameSupplier(AbstractIdleService abstractIdleService) {
|
||
|
this.this$0 = abstractIdleService;
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.base.Supplier
|
||
|
public final String get() {
|
||
|
String serviceName = this.this$0.serviceName();
|
||
|
String valueOf = String.valueOf(this.this$0.state());
|
||
|
StringBuilder sb = new StringBuilder(String.valueOf(serviceName).length() + 1 + String.valueOf(valueOf).length());
|
||
|
sb.append(serviceName);
|
||
|
sb.append(" ");
|
||
|
sb.append(valueOf);
|
||
|
return sb.toString();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
final class DelegateService extends AbstractService {
|
||
|
final AbstractIdleService this$0;
|
||
|
|
||
|
private DelegateService(AbstractIdleService abstractIdleService) {
|
||
|
this.this$0 = abstractIdleService;
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.util.concurrent.AbstractService
|
||
|
protected final void doStart() {
|
||
|
MoreExecutors.renamingDecorator(this.this$0.executor(), (Supplier<String>) this.this$0.threadNameSupplier).execute(new Runnable(this) { // from class: com.google.common.util.concurrent.AbstractIdleService.DelegateService.1
|
||
|
final DelegateService this$1;
|
||
|
|
||
|
{
|
||
|
this.this$1 = this;
|
||
|
}
|
||
|
|
||
|
@Override // java.lang.Runnable
|
||
|
public void run() {
|
||
|
try {
|
||
|
this.this$1.this$0.startUp();
|
||
|
this.this$1.notifyStarted();
|
||
|
} catch (Throwable th) {
|
||
|
this.this$1.notifyFailed(th);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.util.concurrent.AbstractService
|
||
|
protected final void doStop() {
|
||
|
MoreExecutors.renamingDecorator(this.this$0.executor(), (Supplier<String>) this.this$0.threadNameSupplier).execute(new Runnable(this) { // from class: com.google.common.util.concurrent.AbstractIdleService.DelegateService.2
|
||
|
final DelegateService this$1;
|
||
|
|
||
|
{
|
||
|
this.this$1 = this;
|
||
|
}
|
||
|
|
||
|
@Override // java.lang.Runnable
|
||
|
public void run() {
|
||
|
try {
|
||
|
this.this$1.this$0.shutDown();
|
||
|
this.this$1.notifyStopped();
|
||
|
} catch (Throwable th) {
|
||
|
this.this$1.notifyFailed(th);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.util.concurrent.AbstractService
|
||
|
public final String toString() {
|
||
|
return this.this$0.toString();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected AbstractIdleService() {
|
||
|
this.threadNameSupplier = new ThreadNameSupplier();
|
||
|
this.delegate = new DelegateService();
|
||
|
}
|
||
|
|
||
|
protected Executor executor() {
|
||
|
return new Executor(this) { // from class: com.google.common.util.concurrent.AbstractIdleService.1
|
||
|
final AbstractIdleService this$0;
|
||
|
|
||
|
{
|
||
|
this.this$0 = this;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.concurrent.Executor
|
||
|
public void execute(Runnable runnable) {
|
||
|
MoreExecutors.newThread((String) this.this$0.threadNameSupplier.get(), 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();
|
||
|
}
|
||
|
}
|