当前位置: 首页>>代码示例>>Java>>正文


Java NameResolver类代码示例

本文整理汇总了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;
  }
}
 
开发者ID:saturnism,项目名称:grpc-java-by-example,代码行数:25,代码来源:KubernetesNameResolverProvider.java

示例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));
}
 
开发者ID:pravega,项目名称:pravega,代码行数:18,代码来源:ControllerResolverFactory.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:17,代码来源:GRPCChannelManagerTest.java

示例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();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:17,代码来源:OkHttpChannelBuilder.java

示例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();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:19,代码来源:NettyChannelBuilder.java

示例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() {}
  };
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:20,代码来源:AbstractManagedChannelImplBuilder.java

示例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();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:23,代码来源:OverrideAuthorityNameResolverTest.java

示例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
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:22,代码来源:ManagedChannelImplGetNameResolverTest.java

示例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));
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:11,代码来源:FallbackResolverTest.java

示例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));
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:11,代码来源:FallbackResolverTest.java

示例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));
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:9,代码来源:FallbackResolverTest.java

示例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());
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:11,代码来源:FallbackResolverTest.java

示例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;
  }
}
 
开发者ID:coreos,项目名称:jetcd,代码行数:10,代码来源:SmartNameResolverFactory.java

示例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);
}
 
开发者ID:coreos,项目名称:jetcd,代码行数:14,代码来源:SmartNameResolverFactory.java

示例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;
  }
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:11,代码来源:ZkNameResolverProvider.java


注:本文中的io.grpc.NameResolver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。