public PublisherClientImpl(Publisher.IPublisherClient grpcClient, PublisherSettings settings)
        {
            this.GrpcClient = grpcClient;
            PublisherSettings effectiveSettings = settings ?? PublisherSettings.GetDefault();

            _clientHelper = new ClientHelper(effectiveSettings);
        }
        /// <summary>
        /// Synchronously creates a <see cref="PublisherClient"/>, applying defaults for all unspecified settings.
        /// </summary>
        /// <param name="endpoint">Optional <see cref="ServiceEndpoint"/>.</param>
        /// <param name="settings">Optional <see cref="PublisherSettings"/>.</param>
        /// <param name="credentials">Optional <see cref="ChannelCredentials"/>.</param>
        /// <returns>The created <see cref="PublisherClient"/>.</returns>
        public static PublisherClient Create(
            ServiceEndpoint endpoint       = null,
            PublisherSettings settings     = null,
            ChannelCredentials credentials = null)
        {
            Channel channel = ClientHelper.CreateChannel(endpoint ?? DefaultEndpoint, credentials);

            Publisher.PublisherClient grpcClient = new Publisher.PublisherClient(channel);
            return(new PublisherClientImpl(grpcClient, settings));
        }
        // Note: we could have parameterless overloads of Create and CreateAsync,
        // documented to just use the default endpoint, settings and credentials.
        // Pros:
        // - Might be more reassuring on first use
        // - Allows method group conversions
        // Con: overloads!

        /// <summary>
        /// Asynchronously creates a <see cref="PublisherClient"/>, applying defaults for all unspecified settings.
        /// </summary>
        /// <param name="endpoint">Optional <see cref="ServiceEndpoint"/>.</param>
        /// <param name="settings">Optional <see cref="PublisherSettings"/>.</param>
        /// <param name="credentials">Optional <see cref="ChannelCredentials"/>.</param>
        /// <returns>The task representing the created <see cref="PublisherClient"/>.</returns>
        public static async Task <PublisherClient> CreateAsync(
            ServiceEndpoint endpoint       = null,
            PublisherSettings settings     = null,
            ChannelCredentials credentials = null)
        {
            Channel channel = await ClientHelper.CreateChannelAsync(endpoint ?? DefaultEndpoint, credentials).ConfigureAwait(false);

            Publisher.PublisherClient grpcClient = new Publisher.PublisherClient(channel);
            return(new PublisherClientImpl(grpcClient, settings));
        }
 private PublisherSettings(PublisherSettings existing) : base(existing)
 {
     GaxPreconditions.CheckNotNull(existing, nameof(existing));
     CreateTopicRetry            = existing.CreateTopicRetry?.Clone();
     PublishRetry                = existing.PublishRetry?.Clone();
     GetTopicRetry               = existing.GetTopicRetry?.Clone();
     ListTopicsRetry             = existing.ListTopicsRetry?.Clone();
     ListTopicSubscriptionsRetry = existing.ListTopicSubscriptionsRetry?.Clone();
     DeleteTopicRetry            = existing.DeleteTopicRetry?.Clone();
 }
        public PublisherClientImpl(Publisher.IPublisherClient grpcClient, PublisherSettings settings)
        {
            this.GrpcClient = grpcClient;
            PublisherSettings effectiveSettings = settings ?? PublisherSettings.GetDefault();
            IClock            effectiveClock    = effectiveSettings.Clock ?? SystemClock.Instance;

            _clientHelper    = new ClientHelper(effectiveSettings);
            _callCreateTopic = _clientHelper.BuildApiCall <Topic, Topic>(GrpcClient.CreateTopicAsync, GrpcClient.CreateTopic)
                               .WithRetry(effectiveSettings.CreateTopicRetry, effectiveClock, null);
            _callPublish = _clientHelper.BuildApiCall <PublishRequest, PublishResponse>(GrpcClient.PublishAsync, GrpcClient.Publish)
                           .WithRetry(effectiveSettings.PublishRetry, effectiveClock, null);
            _callGetTopic = _clientHelper.BuildApiCall <GetTopicRequest, Topic>(GrpcClient.GetTopicAsync, GrpcClient.GetTopic)
                            .WithRetry(effectiveSettings.GetTopicRetry, effectiveClock, null);
            _callListTopics = _clientHelper.BuildApiCall <ListTopicsRequest, ListTopicsResponse>(GrpcClient.ListTopicsAsync, GrpcClient.ListTopics)
                              .WithRetry(effectiveSettings.ListTopicsRetry, effectiveClock, null);
            _callListTopicSubscriptions = _clientHelper.BuildApiCall <ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse>(GrpcClient.ListTopicSubscriptionsAsync, GrpcClient.ListTopicSubscriptions)
                                          .WithRetry(effectiveSettings.ListTopicSubscriptionsRetry, effectiveClock, null);
            _callDeleteTopic = _clientHelper.BuildApiCall <DeleteTopicRequest, Empty>(GrpcClient.DeleteTopicAsync, GrpcClient.DeleteTopic)
                               .WithRetry(effectiveSettings.DeleteTopicRetry, effectiveClock, null);
        }
 /// <summary>
 /// Wrap a GRPC Publisher client for more convenient use.
 /// </summary>
 /// <param name="grpcClient">A GRPC client to wrap.</param>
 /// <param name="settings">
 /// An optional <see cref="PublisherSettings"/> to configure this wrapper.
 /// If null or not specified, then the default settings are used.
 /// </param>
 /// <returns>A <see cref="PublisherClient"/> that wraps the specified GRPC client.</returns>
 public static PublisherClient ToClient(
     this Publisher.IPublisherClient grpcClient,
     PublisherSettings settings = null
     ) => new PublisherClientImpl(grpcClient, settings);