mirror of https://github.com/grpc/grpc-java.git
core: move NameResolverProvider to internal
This commit is contained in:
parent
851065dd08
commit
9c6ea274fe
|
|
@ -162,7 +162,7 @@ public abstract class ManagedChannelBuilder<T extends ManagedChannelBuilder<T>>
|
||||||
* Provides a custom {@link NameResolver.Factory} for the channel.
|
* Provides a custom {@link NameResolver.Factory} for the channel.
|
||||||
*
|
*
|
||||||
* <p>If this method is not called, the builder will try the providers listed by {@link
|
* <p>If this method is not called, the builder will try the providers listed by {@link
|
||||||
* NameResolverProvider#providers()} for the given target.
|
* io.grpc.internal.NameResolverProvider#providers()} for the given target.
|
||||||
*
|
*
|
||||||
* @return this
|
* @return this
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ import io.grpc.LoadBalancer;
|
||||||
import io.grpc.ManagedChannel;
|
import io.grpc.ManagedChannel;
|
||||||
import io.grpc.ManagedChannelBuilder;
|
import io.grpc.ManagedChannelBuilder;
|
||||||
import io.grpc.NameResolver;
|
import io.grpc.NameResolver;
|
||||||
import io.grpc.NameResolverProvider;
|
|
||||||
import io.grpc.PickFirstBalancerFactory;
|
import io.grpc.PickFirstBalancerFactory;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package io.grpc.internal;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import io.grpc.Attributes;
|
import io.grpc.Attributes;
|
||||||
import io.grpc.NameResolverProvider;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -60,12 +59,12 @@ public final class DnsNameResolverProvider extends NameResolverProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int priority() {
|
public int priority() {
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,12 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc;
|
package io.grpc.internal;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import io.grpc.Attributes;
|
||||||
|
import io.grpc.NameResolver;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
@ -33,7 +35,6 @@ import java.util.ServiceLoader;
|
||||||
* exceptions may reasonably occur for implementation-specific reasons, implementations should
|
* exceptions may reasonably occur for implementation-specific reasons, implementations should
|
||||||
* generally handle the exception gracefully and return {@code false} from {@link #isAvailable()}.
|
* generally handle the exception gracefully and return {@code false} from {@link #isAvailable()}.
|
||||||
*/
|
*/
|
||||||
@Internal
|
|
||||||
public abstract class NameResolverProvider extends NameResolver.Factory {
|
public abstract class NameResolverProvider extends NameResolver.Factory {
|
||||||
/**
|
/**
|
||||||
* The port number used in case the target or the underlying naming system doesn't provide a
|
* The port number used in case the target or the underlying naming system doesn't provide a
|
||||||
|
|
@ -145,7 +146,7 @@ public abstract class NameResolverProvider extends NameResolver.Factory {
|
||||||
* Whether this provider is available for use, taking the current environment into consideration.
|
* Whether this provider is available for use, taking the current environment into consideration.
|
||||||
* If {@code false}, no other methods are safe to be called.
|
* If {@code false}, no other methods are safe to be called.
|
||||||
*/
|
*/
|
||||||
protected abstract boolean isAvailable();
|
public abstract boolean isAvailable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A priority, from 0 to 10 that this provider should be used, taking the current environment into
|
* A priority, from 0 to 10 that this provider should be used, taking the current environment into
|
||||||
|
|
@ -153,7 +154,7 @@ public abstract class NameResolverProvider extends NameResolver.Factory {
|
||||||
* detection. A priority of 0 does not imply that the provider wouldn't work; just that it should
|
* detection. A priority of 0 does not imply that the provider wouldn't work; just that it should
|
||||||
* be last in line.
|
* be last in line.
|
||||||
*/
|
*/
|
||||||
protected abstract int priority();
|
public abstract int priority();
|
||||||
|
|
||||||
private static class NameResolverFactory extends NameResolver.Factory {
|
private static class NameResolverFactory extends NameResolver.Factory {
|
||||||
private final List<NameResolverProvider> providers;
|
private final List<NameResolverProvider> providers;
|
||||||
|
|
@ -22,7 +22,6 @@ import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import io.grpc.Attributes;
|
import io.grpc.Attributes;
|
||||||
import io.grpc.NameResolverProvider;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc;
|
package io.grpc.internal;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
@ -24,7 +24,9 @@ import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
import io.grpc.internal.DnsNameResolverProvider;
|
import io.grpc.Attributes;
|
||||||
|
import io.grpc.NameResolver;
|
||||||
|
import io.grpc.ReplacingClassLoader;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -36,7 +38,7 @@ import org.junit.runners.JUnit4;
|
||||||
/** Unit tests for {@link NameResolverProvider}. */
|
/** Unit tests for {@link NameResolverProvider}. */
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class NameResolverProviderTest {
|
public class NameResolverProviderTest {
|
||||||
private final String serviceFile = "META-INF/services/io.grpc.NameResolverProvider";
|
private final String serviceFile = "META-INF/services/io.grpc.internal.NameResolverProvider";
|
||||||
private final URI uri = URI.create("dns:///localhost");
|
private final URI uri = URI.create("dns:///localhost");
|
||||||
private final Attributes attributes = Attributes.EMPTY;
|
private final Attributes attributes = Attributes.EMPTY;
|
||||||
|
|
||||||
|
|
@ -44,7 +46,7 @@ public class NameResolverProviderTest {
|
||||||
public void noProvider() {
|
public void noProvider() {
|
||||||
ClassLoader cl = new ReplacingClassLoader(
|
ClassLoader cl = new ReplacingClassLoader(
|
||||||
getClass().getClassLoader(), serviceFile,
|
getClass().getClassLoader(), serviceFile,
|
||||||
"io/grpc/NameResolverProviderTest-doesNotExist.txt");
|
"io/grpc/internal/NameResolverProviderTest-doesNotExist.txt");
|
||||||
List<NameResolverProvider> providers = NameResolverProvider.load(cl);
|
List<NameResolverProvider> providers = NameResolverProvider.load(cl);
|
||||||
assertEquals(Collections.<NameResolverProvider>emptyList(), providers);
|
assertEquals(Collections.<NameResolverProvider>emptyList(), providers);
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +55,7 @@ public class NameResolverProviderTest {
|
||||||
public void multipleProvider() {
|
public void multipleProvider() {
|
||||||
ClassLoader cl = new ReplacingClassLoader(
|
ClassLoader cl = new ReplacingClassLoader(
|
||||||
getClass().getClassLoader(), serviceFile,
|
getClass().getClassLoader(), serviceFile,
|
||||||
"io/grpc/NameResolverProviderTest-multipleProvider.txt");
|
"io/grpc/internal/NameResolverProviderTest-multipleProvider.txt");
|
||||||
List<NameResolverProvider> providers = NameResolverProvider.load(cl);
|
List<NameResolverProvider> providers = NameResolverProvider.load(cl);
|
||||||
assertEquals(3, providers.size());
|
assertEquals(3, providers.size());
|
||||||
assertSame(Available7Provider.class, providers.get(0).getClass());
|
assertSame(Available7Provider.class, providers.get(0).getClass());
|
||||||
|
|
@ -69,7 +71,7 @@ public class NameResolverProviderTest {
|
||||||
public void unavailableProvider() {
|
public void unavailableProvider() {
|
||||||
ClassLoader cl = new ReplacingClassLoader(
|
ClassLoader cl = new ReplacingClassLoader(
|
||||||
getClass().getClassLoader(), serviceFile,
|
getClass().getClassLoader(), serviceFile,
|
||||||
"io/grpc/NameResolverProviderTest-unavailableProvider.txt");
|
"io/grpc/internal/NameResolverProviderTest-unavailableProvider.txt");
|
||||||
assertEquals(Collections.<NameResolverProvider>emptyList(), NameResolverProvider.load(cl));
|
assertEquals(Collections.<NameResolverProvider>emptyList(), NameResolverProvider.load(cl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,12 +172,12 @@ public class NameResolverProviderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return isAvailable;
|
return isAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int priority() {
|
public int priority() {
|
||||||
return priority;
|
return priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -221,7 +223,7 @@ public class NameResolverProviderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int priority() {
|
public int priority() {
|
||||||
throw new RuntimeException("purposefully broken");
|
throw new RuntimeException("purposefully broken");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
io.grpc.NameResolverProviderTest$Available5Provider
|
|
||||||
io.grpc.NameResolverProviderTest$Available7Provider
|
|
||||||
io.grpc.NameResolverProviderTest$Available0Provider
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
io.grpc.NameResolverProviderTest$UnavailableProvider
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
io.grpc.internal.NameResolverProviderTest$Available5Provider
|
||||||
|
io.grpc.internal.NameResolverProviderTest$Available7Provider
|
||||||
|
io.grpc.internal.NameResolverProviderTest$Available0Provider
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
io.grpc.internal.NameResolverProviderTest$UnavailableProvider
|
||||||
Loading…
Reference in New Issue