use of com.google.api.gax.core.BackgroundResource in project java-logging by googleapis.
the class GrpcLoggingRpc method close.
@Override
public void close() throws Exception {
if (closed) {
return;
}
closed = true;
configClient.close();
loggingClient.close();
metricsClient.close();
for (BackgroundResource resource : clientContext.getBackgroundResources()) {
resource.close();
}
executorFactory.release(executor);
}
use of com.google.api.gax.core.BackgroundResource in project java-bigtable-hbase by googleapis.
the class SharedDataClientWrapperFactory method release.
synchronized void release(Key key) {
int refCount = refCounts.get(key);
if (--refCount > 0) {
refCounts.put(key, refCount);
return;
}
refCounts.remove(key);
ClientContext clientContext = cachedContexts.remove(key);
for (int i = 0; i < channelPoolSizes.get(key); i++) {
BigtableClientMetrics.counter(MetricLevel.Info, "grpc.channel.active").dec();
}
channelPoolSizes.remove(key);
for (BackgroundResource resource : clientContext.getBackgroundResources()) {
resource.shutdown();
}
}
use of com.google.api.gax.core.BackgroundResource in project java-firestore by googleapis.
the class GrpcFirestoreRpc method close.
@Override
public void close() throws Exception {
if (!closed) {
firestoreStub.close();
for (BackgroundResource resource : clientContext.getBackgroundResources()) {
resource.close();
}
executorFactory.release(executor);
closed = true;
}
for (BackgroundResource resource : clientContext.getBackgroundResources()) {
resource.awaitTermination(1, TimeUnit.SECONDS);
}
}
use of com.google.api.gax.core.BackgroundResource in project java-firestore by googleapis.
the class GrpcFirestoreRpc method shutdownNow.
@Override
public void shutdownNow() {
if (closed) {
return;
}
firestoreStub.shutdownNow();
for (BackgroundResource resource : clientContext.getBackgroundResources()) {
resource.shutdownNow();
}
executorFactory.release(executor);
closed = true;
}
use of com.google.api.gax.core.BackgroundResource in project gax-java by googleapis.
the class ClientContextTest method testWatchdogProvider.
@Test
public void testWatchdogProvider() throws IOException {
FakeClientSettings.Builder builder = new FakeClientSettings.Builder();
InterceptingExecutor executor = new InterceptingExecutor(1);
FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel());
FakeTransportProvider transportProvider = new FakeTransportProvider(transportChannel, executor, true, null, null);
ApiClock clock = Mockito.mock(ApiClock.class);
builder.setClock(clock);
builder.setCredentialsProvider(FixedCredentialsProvider.create(Mockito.mock(Credentials.class)));
builder.setExecutorProvider(new FakeExecutorProvider(executor, true));
builder.setTransportChannelProvider(transportProvider);
Duration watchdogCheckInterval = Duration.ofSeconds(11);
builder.setWatchdogProvider(InstantiatingWatchdogProvider.create().withClock(clock).withCheckInterval(watchdogCheckInterval).withExecutor(executor));
builder.setWatchdogCheckInterval(watchdogCheckInterval);
HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class);
Mockito.when(headerProvider.getHeaders()).thenReturn(ImmutableMap.of("k1", "v1"));
HeaderProvider internalHeaderProvider = Mockito.mock(HeaderProvider.class);
Mockito.when(internalHeaderProvider.getHeaders()).thenReturn(ImmutableMap.of("k2", "v2"));
builder.setHeaderProvider(headerProvider);
builder.setInternalHeaderProvider(internalHeaderProvider);
ClientContext context = ClientContext.create(builder.build());
List<BackgroundResource> resources = context.getBackgroundResources();
assertThat(resources.get(2)).isInstanceOf(Watchdog.class);
}
Aggregations