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


Java Attributes.newBuilder方法代码示例

本文整理汇总了Java中io.grpc.Attributes.newBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java Attributes.newBuilder方法的具体用法?Java Attributes.newBuilder怎么用?Java Attributes.newBuilder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.grpc.Attributes的用法示例。


在下文中一共展示了Attributes.newBuilder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildAttributes

import io.grpc.Attributes; //导入方法依赖的package包/类
private Attributes buildAttributes(GrpcURL subscribeUrl,
    Map<List<SocketAddress>, GrpcURL> addressUrlMapping) {
  Attributes.Builder builder = Attributes.newBuilder();
  if (listener != null) {
    builder.set(GrpcNameResolverProvider.NAMERESOVER_LISTENER, listener);
  }
  if (addresses.get(subscribeUrl) != null) {
    builder.set(GrpcNameResolverProvider.REMOTE_ADDR_KEYS, addresses.get(subscribeUrl));
  }
  if (!addressUrlMapping.isEmpty()) {
    builder.set(GrpcNameResolverProvider.GRPC_ADDRESS_GRPCURL_MAPPING, addressUrlMapping);
  }
  return builder.build();
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:15,代码来源:GrpcNameResolver.java

示例2: run

import io.grpc.Attributes; //导入方法依赖的package包/类
@Override
public void run() {
  Listener savedListener;
  synchronized (DnsNameResolver.this) {
    // If this task is started by refresh(), there might already be a scheduled task.
    if (resolutionTask != null) {
      resolutionTask.cancel(false);
      resolutionTask = null;
    }
    if (shutdown) {
      return;
    }
    savedListener = listener;
    resolving = true;
  }
  try {
    InetSocketAddress destination = InetSocketAddress.createUnresolved(host, port);
    ProxyParameters proxy = proxyDetector.proxyFor(destination);
    if (proxy != null) {
      EquivalentAddressGroup server = new EquivalentAddressGroup(destination);
      savedListener.onAddresses(Collections.singletonList(server), Attributes.EMPTY);
      return;
    }
    ResolutionResults resolvedInetAddrs;
    try {
      resolvedInetAddrs = delegateResolver.resolve(host);
    } catch (Exception e) {
      synchronized (DnsNameResolver.this) {
        if (shutdown) {
          return;
        }
        // Because timerService is the single-threaded GrpcUtil.TIMER_SERVICE in production,
        // we need to delegate the blocking work to the executor
        resolutionTask =
            timerService.schedule(new LogExceptionRunnable(resolutionRunnableOnExecutor),
                1, TimeUnit.MINUTES);
      }
      savedListener.onError(
          Status.UNAVAILABLE.withDescription("Unable to resolve host " + host).withCause(e));
      return;
    }
    // Each address forms an EAG
    List<EquivalentAddressGroup> servers = new ArrayList<EquivalentAddressGroup>();
    for (InetAddress inetAddr : resolvedInetAddrs.addresses) {
      servers.add(new EquivalentAddressGroup(new InetSocketAddress(inetAddr, port)));
    }
    servers.addAll(resolvedInetAddrs.balancerAddresses);

    Attributes.Builder attrs = Attributes.newBuilder();
    if (!resolvedInetAddrs.txtRecords.isEmpty()) {
      attrs.set(
          GrpcAttributes.NAME_RESOLVER_ATTR_DNS_TXT,
          Collections.unmodifiableList(new ArrayList<String>(resolvedInetAddrs.txtRecords)));
    }
    savedListener.onAddresses(servers, attrs.build());
  } finally {
    synchronized (DnsNameResolver.this) {
      resolving = false;
    }
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:62,代码来源:DnsNameResolver.java


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