Java Code Examples for io.grpc.internal.GrpcUtil#STOPWATCH_SUPPLIER
The following examples show how to use
io.grpc.internal.GrpcUtil#STOPWATCH_SUPPLIER .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OkHttpClientTransport.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
OkHttpClientTransport(InetSocketAddress address, String authority, @Nullable String userAgent, Executor executor, @Nullable SSLSocketFactory sslSocketFactory, @Nullable HostnameVerifier hostnameVerifier, ConnectionSpec connectionSpec, int maxMessageSize, int initialWindowSize, @Nullable ProxyParameters proxy, Runnable tooManyPingsRunnable, int maxInboundMetadataSize, TransportTracer transportTracer) { this.address = Preconditions.checkNotNull(address, "address"); this.defaultAuthority = authority; this.maxMessageSize = maxMessageSize; this.initialWindowSize = initialWindowSize; this.executor = Preconditions.checkNotNull(executor, "executor"); serializingExecutor = new SerializingExecutor(executor); // Client initiated streams are odd, server initiated ones are even. Server should not need to // use it. We start clients at 3 to avoid conflicting with HTTP negotiation. nextStreamId = 3; this.sslSocketFactory = sslSocketFactory; this.hostnameVerifier = hostnameVerifier; this.connectionSpec = Preconditions.checkNotNull(connectionSpec, "connectionSpec"); this.stopwatchFactory = GrpcUtil.STOPWATCH_SUPPLIER; this.userAgent = GrpcUtil.getGrpcUserAgent("okhttp", userAgent); this.proxy = proxy; this.tooManyPingsRunnable = Preconditions.checkNotNull(tooManyPingsRunnable, "tooManyPingsRunnable"); this.maxInboundMetadataSize = maxInboundMetadataSize; this.transportTracer = Preconditions.checkNotNull(transportTracer); initTransportTracer(); }
Example 2
Source File: XdsNameResolverProvider.java From grpc-java with Apache License 2.0 | 6 votes |
@Override public XdsNameResolver newNameResolver(URI targetUri, Args args) { 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 name = targetPath.substring(1); return new XdsNameResolver( name, args, new ExponentialBackoffPolicy.Provider(), GrpcUtil.STOPWATCH_SUPPLIER, XdsChannelFactory.getInstance(), Bootstrapper.getInstance()); } return null; }
Example 3
Source File: XdsExperimentalNameResolverProvider.java From grpc-java with Apache License 2.0 | 6 votes |
@Override public NameResolver newNameResolver(URI targetUri, Args args) { 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 name = targetPath.substring(1); return new XdsNameResolver( name, args, new ExponentialBackoffPolicy.Provider(), GrpcUtil.STOPWATCH_SUPPLIER, XdsChannelFactory.getInstance(), Bootstrapper.getInstance()); } return null; }
Example 4
Source File: XdsClientWrapperForServerSds.java From grpc-java with Apache License 2.0 | 5 votes |
/** Creates an XdsClient and starts a watch. */ public void createXdsClientAndStart() { checkState(xdsClient == null, "start() called more than once"); Bootstrapper.BootstrapInfo bootstrapInfo; List<Bootstrapper.ServerInfo> serverList; try { bootstrapInfo = Bootstrapper.getInstance().readBootstrap(); serverList = bootstrapInfo.getServers(); if (serverList.isEmpty()) { throw new ManagementServerNotFoundException("No management server provided by bootstrap"); } } catch (IOException | ManagementServerNotFoundException e) { logger.log(Level.FINE, "Exception reading bootstrap", e); logger.log(Level.INFO, "Fallback to plaintext for server at port {0}", port); return; } Node node = bootstrapInfo.getNode(); timeService = SharedResourceHolder.get(timeServiceResource); XdsClientImpl xdsClientImpl = new XdsClientImpl( "", serverList, XdsClient.XdsChannelFactory.getInstance(), node, createSynchronizationContext(), timeService, new ExponentialBackoffPolicy.Provider(), GrpcUtil.STOPWATCH_SUPPLIER); start(xdsClientImpl); }
Example 5
Source File: AbstractInteropTest.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
protected final CensusStatsModule createClientCensusStatsModule() { return new CensusStatsModule( tagger, tagContextBinarySerializer, clientStatsRecorder, GrpcUtil.STOPWATCH_SUPPLIER, true); }
Example 6
Source File: EdsLoadBalancer.java From grpc-java with Apache License 2.0 | 4 votes |
@Override public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) { logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses); Object lbConfig = resolvedAddresses.getLoadBalancingPolicyConfig(); if (lbConfig == null) { handleNameResolutionError(Status.UNAVAILABLE.withDescription("Missing EDS lb config")); return; } EdsConfig newEdsConfig = (EdsConfig) lbConfig; if (logger.isLoggable(XdsLogLevel.INFO)) { logger.log( XdsLogLevel.INFO, "Received EDS lb config: cluster={0}, child_policy={1}, " + "eds_service_name={2}, report_load={3}", newEdsConfig.clusterName, newEdsConfig.endpointPickingPolicy.getProvider().getPolicyName(), newEdsConfig.edsServiceName, newEdsConfig.lrsServerName != null); } boolean firstUpdate = false; if (clusterName == null) { firstUpdate = true; } clusterName = newEdsConfig.clusterName; if (xdsClientPool == null) { Attributes attributes = resolvedAddresses.getAttributes(); xdsClientPool = attributes.get(XdsAttributes.XDS_CLIENT_POOL); if (xdsClientPool == null) { final BootstrapInfo bootstrapInfo; try { bootstrapInfo = bootstrapper.readBootstrap(); } catch (Exception e) { helper.updateBalancingState( TRANSIENT_FAILURE, new ErrorPicker( Status.UNAVAILABLE.withDescription("Failed to bootstrap").withCause(e))); return; } final List<ServerInfo> serverList = bootstrapInfo.getServers(); final Node node = bootstrapInfo.getNode(); if (serverList.isEmpty()) { helper.updateBalancingState( TRANSIENT_FAILURE, new ErrorPicker( Status.UNAVAILABLE .withDescription("No management server provided by bootstrap"))); return; } XdsClientFactory xdsClientFactory = new XdsClientFactory() { @Override XdsClient createXdsClient() { return new XdsClientImpl( helper.getAuthority(), serverList, channelFactory, node, helper.getSynchronizationContext(), helper.getScheduledExecutorService(), new ExponentialBackoffPolicy.Provider(), GrpcUtil.STOPWATCH_SUPPLIER); } }; xdsClientPool = new RefCountedXdsClientObjectPool(xdsClientFactory); } else { logger.log(XdsLogLevel.INFO, "Use xDS client from channel"); } xdsClient = xdsClientPool.getObject(); } // Note: childPolicy change will be handled in LocalityStore, to be implemented. // If edsServiceName in XdsConfig is changed, do a graceful switch. if (firstUpdate || !Objects.equals(newEdsConfig.edsServiceName, edsServiceName)) { LoadBalancer.Factory clusterEndpointsLoadBalancerFactory = new ClusterEndpointsBalancerFactory(newEdsConfig.edsServiceName); switchingLoadBalancer.switchTo(clusterEndpointsLoadBalancerFactory); } switchingLoadBalancer.handleResolvedAddresses(resolvedAddresses); this.edsServiceName = newEdsConfig.edsServiceName; }
Example 7
Source File: OkHttpClientTransport.java From grpc-java with Apache License 2.0 | 4 votes |
OkHttpClientTransport( InetSocketAddress address, String authority, @Nullable String userAgent, Attributes eagAttrs, Executor executor, @Nullable SocketFactory socketFactory, @Nullable SSLSocketFactory sslSocketFactory, @Nullable HostnameVerifier hostnameVerifier, ConnectionSpec connectionSpec, int maxMessageSize, int initialWindowSize, @Nullable HttpConnectProxiedSocketAddress proxiedAddr, Runnable tooManyPingsRunnable, int maxInboundMetadataSize, TransportTracer transportTracer, boolean useGetForSafeMethods) { this.address = Preconditions.checkNotNull(address, "address"); this.defaultAuthority = authority; this.maxMessageSize = maxMessageSize; this.initialWindowSize = initialWindowSize; this.executor = Preconditions.checkNotNull(executor, "executor"); serializingExecutor = new SerializingExecutor(executor); // Client initiated streams are odd, server initiated ones are even. Server should not need to // use it. We start clients at 3 to avoid conflicting with HTTP negotiation. nextStreamId = 3; this.socketFactory = socketFactory == null ? SocketFactory.getDefault() : socketFactory; this.sslSocketFactory = sslSocketFactory; this.hostnameVerifier = hostnameVerifier; this.connectionSpec = Preconditions.checkNotNull(connectionSpec, "connectionSpec"); this.stopwatchFactory = GrpcUtil.STOPWATCH_SUPPLIER; this.userAgent = GrpcUtil.getGrpcUserAgent("okhttp", userAgent); this.proxiedAddr = proxiedAddr; this.tooManyPingsRunnable = Preconditions.checkNotNull(tooManyPingsRunnable, "tooManyPingsRunnable"); this.maxInboundMetadataSize = maxInboundMetadataSize; this.transportTracer = Preconditions.checkNotNull(transportTracer); this.logId = InternalLogId.allocate(getClass(), address.toString()); this.attributes = Attributes.newBuilder() .set(GrpcAttributes.ATTR_CLIENT_EAG_ATTRS, eagAttrs).build(); this.useGetForSafeMethods = useGetForSafeMethods; initTransportTracer(); }
Example 8
Source File: HealthCheckingLoadBalancerUtil.java From grpc-java with Apache License 2.0 | 3 votes |
/** * Creates a health-checking-capable LoadBalancer. This method is used to implement * health-checking-capable {@link Factory}s, which will typically written this way: * * <pre> * public class HealthCheckingFooLbFactory extends LoadBalancer.Factory { * // This is the original balancer implementation that doesn't have health checking * private final LoadBalancer.Factory fooLbFactory; * * ... * * // Returns the health-checking-capable version of FooLb * public LoadBalancer newLoadBalancer(Helper helper) { * return HealthCheckingLoadBalancerUtil.newHealthCheckingLoadBalancer(fooLbFactory, helper); * } * } * </pre> * * <p>As a requirement for the original LoadBalancer, it must call * {@code Helper.createSubchannel()} from the {@link * io.grpc.LoadBalancer.Helper#getSynchronizationContext() Synchronization Context}, or * {@code createSubchannel()} will throw. * * @param factory the original factory that implements load-balancing logic without health * checking * @param helper the helper passed to the resulting health-checking LoadBalancer. */ public static LoadBalancer newHealthCheckingLoadBalancer(Factory factory, Helper helper) { HealthCheckingLoadBalancerFactory hcFactory = new HealthCheckingLoadBalancerFactory( factory, new ExponentialBackoffPolicy.Provider(), GrpcUtil.STOPWATCH_SUPPLIER); return hcFactory.newLoadBalancer(helper); }