diff options
Diffstat (limited to 'src/ruby/lib/grpc/generic/client_stub.rb')
-rw-r--r-- | src/ruby/lib/grpc/generic/client_stub.rb | 85 |
1 files changed, 31 insertions, 54 deletions
diff --git a/src/ruby/lib/grpc/generic/client_stub.rb b/src/ruby/lib/grpc/generic/client_stub.rb index 12946fe819..cddca13d17 100644 --- a/src/ruby/lib/grpc/generic/client_stub.rb +++ b/src/ruby/lib/grpc/generic/client_stub.rb @@ -44,21 +44,21 @@ module GRPC # setup_channel is used by #initialize to constuct a channel from its # arguments. - def self.setup_channel(alt_chan, host, creds, **kw) + def self.setup_channel(alt_chan, host, creds, channel_args = {}) unless alt_chan.nil? fail(TypeError, '!Channel') unless alt_chan.is_a?(Core::Channel) return alt_chan end - if kw['grpc.primary_user_agent'].nil? - kw['grpc.primary_user_agent'] = '' + if channel_args['grpc.primary_user_agent'].nil? + channel_args['grpc.primary_user_agent'] = '' else - kw['grpc.primary_user_agent'] += ' ' + channel_args['grpc.primary_user_agent'] += ' ' end - kw['grpc.primary_user_agent'] += "grpc-ruby/#{VERSION}" + channel_args['grpc.primary_user_agent'] += "grpc-ruby/#{VERSION}" unless creds.is_a?(Core::ChannelCredentials) || creds.is_a?(Symbol) fail(TypeError, '!ChannelCredentials or Symbol') end - Core::Channel.new(host, kw, creds) + Core::Channel.new(host, channel_args, creds) end # Allows users of the stub to modify the propagate mask. @@ -96,15 +96,16 @@ module GRPC # :this_channel_is_insecure # @param channel_override [Core::Channel] a pre-created channel # @param timeout [Number] the default timeout to use in requests - # @param kw [KeywordArgs]the channel arguments + # @param channel_args [Hash] the channel arguments def initialize(host, q, creds, channel_override: nil, timeout: nil, propagate_mask: nil, - **kw) + channel_args: {}) fail(TypeError, '!CompletionQueue') unless q.is_a?(Core::CompletionQueue) - @ch = ClientStub.setup_channel(channel_override, host, creds, **kw) - alt_host = kw[Core::Channel::SSL_TARGET] + @ch = ClientStub.setup_channel(channel_override, host, creds, + channel_args) + alt_host = channel_args[Core::Channel::SSL_TARGET] @host = alt_host.nil? ? host : alt_host @propagate_mask = propagate_mask @timeout = timeout.nil? ? DEFAULT_TIMEOUT : timeout @@ -135,42 +136,35 @@ module GRPC # If return_op is true, the call returns an Operation, calling execute # on the Operation returns the response. # - # == Keyword Args == - # - # Unspecified keyword arguments are treated as metadata to be sent to the - # server. - # # @param method [String] the RPC method to call on the GRPC server # @param req [Object] the request sent to the server # @param marshal [Function] f(obj)->string that marshals requests # @param unmarshal [Function] f(string)->obj that unmarshals responses - # @param timeout [Numeric] (optional) the max completion time in seconds # @param deadline [Time] (optional) the time the request should complete + # @param return_op [true|false] return an Operation if true # @param parent [Core::Call] a prior call whose reserved metadata # will be propagated by this one. # @param credentials [Core::CallCredentials] credentials to use when making # the call - # @param return_op [true|false] return an Operation if true + # @param metadata [Hash] metadata to be sent to the server # @return [Object] the response received from the server def request_response(method, req, marshal, unmarshal, deadline: nil, - timeout: nil, return_op: false, parent: nil, credentials: nil, - **kw) + metadata: {}) c = new_active_call(method, marshal, unmarshal, deadline: deadline, - timeout: timeout, parent: parent, credentials: credentials) - return c.request_response(req, **kw) unless return_op + return c.request_response(req, metadata: metadata) unless return_op # return the operation view of the active_call; define #execute as a # new method for this instance that invokes #request_response. op = c.operation op.define_singleton_method(:execute) do - c.request_response(req, **kw) + c.request_response(req, metadata: metadata) end op end @@ -205,42 +199,35 @@ module GRPC # # If return_op is true, the call returns the response. # - # == Keyword Args == - # - # Unspecified keyword arguments are treated as metadata to be sent to the - # server. - # # @param method [String] the RPC method to call on the GRPC server # @param requests [Object] an Enumerable of requests to send # @param marshal [Function] f(obj)->string that marshals requests # @param unmarshal [Function] f(string)->obj that unmarshals responses - # @param timeout [Numeric] (optional) the max completion time in seconds # @param deadline [Time] (optional) the time the request should complete # @param return_op [true|false] return an Operation if true # @param parent [Core::Call] a prior call whose reserved metadata # will be propagated by this one. # @param credentials [Core::CallCredentials] credentials to use when making # the call + # @param metadata [Hash] metadata to be sent to the server # @return [Object|Operation] the response received from the server def client_streamer(method, requests, marshal, unmarshal, deadline: nil, - timeout: nil, return_op: false, parent: nil, credentials: nil, - **kw) + metadata: {}) c = new_active_call(method, marshal, unmarshal, deadline: deadline, - timeout: timeout, parent: parent, credentials: credentials) - return c.client_streamer(requests, **kw) unless return_op + return c.client_streamer(requests, metadata: metadata) unless return_op # return the operation view of the active_call; define #execute as a # new method for this instance that invokes #client_streamer. op = c.operation op.define_singleton_method(:execute) do - c.client_streamer(requests, **kw) + c.client_streamer(requests, metadata: metadata) end op end @@ -292,35 +279,33 @@ module GRPC # @param req [Object] the request sent to the server # @param marshal [Function] f(obj)->string that marshals requests # @param unmarshal [Function] f(string)->obj that unmarshals responses - # @param timeout [Numeric] (optional) the max completion time in seconds # @param deadline [Time] (optional) the time the request should complete # @param return_op [true|false]return an Operation if true # @param parent [Core::Call] a prior call whose reserved metadata # will be propagated by this one. # @param credentials [Core::CallCredentials] credentials to use when making # the call + # @param metadata [Hash] metadata to be sent to the server # @param blk [Block] when provided, is executed for each response # @return [Enumerator|Operation|nil] as discussed above def server_streamer(method, req, marshal, unmarshal, deadline: nil, - timeout: nil, return_op: false, parent: nil, credentials: nil, - **kw, + metadata: {}, &blk) c = new_active_call(method, marshal, unmarshal, deadline: deadline, - timeout: timeout, parent: parent, credentials: credentials) - return c.server_streamer(req, **kw, &blk) unless return_op + return c.server_streamer(req, metadata: metadata, &blk) unless return_op # return the operation view of the active_call; define #execute # as a new method for this instance that invokes #server_streamer op = c.operation op.define_singleton_method(:execute) do - c.server_streamer(req, **kw, &blk) + c.server_streamer(req, metadata: metadata, &blk) end op end @@ -391,11 +376,6 @@ module GRPC # * the deadline is exceeded # # - # == Keyword Args == - # - # Unspecified keyword arguments are treated as metadata to be sent to the - # server. - # # == Return Value == # # if the return_op is false, the return value is an Enumerator of the @@ -411,36 +391,35 @@ module GRPC # @param requests [Object] an Enumerable of requests to send # @param marshal [Function] f(obj)->string that marshals requests # @param unmarshal [Function] f(string)->obj that unmarshals responses - # @param timeout [Numeric] (optional) the max completion time in seconds # @param deadline [Time] (optional) the time the request should complete # @param parent [Core::Call] a prior call whose reserved metadata # will be propagated by this one. # @param credentials [Core::CallCredentials] credentials to use when making # the call # @param return_op [true|false] return an Operation if true + # @param metadata [Hash] metadata to be sent to the server # @param blk [Block] when provided, is executed for each response # @return [Enumerator|nil|Operation] as discussed above def bidi_streamer(method, requests, marshal, unmarshal, deadline: nil, - timeout: nil, return_op: false, parent: nil, credentials: nil, - **kw, + metadata: {}, &blk) c = new_active_call(method, marshal, unmarshal, deadline: deadline, - timeout: timeout, parent: parent, credentials: credentials) - return c.bidi_streamer(requests, **kw, &blk) unless return_op + return c.bidi_streamer(requests, metadata: metadata, + &blk) unless return_op # return the operation view of the active_call; define #execute # as a new method for this instance that invokes #bidi_streamer op = c.operation op.define_singleton_method(:execute) do - c.bidi_streamer(requests, **kw, &blk) + c.bidi_streamer(requests, metadata: metadata, &blk) end op end @@ -457,12 +436,10 @@ module GRPC # @param timeout [TimeConst] def new_active_call(method, marshal, unmarshal, deadline: nil, - timeout: nil, parent: nil, credentials: nil) - if deadline.nil? - deadline = from_relative_time(timeout.nil? ? @timeout : timeout) - end + + deadline = from_relative_time(@timeout) if deadline.nil? # Provide each new client call with its own completion queue call_queue = Core::CompletionQueue.new call = @ch.create_call(call_queue, |