本文整理汇总了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();
}
示例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;
}
}
}