protected Builder(ClientContext clientContext) { super(clientContext); annotateVideoSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); annotateVideoOperationSettings = OperationCallSettings.newBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(annotateVideoSettings); initDefaults(this); }
protected Builder(VideoIntelligenceServiceStubSettings settings) { super(settings); annotateVideoSettings = settings.annotateVideoSettings.toBuilder(); annotateVideoOperationSettings = settings.annotateVideoOperationSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(annotateVideoSettings); }
@Test public void testBuilder() { OperationCallSettings.Builder<Integer, String, Long> builder = OperationCallSettings.newBuilder(); UnaryCallSettings<Integer, OperationSnapshot> initialCallSettings = UnaryCallSettings.<Integer, OperationSnapshot>newUnaryCallSettingsBuilder() .setRetryableCodes(Code.UNAVAILABLE) .build(); TimedRetryAlgorithm pollingAlgorithm = Mockito.mock(TimedRetryAlgorithm.class); ResponseTransformer responseTransformer = new ResponseTransformer(); MetadataTransformer metadataTransformer = new MetadataTransformer(); builder.setPollingAlgorithm(pollingAlgorithm); builder.setResponseTransformer(responseTransformer); builder.setMetadataTransformer(metadataTransformer); builder.setInitialCallSettings(initialCallSettings); Truth.assertThat(builder.getInitialCallSettings()).isSameAs(initialCallSettings); OperationCallSettings settings = builder.build(); Truth.assertThat(settings.getPollingAlgorithm()).isSameAs(pollingAlgorithm); Truth.assertThat(settings.getResponseTransformer()).isSameAs(responseTransformer); Truth.assertThat(settings.getMetadataTransformer()).isSameAs(metadataTransformer); Truth.assertThat(settings.getInitialCallSettings()).isNotNull(); Truth.assertThat(settings.getInitialCallSettings().getRetryableCodes().size()).isEqualTo(1); }
@Test public void testBuilderFromSettings() throws Exception { OperationCallSettings.Builder<Integer, String, Long> builder = OperationCallSettings.newBuilder(); UnaryCallSettings<Integer, OperationSnapshot> initialCallSettings = UnaryCallSettings.<Integer, OperationSnapshot>newUnaryCallSettingsBuilder() .setRetryableCodes(Code.UNAVAILABLE) .build(); TimedRetryAlgorithm pollingAlgorithm = Mockito.mock(TimedRetryAlgorithm.class); ResponseTransformer responseTransformer = new ResponseTransformer(); MetadataTransformer metadataTransformer = new MetadataTransformer(); builder.setPollingAlgorithm(pollingAlgorithm); builder.setResponseTransformer(responseTransformer); builder.setMetadataTransformer(metadataTransformer); builder.setInitialCallSettings(initialCallSettings); Truth.assertThat(builder.getInitialCallSettings()).isSameAs(initialCallSettings); OperationCallSettings settings = builder.build(); OperationCallSettings.Builder newBuilder = settings.toBuilder(); Truth.assertThat(newBuilder.getPollingAlgorithm()).isSameAs(pollingAlgorithm); Truth.assertThat(newBuilder.getResponseTransformer()).isSameAs(responseTransformer); Truth.assertThat(newBuilder.getMetadataTransformer()).isSameAs(metadataTransformer); Truth.assertThat(newBuilder.getInitialCallSettings()).isNotNull(); Truth.assertThat(newBuilder.getInitialCallSettings().getRetryableCodes().size()).isEqualTo(1); }
OperationCallableImpl( UnaryCallable<RequestT, OperationSnapshot> initialCallable, RetryingExecutorWithContext<OperationSnapshot> executor, LongRunningClient longRunningClient, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings) { this.initialCallable = checkNotNull(initialCallable); this.executor = checkNotNull(executor); this.longRunningClient = checkNotNull(longRunningClient); this.responseTransformer = operationCallSettings.getResponseTransformer(); this.metadataTransformer = operationCallSettings.getMetadataTransformer(); }
/** * Creates a callable object that represents a long-running operation. Designed for use by * generated code. * * @param grpcCallSettings the gRPC call settings * @param operationCallSettings {@link OperationCallSettings} to configure the method-level * settings with. * @param clientContext {@link ClientContext} to use to connect to the service. * @param operationsStub {@link OperationsStub} to use to poll for updates on the Operation. * @return {@link com.google.api.gax.rpc.OperationCallable} callable object. */ @BetaApi( "The surface for long-running operations is not stable yet and may change in the future.") public static <RequestT, ResponseT, MetadataT> OperationCallable<RequestT, ResponseT, MetadataT> createOperationCallable( GrpcCallSettings<RequestT, Operation> grpcCallSettings, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings, ClientContext clientContext, OperationsStub operationsStub) { UnaryCallable<RequestT, Operation> initialGrpcCallable = createBaseUnaryCallable( grpcCallSettings, operationCallSettings.getInitialCallSettings(), clientContext); UnaryCallable<RequestT, OperationSnapshot> initialCallable = new GrpcOperationSnapshotCallable<>(initialGrpcCallable); LongRunningClient longRunningClient = new GrpcLongRunningClient(operationsStub); OperationCallable<RequestT, ResponseT, MetadataT> operationCallable = Callables.longRunningOperation( initialCallable, operationCallSettings, clientContext, longRunningClient); return operationCallable.withDefaultCallContext(clientContext.getDefaultCallContext()); }
static <RequestT, ResponseT, MetadataT> OperationCallableImpl<RequestT, ResponseT, MetadataT> longRunningOperationImpl( UnaryCallable<RequestT, OperationSnapshot> initialCallable, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings, ClientContext clientContext, LongRunningClient longRunningClient) { RetryAlgorithm<OperationSnapshot> pollingAlgorithm = new RetryAlgorithm<>( new OperationResponsePollAlgorithm(), operationCallSettings.getPollingAlgorithm()); ScheduledRetryingExecutor<OperationSnapshot> scheduler = new ScheduledRetryingExecutor<>(pollingAlgorithm, clientContext.getExecutor()); return new OperationCallableImpl<>( initialCallable, scheduler, longRunningClient, operationCallSettings); } }
OperationCallableImpl( UnaryCallable<RequestT, OperationSnapshot> initialCallable, RetryingExecutorWithContext<OperationSnapshot> executor, LongRunningClient longRunningClient, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings) { this.initialCallable = checkNotNull(initialCallable); this.executor = checkNotNull(executor); this.longRunningClient = checkNotNull(longRunningClient); this.responseTransformer = operationCallSettings.getResponseTransformer(); this.metadataTransformer = operationCallSettings.getMetadataTransformer(); }
/** * Creates a callable object that represents a long-running operation. Designed for use by * generated code. * * @param grpcCallSettings the gRPC call settings * @param operationCallSettings {@link OperationCallSettings} to configure the method-level * settings with. * @param clientContext {@link ClientContext} to use to connect to the service. * @param operationsStub {@link OperationsStub} to use to poll for updates on the Operation. * @return {@link com.google.api.gax.rpc.OperationCallable} callable object. */ @BetaApi( "The surface for long-running operations is not stable yet and may change in the future.") public static <RequestT, ResponseT, MetadataT> OperationCallable<RequestT, ResponseT, MetadataT> createOperationCallable( GrpcCallSettings<RequestT, Operation> grpcCallSettings, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings, ClientContext clientContext, OperationsStub operationsStub) { UnaryCallable<RequestT, Operation> initialGrpcCallable = createBaseUnaryCallable( grpcCallSettings, operationCallSettings.getInitialCallSettings(), clientContext); UnaryCallable<RequestT, OperationSnapshot> initialCallable = new GrpcOperationSnapshotCallable<>(initialGrpcCallable); LongRunningClient longRunningClient = new GrpcLongRunningClient(operationsStub); OperationCallable<RequestT, ResponseT, MetadataT> operationCallable = Callables.longRunningOperation( initialCallable, operationCallSettings, clientContext, longRunningClient); return operationCallable.withDefaultCallContext(clientContext.getDefaultCallContext()); }
static <RequestT, ResponseT, MetadataT> OperationCallableImpl<RequestT, ResponseT, MetadataT> longRunningOperationImpl( UnaryCallable<RequestT, OperationSnapshot> initialCallable, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings, ClientContext clientContext, LongRunningClient longRunningClient) { RetryAlgorithm<OperationSnapshot> pollingAlgorithm = new RetryAlgorithm<>( new OperationResponsePollAlgorithm(), operationCallSettings.getPollingAlgorithm()); ScheduledRetryingExecutor<OperationSnapshot> scheduler = new ScheduledRetryingExecutor<>(pollingAlgorithm, clientContext.getExecutor()); return new OperationCallableImpl<>( initialCallable, scheduler, longRunningClient, operationCallSettings); } }
protected Builder(ClientContext clientContext) { super(clientContext); annotateVideoSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); annotateVideoOperationSettings = OperationCallSettings.newBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(annotateVideoSettings); initDefaults(this); }
protected Builder(VideoIntelligenceServiceStubSettings settings) { super(settings); annotateVideoSettings = settings.annotateVideoSettings.toBuilder(); annotateVideoOperationSettings = settings.annotateVideoOperationSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(annotateVideoSettings); }
/** * Creates a callable object that represents a long-running operation. Designed for use by * generated code. * * @param innerCallable the callable that starts the operation * @param operationCallSettings {@link OperationCallSettings} to configure the method-level * settings with. * @param clientContext {@link ClientContext} to use to connect to the service. * @param longRunningClient {@link LongRunningClient} to use to poll for updates on the Operation. * @return {@link com.google.api.gax.rpc.OperationCallable} callable object. */ public static <RequestT, ResponseT, MetadataT> OperationCallable<RequestT, ResponseT, MetadataT> createOperationCallable( UnaryCallable<RequestT, OperationSnapshot> innerCallable, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings, ClientContext clientContext, LongRunningClient longRunningClient) { UnaryCallable<RequestT, OperationSnapshot> initialCallable = createBaseUnaryCallable( innerCallable, operationCallSettings.getInitialCallSettings(), clientContext); OperationCallable<RequestT, ResponseT, MetadataT> operationCallable = Callables.longRunningOperation( initialCallable, operationCallSettings, clientContext, longRunningClient); return operationCallable.withDefaultCallContext(FakeCallContext.create(clientContext)); }
protected Builder(ClientContext clientContext) { super(clientContext); annotateVideoSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); annotateVideoOperationSettings = OperationCallSettings.newBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(annotateVideoSettings); initDefaults(this); }
protected Builder(VideoIntelligenceServiceStubSettings settings) { super(settings); annotateVideoSettings = settings.annotateVideoSettings.toBuilder(); annotateVideoOperationSettings = settings.annotateVideoOperationSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(annotateVideoSettings); }
protected Builder(ClientContext clientContext) { super(clientContext); annotateVideoSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); annotateVideoOperationSettings = OperationCallSettings.newBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(annotateVideoSettings); initDefaults(this); }
protected Builder(VideoIntelligenceServiceStubSettings settings) { super(settings); annotateVideoSettings = settings.annotateVideoSettings.toBuilder(); annotateVideoOperationSettings = settings.annotateVideoOperationSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(annotateVideoSettings); }
protected Builder(ClientContext clientContext) { super(clientContext); annotateVideoSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); annotateVideoOperationSettings = OperationCallSettings.newBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(annotateVideoSettings); initDefaults(this); }
protected Builder(VideoIntelligenceServiceStubSettings settings) { super(settings); annotateVideoSettings = settings.annotateVideoSettings.toBuilder(); annotateVideoOperationSettings = settings.annotateVideoOperationSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(annotateVideoSettings); }
protected Builder(ClientContext clientContext) { super(clientContext); batchAnnotateImagesSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); asyncBatchAnnotateFilesSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); asyncBatchAnnotateFilesOperationSettings = OperationCallSettings.newBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of( batchAnnotateImagesSettings, asyncBatchAnnotateFilesSettings); initDefaults(this); }