class Gapic::ServiceStub::Channel


This class wraps the gRPC stub object and its RPC methods.
Gapic gRPC ServiceStub Channel.
@private
#

def call_rpc method_name, request, options: nil, &block

Returns:
  • (Object) - The response object.

Other tags:
    Yieldparam: operation - The RPC operation for the response.
    Yieldparam: response - The response object.

Other tags:
    Yield: - Access the response along with the RPC operation.

Parameters:
  • options (Gapic::CallOptions, Hash) -- The options for making the RPC call. A Hash can be provided to
  • request (Object) -- The request object.
  • method_name (Symbol) -- The RPC method name.
def call_rpc method_name, request, options: nil, &block
  @mutex.synchronize { @concurrent_streams += 1 }
  begin
    meth = @grpc_stub.method method_name
    rpc_call = RpcCall.new meth, stub_logger: @stub_logger, method_name: method_name
    response = rpc_call.call request, options: options, &block
    response
  ensure
    @mutex.synchronize { @concurrent_streams -= 1 }
  end
end

def initialize grpc_stub_class, endpoint:, credentials:, channel_args: nil, interceptors: nil,


Creates a new Channel instance
#
def initialize grpc_stub_class, endpoint:, credentials:, channel_args: nil, interceptors: nil,
               on_channel_create: nil, stub_logger: nil
  @grpc_stub_class = grpc_stub_class
  @endpoint = endpoint
  @credentials = credentials
  @channel_args = Hash channel_args
  @interceptors = Array interceptors
  @stub_logger = stub_logger
  @concurrent_streams = 0
  @mutex = Mutex.new
  setup_grpc_stub
  on_channel_create&.call self
end

def setup_grpc_stub


Creates a gRPC stub object
#
def setup_grpc_stub
  raise ArgumentError, "grpc_stub_class is required" if @grpc_stub_class.nil?
  raise ArgumentError, "endpoint is required" if @endpoint.nil?
  raise ArgumentError, "credentials is required" if @credentials.nil?
  @grpc_stub = case @credentials
               when ::GRPC::Core::Channel
                 @grpc_stub_class.new @endpoint, nil, channel_override: @credentials, interceptors: @interceptors
               when ::GRPC::Core::ChannelCredentials, Symbol
                 @grpc_stub_class.new @endpoint, @credentials, channel_args: @channel_args,
                                      interceptors: @interceptors
               else
                 updater_proc = @credentials.updater_proc if @credentials.respond_to? :updater_proc
                 updater_proc ||= @credentials if @credentials.is_a? Proc
                 raise ArgumentError, "invalid credentials (#{credentials.class})" if updater_proc.nil?
                 call_creds = ::GRPC::Core::CallCredentials.new updater_proc
                 chan_creds = ::GRPC::Core::ChannelCredentials.new.compose call_creds
                 @grpc_stub_class.new @endpoint, chan_creds, channel_args: @channel_args,
                                      interceptors: @interceptors
               end
end