导航菜单

页面标题

页面副标题

⁣逼‌多​多⁣ v3.6.2 - LoadBalancer.java 源代码

正在查看: ⁣逼‌多​多⁣ v3.6.2 应用的 LoadBalancer.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package io.grpc;

import io.grpc.Attributes;
import io.grpc.ClientStreamTracer;
import io.grpc.NameResolver;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import q.g;
import q.i;
import q.l;

@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
public abstract class LoadBalancer {
    private int recursionCount;

    @Internal
    public static final Attributes.Key<Map<String, ?>> ATTR_HEALTH_CHECKING_CONFIG = Attributes.Key.create("internal:health-checking-config");

    @Internal
    public static final CreateSubchannelArgs.Key<SubchannelStateListener> HEALTH_CONSUMER_LISTENER_ARG_KEY = CreateSubchannelArgs.Key.create("internal:health-check-consumer-listener");

    @Internal
    public static final Attributes.Key<Boolean> HAS_HEALTH_PRODUCER_LISTENER_KEY = Attributes.Key.create("internal:has-health-check-producer-listener");
    public static final Attributes.Key<Boolean> IS_PETIOLE_POLICY = Attributes.Key.create("io.grpc.IS_PETIOLE_POLICY");

    @Deprecated
    public static final SubchannelPicker EMPTY_PICKER = new SubchannelPicker() {
        @Override
        public PickResult pickSubchannel(PickSubchannelArgs pickSubchannelArgs) {
            return PickResult.withNoResult();
        }

        public String toString() {
            return "EMPTY_PICKER";
        }
    };

    @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
    public static final class CreateSubchannelArgs {
        private final List<EquivalentAddressGroup> addrs;
        private final Attributes attrs;
        private final Object[][] customOptions;

        @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
        public static final class Builder {
            private List<EquivalentAddressGroup> addrs;
            private Attributes attrs = Attributes.EMPTY;
            private Object[][] customOptions = (Object[][]) Array.newInstance((Class<?>) Object.class, 0, 2);

            Builder() {
            }

            public Builder copyCustomOptions(Object[][] objArr) {
                Object[][] objArr2 = (Object[][]) Array.newInstance((Class<?>) Object.class, objArr.length, 2);
                this.customOptions = objArr2;
                System.arraycopy(objArr, 0, objArr2, 0, objArr.length);
                return this;
            }

            public <T> Builder addOption(Key<T> key, T t) {
                l.o(key, "key");
                l.o(t, "value");
                int i = 0;
                while (true) {
                    Object[][] objArr = this.customOptions;
                    if (i >= objArr.length) {
                        i = -1;
                        break;
                    }
                    if (key.equals(objArr[i][0])) {
                        break;
                    }
                    i++;
                }
                if (i == -1) {
                    Object[][] objArr2 = (Object[][]) Array.newInstance((Class<?>) Object.class, this.customOptions.length + 1, 2);
                    Object[][] objArr3 = this.customOptions;
                    System.arraycopy(objArr3, 0, objArr2, 0, objArr3.length);
                    this.customOptions = objArr2;
                    i = objArr2.length - 1;
                }
                this.customOptions[i] = new Object[]{key, t};
                return this;
            }

            public CreateSubchannelArgs build() {
                return new CreateSubchannelArgs(this.addrs, this.attrs, this.customOptions);
            }

            public Builder setAddresses(EquivalentAddressGroup equivalentAddressGroup) {
                this.addrs = Collections.singletonList(equivalentAddressGroup);
                return this;
            }

            public Builder setAttributes(Attributes attributes) {
                this.attrs = (Attributes) l.o(attributes, "attrs");
                return this;
            }

            public Builder setAddresses(List<EquivalentAddressGroup> list) {
                l.e(!list.isEmpty(), "addrs is empty");
                this.addrs = Collections.unmodifiableList(new ArrayList(list));
                return this;
            }
        }

        @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
        public static final class Key<T> {
            private final String debugString;
            private final T defaultValue;

            private Key(String str, T t) {
                this.debugString = str;
                this.defaultValue = t;
            }

            public static <T> Key<T> create(String str) {
                l.o(str, "debugString");
                return new Key<>(str, null);
            }

            public static <T> Key<T> createWithDefault(String str, T t) {
                l.o(str, "debugString");
                return new Key<>(str, t);
            }

            public T getDefault() {
                return this.defaultValue;
            }

            public String toString() {
                return this.debugString;
            }
        }

        public static Builder newBuilder() {
            return new Builder();
        }

        public List<EquivalentAddressGroup> getAddresses() {
            return this.addrs;
        }

        public Attributes getAttributes() {
            return this.attrs;
        }

        public <T> T getOption(Key<T> key) {
            l.o(key, "key");
            int i = 0;
            while (true) {
                Object[][] objArr = this.customOptions;
                if (i >= objArr.length) {
                    return (T) ((Key) key).defaultValue;
                }
                if (key.equals(objArr[i][0])) {
                    return (T) this.customOptions[i][1];
                }
                i++;
            }
        }

        public Builder toBuilder() {
            return newBuilder().setAddresses(this.addrs).setAttributes(this.attrs).copyCustomOptions(this.customOptions);
        }

        public String toString() {
            return g.c(this).d("addrs", this.addrs).d("attrs", this.attrs).d("customOptions", Arrays.deepToString(this.customOptions)).toString();
        }

        private CreateSubchannelArgs(List<EquivalentAddressGroup> list, Attributes attributes, Object[][] objArr) {
            this.addrs = (List) l.o(list, "addresses are not set");
            this.attrs = (Attributes) l.o(attributes, "attrs");
            this.customOptions = (Object[][]) l.o(objArr, "customOptions");
        }
    }

    @Deprecated
    public static final class ErrorPicker extends SubchannelPicker {
        private final Status error;

        public ErrorPicker(Status status) {
            this.error = (Status) l.o(status, "error");
        }

        @Override
        public PickResult pickSubchannel(PickSubchannelArgs pickSubchannelArgs) {
            return PickResult.withError(this.error);
        }

        public String toString() {
            return g.c(this).d("error", this.error).toString();
        }
    }

    @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
    public static abstract class Factory {
        public abstract LoadBalancer newLoadBalancer(Helper helper);
    }

    public static final class FixedResultPicker extends SubchannelPicker {
        private final PickResult result;

        public FixedResultPicker(PickResult pickResult) {
            this.result = (PickResult) l.o(pickResult, "result");
        }

        @Override
        public PickResult pickSubchannel(PickSubchannelArgs pickSubchannelArgs) {
            return this.result;
        }

        public String toString() {
            return "FixedResultPicker(" + this.result + ")";
        }
    }

    @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
    public static abstract class Helper {
        public abstract ManagedChannel createOobChannel(EquivalentAddressGroup equivalentAddressGroup, String str);

        public ManagedChannel createOobChannel(List<EquivalentAddressGroup> list, String str) {
            throw new UnsupportedOperationException();
        }

        public ManagedChannel createResolvingOobChannel(String str) {
            return createResolvingOobChannelBuilder(str).build();
        }

        @Deprecated
        public ManagedChannelBuilder<?> createResolvingOobChannelBuilder(String str) {
            throw new UnsupportedOperationException("Not implemented");
        }

        public Subchannel createSubchannel(CreateSubchannelArgs createSubchannelArgs) {
            throw new UnsupportedOperationException();
        }

        public abstract String getAuthority();

        public ChannelCredentials getChannelCredentials() {
            return getUnsafeChannelCredentials().withoutBearerTokens();
        }

        public ChannelLogger getChannelLogger() {
            throw new UnsupportedOperationException();
        }

        public String getChannelTarget() {
            throw new UnsupportedOperationException();
        }

        @Internal
        public MetricRecorder getMetricRecorder() {
            return new MetricRecorder() {
            };
        }

        public NameResolver.Args getNameResolverArgs() {
            throw new UnsupportedOperationException();
        }

        public NameResolverRegistry getNameResolverRegistry() {
            throw new UnsupportedOperationException();
        }

        public ScheduledExecutorService getScheduledExecutorService() {
            throw new UnsupportedOperationException();
        }

        public SynchronizationContext getSynchronizationContext() {
            throw new UnsupportedOperationException();
        }

        public ChannelCredentials getUnsafeChannelCredentials() {
            throw new UnsupportedOperationException();
        }

        @ExperimentalApi("https://github.com/grpc/grpc-java/issues/8088")
        @Deprecated
        public void ignoreRefreshNameResolutionCheck() {
        }

        public void refreshNameResolution() {
            throw new UnsupportedOperationException();
        }

        public abstract void updateBalancingState(ConnectivityState connectivityState, SubchannelPicker subchannelPicker);

        public void updateOobChannelAddresses(ManagedChannel managedChannel, EquivalentAddressGroup equivalentAddressGroup) {
            throw new UnsupportedOperationException();
        }

        public ManagedChannelBuilder<?> createResolvingOobChannelBuilder(String str, ChannelCredentials channelCredentials) {
            throw new UnsupportedOperationException();
        }

        public void updateOobChannelAddresses(ManagedChannel managedChannel, List<EquivalentAddressGroup> list) {
            throw new UnsupportedOperationException();
        }
    }

    @Internal
    public interface PickDetailsConsumer {
        default void addOptionalLabel(String str, String str2) {
            l.o(str, "key");
            l.o(str2, "value");
        }
    }

    @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
    public static abstract class PickSubchannelArgs {
        public abstract CallOptions getCallOptions();

        public abstract Metadata getHeaders();

        public abstract MethodDescriptor<?, ?> getMethodDescriptor();

        @Internal
        public PickDetailsConsumer getPickDetailsConsumer() {
            return new PickDetailsConsumer() {
            };
        }
    }

    @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
    public static final class ResolvedAddresses {
        private final List<EquivalentAddressGroup> addresses;
        private final Attributes attributes;
        private final Object loadBalancingPolicyConfig;

        @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
        public static final class Builder {
            private List<EquivalentAddressGroup> addresses;
            private Attributes attributes = Attributes.EMPTY;
            private Object loadBalancingPolicyConfig;

            Builder() {
            }

            public ResolvedAddresses build() {
                return new ResolvedAddresses(this.addresses, this.attributes, this.loadBalancingPolicyConfig);
            }

            public Builder setAddresses(List<EquivalentAddressGroup> list) {
                this.addresses = list;
                return this;
            }

            public Builder setAttributes(Attributes attributes) {
                this.attributes = attributes;
                return this;
            }

            public Builder setLoadBalancingPolicyConfig(Object obj) {
                this.loadBalancingPolicyConfig = obj;
                return this;
            }
        }

        public static Builder newBuilder() {
            return new Builder();
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof ResolvedAddresses)) {
                return false;
            }
            ResolvedAddresses resolvedAddresses = (ResolvedAddresses) obj;
            return i.a(this.addresses, resolvedAddresses.addresses) && i.a(this.attributes, resolvedAddresses.attributes) && i.a(this.loadBalancingPolicyConfig, resolvedAddresses.loadBalancingPolicyConfig);
        }

        public List<EquivalentAddressGroup> getAddresses() {
            return this.addresses;
        }

        public Attributes getAttributes() {
            return this.attributes;
        }

        public Object getLoadBalancingPolicyConfig() {
            return this.loadBalancingPolicyConfig;
        }

        public int hashCode() {
            return i.b(new Object[]{this.addresses, this.attributes, this.loadBalancingPolicyConfig});
        }

        public Builder toBuilder() {
            return newBuilder().setAddresses(this.addresses).setAttributes(this.attributes).setLoadBalancingPolicyConfig(this.loadBalancingPolicyConfig);
        }

        public String toString() {
            return g.c(this).d("addresses", this.addresses).d("attributes", this.attributes).d("loadBalancingPolicyConfig", this.loadBalancingPolicyConfig).toString();
        }

        private ResolvedAddresses(List<EquivalentAddressGroup> list, Attributes attributes, Object obj) {
            this.addresses = Collections.unmodifiableList(new ArrayList((Collection) l.o(list, "addresses")));
            this.attributes = (Attributes) l.o(attributes, "attributes");
            this.loadBalancingPolicyConfig = obj;
        }
    }

    @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
    public static abstract class Subchannel {
        @Internal
        public Channel asChannel() {
            throw new UnsupportedOperationException();
        }

        public final io.grpc.EquivalentAddressGroup getAddresses() {
            throw new UnsupportedOperationException("Method not decompiled: io.grpc.LoadBalancer.Subchannel.getAddresses():io.grpc.EquivalentAddressGroup");
        }

        public List<EquivalentAddressGroup> getAllAddresses() {
            throw new UnsupportedOperationException();
        }

        public abstract Attributes getAttributes();

        public ChannelLogger getChannelLogger() {
            throw new UnsupportedOperationException();
        }

        @Internal
        public Object getInternalSubchannel() {
            throw new UnsupportedOperationException();
        }

        public abstract void requestConnection();

        public abstract void shutdown();

        public void start(SubchannelStateListener subchannelStateListener) {
            throw new UnsupportedOperationException("Not implemented");
        }

        public void updateAddresses(List<EquivalentAddressGroup> list) {
            throw new UnsupportedOperationException();
        }
    }

    @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
    public static abstract class SubchannelPicker {
        public abstract PickResult pickSubchannel(PickSubchannelArgs pickSubchannelArgs);

        @Deprecated
        public void requestConnection() {
        }
    }

    public interface SubchannelStateListener {
        void onSubchannelState(ConnectivityStateInfo connectivityStateInfo);
    }

    public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
        if (!resolvedAddresses.getAddresses().isEmpty() || canHandleEmptyAddressListFromNameResolution()) {
            int i = this.recursionCount;
            this.recursionCount = i + 1;
            if (i == 0) {
                handleResolvedAddresses(resolvedAddresses);
            }
            this.recursionCount = 0;
            return Status.OK;
        }
        Status withDescription = Status.UNAVAILABLE.withDescription("NameResolver returned no usable address. addrs=" + resolvedAddresses.getAddresses() + ", attrs=" + resolvedAddresses.getAttributes());
        handleNameResolutionError(withDescription);
        return withDescription;
    }

    public boolean canHandleEmptyAddressListFromNameResolution() {
        return false;
    }

    public abstract void handleNameResolutionError(Status status);

    public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) {
        int i = this.recursionCount;
        this.recursionCount = i + 1;
        if (i == 0) {
            acceptResolvedAddresses(resolvedAddresses);
        }
        this.recursionCount = 0;
    }

    @Deprecated
    public void handleSubchannelState(Subchannel subchannel, ConnectivityStateInfo connectivityStateInfo) {
    }

    public void requestConnection() {
    }

    public abstract void shutdown();

    @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
    public static final class PickResult {
        private static final PickResult NO_RESULT = new PickResult(null, null, Status.OK, false);
        private final boolean drop;
        private final Status status;
        private final ClientStreamTracer.Factory streamTracerFactory;
        private final Subchannel subchannel;

        private PickResult(Subchannel subchannel, ClientStreamTracer.Factory factory, Status status, boolean z) {
            this.subchannel = subchannel;
            this.streamTracerFactory = factory;
            this.status = (Status) l.o(status, "status");
            this.drop = z;
        }

        public static PickResult withDrop(Status status) {
            l.e(!status.isOk(), "drop status shouldn't be OK");
            return new PickResult(null, null, status, true);
        }

        public static PickResult withError(Status status) {
            l.e(!status.isOk(), "error status shouldn't be OK");
            return new PickResult(null, null, status, false);
        }

        public static PickResult withNoResult() {
            return NO_RESULT;
        }

        public static PickResult withSubchannel(Subchannel subchannel, ClientStreamTracer.Factory factory) {
            return new PickResult((Subchannel) l.o(subchannel, "subchannel"), factory, Status.OK, false);
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof PickResult)) {
                return false;
            }
            PickResult pickResult = (PickResult) obj;
            return i.a(this.subchannel, pickResult.subchannel) && i.a(this.status, pickResult.status) && i.a(this.streamTracerFactory, pickResult.streamTracerFactory) && this.drop == pickResult.drop;
        }

        public Status getStatus() {
            return this.status;
        }

        public ClientStreamTracer.Factory getStreamTracerFactory() {
            return this.streamTracerFactory;
        }

        public Subchannel getSubchannel() {
            return this.subchannel;
        }

        public boolean hasResult() {
            return (this.subchannel == null && this.status.isOk()) ? false : true;
        }

        public int hashCode() {
            return i.b(new Object[]{this.subchannel, this.status, this.streamTracerFactory, Boolean.valueOf(this.drop)});
        }

        public boolean isDrop() {
            return this.drop;
        }

        public String toString() {
            return g.c(this).d("subchannel", this.subchannel).d("streamTracerFactory", this.streamTracerFactory).d("status", this.status).e("drop", this.drop).toString();
        }

        public static PickResult withSubchannel(Subchannel subchannel) {
            return withSubchannel(subchannel, null);
        }
    }
}