Java Code Examples for io.grpc.internal.SharedResourceHolder#get()
The following examples show how to use
io.grpc.internal.SharedResourceHolder#get() .
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: NettyChannelBuilder.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
NettyTransportFactory(ProtocolNegotiator protocolNegotiator, Class<? extends Channel> channelType, Map<ChannelOption<?>, ?> channelOptions, EventLoopGroup group, int flowControlWindow, int maxMessageSize, int maxHeaderListSize, long keepAliveTimeNanos, long keepAliveTimeoutNanos, boolean keepAliveWithoutCalls, TransportTracer transportTracer, LocalSocketPicker localSocketPicker) { this.protocolNegotiator = protocolNegotiator; this.channelType = channelType; this.channelOptions = new HashMap<ChannelOption<?>, Object>(channelOptions); this.flowControlWindow = flowControlWindow; this.maxMessageSize = maxMessageSize; this.maxHeaderListSize = maxHeaderListSize; this.keepAliveTimeNanos = new AtomicBackoff("keepalive time nanos", keepAliveTimeNanos); this.keepAliveTimeoutNanos = keepAliveTimeoutNanos; this.keepAliveWithoutCalls = keepAliveWithoutCalls; this.transportTracer = transportTracer; this.localSocketPicker = localSocketPicker != null ? localSocketPicker : new LocalSocketPicker(); usingSharedGroup = group == null; if (usingSharedGroup) { // The group was unspecified, using the shared group. this.group = SharedResourceHolder.get(Utils.DEFAULT_WORKER_EVENT_LOOP_GROUP); } else { this.group = group; } }
Example 2
Source File: ErrorNumberUtil.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
/** * 将当前出错的服务器从备选列表中去除 * * @author sxp * @since 2018-6-21 * @since 2019/12/11 modify by wlh 10分钟(时间可配)后,将服务重新放回至服务提供列表 */ private static void removeCurrentProvider(NameResolver nameResolver, String providerId, String method) { Map<String, ServiceProvider> providersForLoadBalance = nameResolver.getProvidersForLoadBalance(); if (providersForLoadBalance == null || providersForLoadBalance.size() == 0) { logger.info("客户端的备选列表为空", providerId); return; } if (providersForLoadBalance.containsKey(providerId)) { logger.error("FATAL ERROR : 服务器节点{}连续调用出错{}次,从客户端备选服务器列表中删除", providerId, switchoverThreshold); providersForLoadBalance.remove(providerId); nameResolver.reCalculateProvidersCountAfterLoadBalance(method); if (timerService == null) { timerService = SharedResourceHolder.get(GrpcUtil.TIMER_SERVICE); } timerService.schedule(new RecoveryServerRunnable(nameResolver, providerId, method), recoveryMilliseconds, TimeUnit.MILLISECONDS); } }
Example 3
Source File: CronetChannelBuilder.java From grpc-java with Apache License 2.0 | 6 votes |
private CronetTransportFactory( StreamBuilderFactory streamFactory, Executor executor, @Nullable ScheduledExecutorService timeoutService, int maxMessageSize, boolean alwaysUsePut, TransportTracer transportTracer, boolean useGetForSafeMethods, boolean usePutForIdempotentMethods) { usingSharedScheduler = timeoutService == null; this.timeoutService = usingSharedScheduler ? SharedResourceHolder.get(GrpcUtil.TIMER_SERVICE) : timeoutService; this.maxMessageSize = maxMessageSize; this.alwaysUsePut = alwaysUsePut; this.streamFactory = streamFactory; this.executor = Preconditions.checkNotNull(executor, "executor"); this.transportTracer = Preconditions.checkNotNull(transportTracer, "transportTracer"); this.useGetForSafeMethods = useGetForSafeMethods; this.usePutForIdempotentMethods = usePutForIdempotentMethods; }
Example 4
Source File: KubernetesNameResolver.java From grpc-by-example-java with Apache License 2.0 | 6 votes |
@Override @GuardedBy("this") public void refresh() { if (refreshing) return; try { refreshing = true; Endpoints endpoints = kubernetesClient.endpoints().inNamespace(namespace) .withName(name) .get(); if (endpoints == null) { // Didn't find anything, retrying ScheduledExecutorService timerService = SharedResourceHolder.get(timerServiceResource); timerService.schedule(() -> { refresh(); }, 30, TimeUnit.SECONDS); return; } update(endpoints); watch(); } finally { refreshing = false; } }
Example 5
Source File: CronetChannelBuilder.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
private CronetTransportFactory( StreamBuilderFactory streamFactory, Executor executor, @Nullable ScheduledExecutorService timeoutService, int maxMessageSize, boolean alwaysUsePut, TransportTracer transportTracer) { usingSharedScheduler = timeoutService == null; this.timeoutService = usingSharedScheduler ? SharedResourceHolder.get(GrpcUtil.TIMER_SERVICE) : timeoutService; this.maxMessageSize = maxMessageSize; this.alwaysUsePut = alwaysUsePut; this.streamFactory = streamFactory; this.executor = Preconditions.checkNotNull(executor, "executor"); this.transportTracer = Preconditions.checkNotNull(transportTracer, "transportTracer"); }
Example 6
Source File: DiscoveryClientNameResolver.java From grpc-spring-boot-starter with MIT License | 5 votes |
@Override public void start(final Listener2 listener) { checkState(this.listener == null, "already started"); if (this.usingExecutorResource) { this.executor = SharedResourceHolder.get(this.executorResource); } this.listener = checkNotNull(listener, "listener"); resolve(); }
Example 7
Source File: InProcessChannelBuilder.java From grpc-java with Apache License 2.0 | 5 votes |
private InProcessClientTransportFactory( String name, @Nullable ScheduledExecutorService scheduledExecutorService, int maxInboundMetadataSize, boolean includeCauseWithStatus) { this.name = name; useSharedTimer = scheduledExecutorService == null; timerService = useSharedTimer ? SharedResourceHolder.get(GrpcUtil.TIMER_SERVICE) : scheduledExecutorService; this.maxInboundMetadataSize = maxInboundMetadataSize; this.includeCauseWithStatus = includeCauseWithStatus; }
Example 8
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 9
Source File: SmartNameResolver.java From jetcd with Apache License 2.0 | 5 votes |
@Override public void start(Listener listener) { synchronized (lock) { Preconditions.checkState(this.listener == null, "already started"); this.executor = SharedResourceHolder.get(GrpcUtil.SHARED_CHANNEL_EXECUTOR); this.listener = Preconditions.checkNotNull(listener, "listener"); resolve(); } }
Example 10
Source File: DiscoveryClientNameResolver.java From grpc-spring-boot-starter with MIT License | 5 votes |
@Override public void start(final Listener2 listener) { checkState(this.listener == null, "already started"); if (this.usingExecutorResource) { this.executor = SharedResourceHolder.get(this.executorResource); } this.listener = checkNotNull(listener, "listener"); resolve(); }
Example 11
Source File: SelfNameResolver.java From grpc-spring-boot-starter with MIT License | 5 votes |
@Override public final void start(final Listener2 listener) { checkState(this.listener == null, "already started"); this.listener = checkNotNull(listener, "listener"); if (this.usingExecutorResource) { this.executor = SharedResourceHolder.get(this.executorResource); } resolve(); }
Example 12
Source File: SelfNameResolver.java From grpc-spring-boot-starter with MIT License | 5 votes |
@Override public final void start(final Listener2 listener) { checkState(this.listener == null, "already started"); this.listener = checkNotNull(listener, "listener"); if (this.usingExecutorResource) { this.executor = SharedResourceHolder.get(this.executorResource); } resolve(); }
Example 13
Source File: InProcessChannelBuilder.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
private InProcessClientTransportFactory( String name, @Nullable ScheduledExecutorService scheduledExecutorService, int maxInboundMetadataSize) { this.name = name; useSharedTimer = scheduledExecutorService == null; timerService = useSharedTimer ? SharedResourceHolder.get(GrpcUtil.TIMER_SERVICE) : scheduledExecutorService; this.maxInboundMetadataSize = maxInboundMetadataSize; }
Example 14
Source File: ZookeeperNameResolver.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Override public final synchronized void start(Listener listener) { Preconditions.checkState(this.listener == null, "already started"); timerService = SharedResourceHolder.get(timerServiceResource); executor = SharedResourceHolder.get(executorResource); this.listener = Preconditions.checkNotNull(listener, "listener"); resolve(); }
Example 15
Source File: GoogleDefaultChannelBuilder.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Override public GoogleDefaultProtocolNegotiator buildProtocolNegotiator() { TsiHandshakerFactory altsHandshakerFactory = new TsiHandshakerFactory() { @Override public TsiHandshaker newHandshaker(String authority) { // Used the shared grpc channel to connecting to the ALTS handshaker service. // TODO: Release the channel if it is not used. // https://github.com/grpc/grpc-java/issues/4755. ManagedChannel channel = SharedResourceHolder.get(HandshakerServiceChannel.SHARED_HANDSHAKER_CHANNEL); AltsClientOptions handshakerOptions = new AltsClientOptions.Builder() .setRpcProtocolVersions(RpcProtocolVersionsUtil.getRpcProtocolVersions()) .setTargetName(authority) .build(); return AltsTsiHandshaker.newClient( HandshakerServiceGrpc.newStub(channel), handshakerOptions); } }; SslContext sslContext; try { sslContext = GrpcSslContexts.forClient().build(); } catch (SSLException ex) { throw new RuntimeException(ex); } return negotiatorForTest = new GoogleDefaultProtocolNegotiator(altsHandshakerFactory, sslContext); }
Example 16
Source File: OkHttpChannelBuilder.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
private OkHttpTransportFactory(Executor executor, @Nullable ScheduledExecutorService timeoutService, @Nullable SSLSocketFactory socketFactory, @Nullable HostnameVerifier hostnameVerifier, ConnectionSpec connectionSpec, int maxMessageSize, boolean enableKeepAlive, long keepAliveTimeNanos, long keepAliveTimeoutNanos, int flowControlWindow, boolean keepAliveWithoutCalls, int maxInboundMetadataSize, TransportTracer.Factory transportTracerFactory) { usingSharedScheduler = timeoutService == null; this.timeoutService = usingSharedScheduler ? SharedResourceHolder.get(GrpcUtil.TIMER_SERVICE) : timeoutService; this.socketFactory = socketFactory; this.hostnameVerifier = hostnameVerifier; this.connectionSpec = connectionSpec; this.maxMessageSize = maxMessageSize; this.enableKeepAlive = enableKeepAlive; this.keepAliveTimeNanos = new AtomicBackoff("keepalive time nanos", keepAliveTimeNanos); this.keepAliveTimeoutNanos = keepAliveTimeoutNanos; this.flowControlWindow = flowControlWindow; this.keepAliveWithoutCalls = keepAliveWithoutCalls; this.maxInboundMetadataSize = maxInboundMetadataSize; usingSharedExecutor = executor == null; this.transportTracerFactory = Preconditions.checkNotNull(transportTracerFactory, "transportTracerFactory"); if (usingSharedExecutor) { // The executor was unspecified, using the shared executor. this.executor = SharedResourceHolder.get(SHARED_EXECUTOR); } else { this.executor = executor; } }
Example 17
Source File: OkHttpChannelBuilder.java From grpc-java with Apache License 2.0 | 4 votes |
private OkHttpTransportFactory( Executor executor, @Nullable ScheduledExecutorService timeoutService, @Nullable SocketFactory socketFactory, @Nullable SSLSocketFactory sslSocketFactory, @Nullable HostnameVerifier hostnameVerifier, ConnectionSpec connectionSpec, int maxMessageSize, boolean enableKeepAlive, long keepAliveTimeNanos, long keepAliveTimeoutNanos, int flowControlWindow, boolean keepAliveWithoutCalls, int maxInboundMetadataSize, TransportTracer.Factory transportTracerFactory, boolean useGetForSafeMethods) { usingSharedScheduler = timeoutService == null; this.timeoutService = usingSharedScheduler ? SharedResourceHolder.get(GrpcUtil.TIMER_SERVICE) : timeoutService; this.socketFactory = socketFactory; this.sslSocketFactory = sslSocketFactory; this.hostnameVerifier = hostnameVerifier; this.connectionSpec = connectionSpec; this.maxMessageSize = maxMessageSize; this.enableKeepAlive = enableKeepAlive; this.keepAliveTimeNanos = new AtomicBackoff("keepalive time nanos", keepAliveTimeNanos); this.keepAliveTimeoutNanos = keepAliveTimeoutNanos; this.flowControlWindow = flowControlWindow; this.keepAliveWithoutCalls = keepAliveWithoutCalls; this.maxInboundMetadataSize = maxInboundMetadataSize; this.useGetForSafeMethods = useGetForSafeMethods; usingSharedExecutor = executor == null; this.transportTracerFactory = Preconditions.checkNotNull(transportTracerFactory, "transportTracerFactory"); if (usingSharedExecutor) { // The executor was unspecified, using the shared executor. this.executor = SharedResourceHolder.get(SHARED_EXECUTOR); } else { this.executor = executor; } }