本文整理汇总了Java中io.grpc.NameResolver类的典型用法代码示例。如果您正苦于以下问题:Java NameResolver类的具体用法?Java NameResolver怎么用?Java NameResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NameResolver类属于io.grpc包,在下文中一共展示了NameResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newNameResolver
import io.grpc.NameResolver; //导入依赖的package包/类
@Nullable
@Override
public NameResolver newNameResolver(URI targetUri, Attributes params) {
if (SCHEME.equals(targetUri.getScheme())) {
String targetPath = Preconditions.checkNotNull(targetUri.getPath(), "targetPath");
Preconditions.checkArgument(targetPath.startsWith("/"),
"the path component (%s) of the target (%s) must start with '/'", targetPath, targetUri);
String[] parts = targetPath.split("/");
if (parts.length != 4) {
throw new IllegalArgumentException("Must be formatted like kubernetes:///{namespace}/{service}/{port}");
}
try {
int port = Integer.valueOf(parts[3]);
return new KubernetesNameResolver(parts[1], parts[2], port, params, GrpcUtil.TIMER_SERVICE,
GrpcUtil.SHARED_CHANNEL_EXECUTOR);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Unable to parse port number", e);
}
} else {
return null;
}
}
示例2: newNameResolver
import io.grpc.NameResolver; //导入依赖的package包/类
@Nullable
@Override
public NameResolver newNameResolver(URI targetUri, Attributes params) {
final String scheme = targetUri.getScheme();
if (!SCHEME_DISCOVER.equals(scheme) && !SCHEME_DIRECT.equals(scheme)) {
return null;
}
final String authority = targetUri.getAuthority();
final List<InetSocketAddress> addresses = Splitter.on(',').splitToList(authority).stream().map(host -> {
final String[] strings = host.split(":");
Preconditions.checkArgument(strings.length == 2, "URI should have both address and port");
return InetSocketAddress.createUnresolved(strings[0], Integer.valueOf(strings[1]));
}).collect(Collectors.toList());
return new ControllerNameResolver(authority, addresses, SCHEME_DISCOVER.equals(scheme));
}
示例3: setUp
import io.grpc.NameResolver; //导入依赖的package包/类
@Before
public void setUp() throws Throwable {
List<String> grpcServers = new ArrayList<String>();
grpcServers.add("127.0.0.1:2181");
RemoteDownstreamConfig.Collector.GRPC_SERVERS = grpcServers;
Config.Collector.GRPC_CHANNEL_CHECK_INTERVAL = 1;
mockStatic(NettyChannelBuilder.class);
when(NettyChannelBuilder.forAddress(anyString(), anyInt())).thenReturn(mock);
when(mock.nameResolverFactory(any(NameResolver.Factory.class))).thenReturn(mock);
when(mock.maxInboundMessageSize(anyInt())).thenReturn(mock);
when(mock.usePlaintext(true)).thenReturn(mock);
when(mock.build()).thenReturn(grpcServerRule.getChannel());
grpcChannelManager.addChannelListener(listener);
}
示例4: getNameResolverParams
import io.grpc.NameResolver; //导入依赖的package包/类
@Override
protected Attributes getNameResolverParams() {
int defaultPort;
switch (negotiationType) {
case PLAINTEXT:
defaultPort = GrpcUtil.DEFAULT_PORT_PLAINTEXT;
break;
case TLS:
defaultPort = GrpcUtil.DEFAULT_PORT_SSL;
break;
default:
throw new AssertionError(negotiationType + " not handled");
}
return Attributes.newBuilder()
.set(NameResolver.Factory.PARAMS_DEFAULT_PORT, defaultPort).build();
}
示例5: getNameResolverParams
import io.grpc.NameResolver; //导入依赖的package包/类
@Override
@CheckReturnValue
protected Attributes getNameResolverParams() {
int defaultPort;
switch (negotiationType) {
case PLAINTEXT:
case PLAINTEXT_UPGRADE:
defaultPort = GrpcUtil.DEFAULT_PORT_PLAINTEXT;
break;
case TLS:
defaultPort = GrpcUtil.DEFAULT_PORT_SSL;
break;
default:
throw new AssertionError(negotiationType + " not handled");
}
return Attributes.newBuilder()
.set(NameResolver.Factory.PARAMS_DEFAULT_PORT, defaultPort).build();
}
示例6: newNameResolver
import io.grpc.NameResolver; //导入依赖的package包/类
@Override
public NameResolver newNameResolver(URI notUsedUri, Attributes params) {
return new NameResolver() {
@Override
public String getServiceAuthority() {
return authority;
}
@Override
public void start(final Listener listener) {
listener.onAddresses(
Collections.singletonList(new EquivalentAddressGroup(address)),
Attributes.EMPTY);
}
@Override
public void shutdown() {}
};
}
示例7: forwardsNonOverridenCalls
import io.grpc.NameResolver; //导入依赖的package包/类
@Test
public void forwardsNonOverridenCalls() {
NameResolver.Factory wrappedFactory = mock(NameResolver.Factory.class);
NameResolver mockResolver = mock(NameResolver.class);
when(wrappedFactory.newNameResolver(any(URI.class), any(Attributes.class)))
.thenReturn(mockResolver);
NameResolver.Factory factory =
new OverrideAuthorityNameResolverFactory(wrappedFactory, "override:5678");
NameResolver overrideResolver =
factory.newNameResolver(URI.create("dns:///localhost:443"), Attributes.EMPTY);
assertNotNull(overrideResolver);
NameResolver.Listener listener = mock(NameResolver.Listener.class);
overrideResolver.start(listener);
verify(mockResolver).start(listener);
overrideResolver.shutdown();
verify(mockResolver).shutdown();
overrideResolver.refresh();
verify(mockResolver).refresh();
}
示例8: validTargetNoResovler
import io.grpc.NameResolver; //导入依赖的package包/类
@Test
public void validTargetNoResovler() {
Factory nameResolverFactory = new NameResolver.Factory() {
@Override
public NameResolver newNameResolver(URI targetUri, Attributes params) {
return null;
}
@Override
public String getDefaultScheme() {
return "defaultscheme";
}
};
try {
ManagedChannelImpl.getNameResolver(
"foo.googleapis.com:8080", nameResolverFactory, NAME_RESOLVER_PARAMS);
fail("Should fail");
} catch (IllegalArgumentException e) {
// expected
}
}
示例9: firstShouldFind
import io.grpc.NameResolver; //导入依赖的package包/类
@Test
public void firstShouldFind() throws Exception {
NameResolver fakeResolver = new FakeResolver();
FakeResolverProvider canResolve = new FakeResolverProvider("aaa://", fakeResolver);
FakeResolverProvider cannotResolve = new FakeResolverProvider("bbb://", null);
NameResolver.Factory factory = FallbackResolver.startWith(canResolve).thenCheck(cannotResolve);
assertEquals(fakeResolver, factory.newNameResolver(new URI("aaa://foo"), Attributes.EMPTY));
}
示例10: secondShouldFind
import io.grpc.NameResolver; //导入依赖的package包/类
@Test
public void secondShouldFind() throws Exception {
NameResolver fakeResolver = new FakeResolver();
FakeResolverProvider canResolve = new FakeResolverProvider("aaa://", fakeResolver);
FakeResolverProvider cannotResolve = new FakeResolverProvider("bbb://", null);
NameResolver.Factory factory = FallbackResolver.startWith(cannotResolve).thenCheck(canResolve);
assertEquals(fakeResolver, factory.newNameResolver(new URI("bbb://foo"), Attributes.EMPTY));
}
示例11: neitherShouldFind
import io.grpc.NameResolver; //导入依赖的package包/类
@Test
public void neitherShouldFind() throws Exception {
FakeResolverProvider cannotResolve = new FakeResolverProvider("bbb://", null);
NameResolver.Factory factory = FallbackResolver.startWith(cannotResolve).thenCheck(cannotResolve);
assertNull(factory.newNameResolver(new URI("bbb://foo"), Attributes.EMPTY));
}
示例12: firstSchemeIsDefaultScheme
import io.grpc.NameResolver; //导入依赖的package包/类
@Test
public void firstSchemeIsDefaultScheme() {
NameResolver fakeResolver = new FakeResolver();
FakeResolverProvider canResolve = new FakeResolverProvider("aaa://", fakeResolver);
FakeResolverProvider cannotResolve = new FakeResolverProvider("bbb://", null);
NameResolver.Factory factory = FallbackResolver.startWith(canResolve).thenCheck(cannotResolve);
assertEquals("aaa://", factory.getDefaultScheme());
}
示例13: newNameResolver
import io.grpc.NameResolver; //导入依赖的package包/类
@Nullable
@Override
public NameResolver newNameResolver(URI targetUri, Attributes params) {
if ("etcd".equals(targetUri.getScheme())) {
return new SmartNameResolver(this.authority , this.uris, this.loader);
} else {
return null;
}
}
示例14: forEndpoints
import io.grpc.NameResolver; //导入依赖的package包/类
public static NameResolver.Factory forEndpoints(
String authority, Collection<String> endpoints, URIResolverLoader loader) {
List<URI> uris = endpoints.stream().map(endpoint -> {
try {
return new URI(endpoint);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
}).collect(Collectors.toList());
return new SmartNameResolverFactory(authority, uris, loader);
}
示例15: newNameResolver
import io.grpc.NameResolver; //导入依赖的package包/类
@Override
public NameResolver newNameResolver(URI targetUri, Attributes params) {
if (SCHEME.equals(targetUri.getScheme())) {
params = Attributes.newBuilder(params)
.set(GrpclbConstants.ATTR_LB_POLICY, GrpclbConstants.LbPolicy.ROUND_ROBIN).build();
return new ZkNameResolver(targetUri, params, getCallOptions());
} else {
return null;
}
}