361 lines
14 KiB
Java
361 lines
14 KiB
Java
package io.grpc;
|
|
|
|
import com.google.common.base.MoreObjects;
|
|
import com.google.common.base.Objects;
|
|
import com.google.common.base.Preconditions;
|
|
import com.huawei.hms.support.feature.result.CommonConstant;
|
|
import java.lang.annotation.Documented;
|
|
import java.lang.annotation.Retention;
|
|
import java.lang.annotation.RetentionPolicy;
|
|
import java.net.URI;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public abstract class NameResolver {
|
|
|
|
/* loaded from: classes6.dex */
|
|
public static abstract class Factory {
|
|
public abstract String getDefaultScheme();
|
|
|
|
public abstract NameResolver newNameResolver(URI uri, Args args);
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
public interface Listener {
|
|
void onAddresses(List<EquivalentAddressGroup> list, Attributes attributes);
|
|
|
|
void onError(Status status);
|
|
}
|
|
|
|
@Documented
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
/* loaded from: classes.dex */
|
|
public @interface ResolutionResultAttr {
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
public static abstract class ServiceConfigParser {
|
|
public abstract ConfigOrError parseServiceConfig(Map<String, ?> map);
|
|
}
|
|
|
|
public abstract String getServiceAuthority();
|
|
|
|
public void refresh() {
|
|
}
|
|
|
|
public abstract void shutdown();
|
|
|
|
public void start(Listener listener) {
|
|
if (listener instanceof Listener2) {
|
|
start((Listener2) listener);
|
|
} else {
|
|
start(new Listener2(this, listener) { // from class: io.grpc.NameResolver.1
|
|
final NameResolver this$0;
|
|
final Listener val$listener;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$listener = listener;
|
|
}
|
|
|
|
@Override // io.grpc.NameResolver.Listener2, io.grpc.NameResolver.Listener
|
|
public void onError(Status status) {
|
|
this.val$listener.onError(status);
|
|
}
|
|
|
|
@Override // io.grpc.NameResolver.Listener2
|
|
public void onResult(ResolutionResult resolutionResult) {
|
|
this.val$listener.onAddresses(resolutionResult.getAddresses(), resolutionResult.getAttributes());
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public void start(Listener2 listener2) {
|
|
start((Listener) listener2);
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
public static abstract class Listener2 implements Listener {
|
|
@Override // io.grpc.NameResolver.Listener
|
|
public abstract void onError(Status status);
|
|
|
|
public abstract void onResult(ResolutionResult resolutionResult);
|
|
|
|
@Override // io.grpc.NameResolver.Listener
|
|
@Deprecated
|
|
public final void onAddresses(List<EquivalentAddressGroup> list, Attributes attributes) {
|
|
onResult(ResolutionResult.newBuilder().setAddresses(list).setAttributes(attributes).build());
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
public static final class Args {
|
|
private final ChannelLogger channelLogger;
|
|
private final int defaultPort;
|
|
private final Executor executor;
|
|
private final ProxyDetector proxyDetector;
|
|
private final ScheduledExecutorService scheduledExecutorService;
|
|
private final ServiceConfigParser serviceConfigParser;
|
|
private final SynchronizationContext syncContext;
|
|
|
|
private Args(Integer num, ProxyDetector proxyDetector, SynchronizationContext synchronizationContext, ServiceConfigParser serviceConfigParser, ScheduledExecutorService scheduledExecutorService, ChannelLogger channelLogger, Executor executor) {
|
|
this.defaultPort = ((Integer) Preconditions.checkNotNull(num, "defaultPort not set")).intValue();
|
|
this.proxyDetector = (ProxyDetector) Preconditions.checkNotNull(proxyDetector, "proxyDetector not set");
|
|
this.syncContext = (SynchronizationContext) Preconditions.checkNotNull(synchronizationContext, "syncContext not set");
|
|
this.serviceConfigParser = (ServiceConfigParser) Preconditions.checkNotNull(serviceConfigParser, "serviceConfigParser not set");
|
|
this.scheduledExecutorService = scheduledExecutorService;
|
|
this.channelLogger = channelLogger;
|
|
this.executor = executor;
|
|
}
|
|
|
|
public final ScheduledExecutorService getScheduledExecutorService() {
|
|
ScheduledExecutorService scheduledExecutorService = this.scheduledExecutorService;
|
|
if (scheduledExecutorService != null) {
|
|
return scheduledExecutorService;
|
|
}
|
|
throw new IllegalStateException("ScheduledExecutorService not set in Builder");
|
|
}
|
|
|
|
public final ChannelLogger getChannelLogger() {
|
|
ChannelLogger channelLogger = this.channelLogger;
|
|
if (channelLogger != null) {
|
|
return channelLogger;
|
|
}
|
|
throw new IllegalStateException("ChannelLogger is not set in Builder");
|
|
}
|
|
|
|
public final String toString() {
|
|
return MoreObjects.toStringHelper(this).add("defaultPort", this.defaultPort).add("proxyDetector", this.proxyDetector).add("syncContext", this.syncContext).add("serviceConfigParser", this.serviceConfigParser).add("scheduledExecutorService", this.scheduledExecutorService).add("channelLogger", this.channelLogger).add("executor", this.executor).toString();
|
|
}
|
|
|
|
public final Builder toBuilder() {
|
|
Builder builder = new Builder();
|
|
builder.setDefaultPort(this.defaultPort);
|
|
builder.setProxyDetector(this.proxyDetector);
|
|
builder.setSynchronizationContext(this.syncContext);
|
|
builder.setServiceConfigParser(this.serviceConfigParser);
|
|
builder.setScheduledExecutorService(this.scheduledExecutorService);
|
|
builder.setChannelLogger(this.channelLogger);
|
|
builder.setOffloadExecutor(this.executor);
|
|
return builder;
|
|
}
|
|
|
|
public static Builder newBuilder() {
|
|
return new Builder();
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
public static final class Builder {
|
|
private ChannelLogger channelLogger;
|
|
private Integer defaultPort;
|
|
private Executor executor;
|
|
private ProxyDetector proxyDetector;
|
|
private ScheduledExecutorService scheduledExecutorService;
|
|
private ServiceConfigParser serviceConfigParser;
|
|
private SynchronizationContext syncContext;
|
|
|
|
Builder() {
|
|
}
|
|
|
|
public final Builder setDefaultPort(int i) {
|
|
this.defaultPort = Integer.valueOf(i);
|
|
return this;
|
|
}
|
|
|
|
public final Builder setProxyDetector(ProxyDetector proxyDetector) {
|
|
this.proxyDetector = (ProxyDetector) Preconditions.checkNotNull(proxyDetector);
|
|
return this;
|
|
}
|
|
|
|
public final Builder setSynchronizationContext(SynchronizationContext synchronizationContext) {
|
|
this.syncContext = (SynchronizationContext) Preconditions.checkNotNull(synchronizationContext);
|
|
return this;
|
|
}
|
|
|
|
public final Builder setScheduledExecutorService(ScheduledExecutorService scheduledExecutorService) {
|
|
this.scheduledExecutorService = (ScheduledExecutorService) Preconditions.checkNotNull(scheduledExecutorService);
|
|
return this;
|
|
}
|
|
|
|
public final Builder setServiceConfigParser(ServiceConfigParser serviceConfigParser) {
|
|
this.serviceConfigParser = (ServiceConfigParser) Preconditions.checkNotNull(serviceConfigParser);
|
|
return this;
|
|
}
|
|
|
|
public final Builder setChannelLogger(ChannelLogger channelLogger) {
|
|
this.channelLogger = (ChannelLogger) Preconditions.checkNotNull(channelLogger);
|
|
return this;
|
|
}
|
|
|
|
public final Args build() {
|
|
return new Args(this.defaultPort, this.proxyDetector, this.syncContext, this.serviceConfigParser, this.scheduledExecutorService, this.channelLogger, this.executor);
|
|
}
|
|
|
|
public final Builder setOffloadExecutor(Executor executor) {
|
|
this.executor = executor;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public final SynchronizationContext getSynchronizationContext() {
|
|
return this.syncContext;
|
|
}
|
|
|
|
public final ServiceConfigParser getServiceConfigParser() {
|
|
return this.serviceConfigParser;
|
|
}
|
|
|
|
public final ProxyDetector getProxyDetector() {
|
|
return this.proxyDetector;
|
|
}
|
|
|
|
public final Executor getOffloadExecutor() {
|
|
return this.executor;
|
|
}
|
|
|
|
public final int getDefaultPort() {
|
|
return this.defaultPort;
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
public static final class ResolutionResult {
|
|
private final List<EquivalentAddressGroup> addresses;
|
|
private final Attributes attributes;
|
|
private final ConfigOrError serviceConfig;
|
|
|
|
ResolutionResult(List<EquivalentAddressGroup> list, Attributes attributes, ConfigOrError configOrError) {
|
|
this.addresses = Collections.unmodifiableList(new ArrayList(list));
|
|
this.attributes = (Attributes) Preconditions.checkNotNull(attributes, "attributes");
|
|
this.serviceConfig = configOrError;
|
|
}
|
|
|
|
public static Builder newBuilder() {
|
|
return new Builder();
|
|
}
|
|
|
|
public final Builder toBuilder() {
|
|
return newBuilder().setAddresses(this.addresses).setAttributes(this.attributes).setServiceConfig(this.serviceConfig);
|
|
}
|
|
|
|
public final String toString() {
|
|
return MoreObjects.toStringHelper(this).add("addresses", this.addresses).add("attributes", this.attributes).add("serviceConfig", this.serviceConfig).toString();
|
|
}
|
|
|
|
public final boolean equals(Object obj) {
|
|
if (!(obj instanceof ResolutionResult)) {
|
|
return false;
|
|
}
|
|
ResolutionResult resolutionResult = (ResolutionResult) obj;
|
|
return Objects.equal(this.addresses, resolutionResult.addresses) && Objects.equal(this.attributes, resolutionResult.attributes) && Objects.equal(this.serviceConfig, resolutionResult.serviceConfig);
|
|
}
|
|
|
|
public final int hashCode() {
|
|
return Objects.hashCode(this.addresses, this.attributes, this.serviceConfig);
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
public static final class Builder {
|
|
private List<EquivalentAddressGroup> addresses = Collections.emptyList();
|
|
private Attributes attributes = Attributes.EMPTY;
|
|
private ConfigOrError serviceConfig;
|
|
|
|
Builder() {
|
|
}
|
|
|
|
public final ResolutionResult build() {
|
|
return new ResolutionResult(this.addresses, this.attributes, this.serviceConfig);
|
|
}
|
|
|
|
public final Builder setServiceConfig(ConfigOrError configOrError) {
|
|
this.serviceConfig = configOrError;
|
|
return this;
|
|
}
|
|
|
|
public final Builder setAttributes(Attributes attributes) {
|
|
this.attributes = attributes;
|
|
return this;
|
|
}
|
|
|
|
public final Builder setAddresses(List<EquivalentAddressGroup> list) {
|
|
this.addresses = list;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public final ConfigOrError getServiceConfig() {
|
|
return this.serviceConfig;
|
|
}
|
|
|
|
public final Attributes getAttributes() {
|
|
return this.attributes;
|
|
}
|
|
|
|
public final List<EquivalentAddressGroup> getAddresses() {
|
|
return this.addresses;
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
public static final class ConfigOrError {
|
|
static final boolean $assertionsDisabled = false;
|
|
private final Object config;
|
|
private final Status status;
|
|
|
|
public static ConfigOrError fromConfig(Object obj) {
|
|
return new ConfigOrError(obj);
|
|
}
|
|
|
|
public static ConfigOrError fromError(Status status) {
|
|
return new ConfigOrError(status);
|
|
}
|
|
|
|
private ConfigOrError(Object obj) {
|
|
this.config = Preconditions.checkNotNull(obj, "config");
|
|
this.status = null;
|
|
}
|
|
|
|
private ConfigOrError(Status status) {
|
|
this.config = null;
|
|
this.status = (Status) Preconditions.checkNotNull(status, CommonConstant.KEY_STATUS);
|
|
Preconditions.checkArgument(!status.isOk(), "cannot use OK status: %s", status);
|
|
}
|
|
|
|
public final boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (obj == null || getClass() != obj.getClass()) {
|
|
return false;
|
|
}
|
|
ConfigOrError configOrError = (ConfigOrError) obj;
|
|
return Objects.equal(this.status, configOrError.status) && Objects.equal(this.config, configOrError.config);
|
|
}
|
|
|
|
public final int hashCode() {
|
|
return Objects.hashCode(this.status, this.config);
|
|
}
|
|
|
|
public final String toString() {
|
|
if (this.config != null) {
|
|
return MoreObjects.toStringHelper(this).add("config", this.config).toString();
|
|
}
|
|
return MoreObjects.toStringHelper(this).add("error", this.status).toString();
|
|
}
|
|
|
|
public final Status getError() {
|
|
return this.status;
|
|
}
|
|
|
|
public final Object getConfig() {
|
|
return this.config;
|
|
}
|
|
}
|
|
}
|