Search in sources :

Example 6 with BackgroundResource

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);
}
Also used : BackgroundResource(com.google.api.gax.core.BackgroundResource)

Example 7 with BackgroundResource

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();
    }
}
Also used : BackgroundResource(com.google.api.gax.core.BackgroundResource) ClientContext(com.google.api.gax.rpc.ClientContext)

Example 8 with BackgroundResource

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);
    }
}
Also used : BackgroundResource(com.google.api.gax.core.BackgroundResource)

Example 9 with BackgroundResource

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;
}
Also used : BackgroundResource(com.google.api.gax.core.BackgroundResource)

Example 10 with BackgroundResource

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);
}
Also used : FakeTransportChannel(com.google.api.gax.rpc.testing.FakeTransportChannel) FakeClientSettings(com.google.api.gax.rpc.testing.FakeClientSettings) ApiClock(com.google.api.core.ApiClock) Duration(org.threeten.bp.Duration) BackgroundResource(com.google.api.gax.core.BackgroundResource) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Aggregations

BackgroundResource (com.google.api.gax.core.BackgroundResource)11 FakeChannel (com.google.api.gax.rpc.testing.FakeChannel)5 FakeClientSettings (com.google.api.gax.rpc.testing.FakeClientSettings)5 FakeTransportChannel (com.google.api.gax.rpc.testing.FakeTransportChannel)5 Test (org.junit.Test)4 ApiClock (com.google.api.core.ApiClock)3 ExecutorProvider (com.google.api.gax.core.ExecutorProvider)2 Credentials (com.google.auth.Credentials)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Duration (org.threeten.bp.Duration)2 ExecutorAsBackgroundResource (com.google.api.gax.core.ExecutorAsBackgroundResource)1 FixedExecutorProvider (com.google.api.gax.core.FixedExecutorProvider)1 ClientContext (com.google.api.gax.rpc.ClientContext)1 QuotaProjectIdHidingCredentials (com.google.api.gax.rpc.internal.QuotaProjectIdHidingCredentials)1 MtlsProvider (com.google.api.gax.rpc.mtls.MtlsProvider)1 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)1 ImmutableList (com.google.common.collect.ImmutableList)1 Nullable (javax.annotation.Nullable)1