Class: JRPC::TcpClient

Inherits:
BaseClient show all
Defined in:
lib/jrpc/tcp_client.rb

Constant Summary collapse

MAX_LOGGED_MESSAGE_LENGTH =
255

Constants inherited from BaseClient

BaseClient::ID_CHARACTERS

Instance Attribute Summary collapse

Attributes inherited from BaseClient

#options, #uri

Instance Method Summary collapse

Methods inherited from BaseClient

#invoke_notification, #invoke_request, #method_missing

Constructor Details

#initialize(uri, options = {}) ⇒ TcpClient

Returns a new instance of TcpClient.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jrpc/tcp_client.rb', line 13

def initialize(uri, options = {})
  super
  @logger = @options.delete(:logger) || Logger.new($null)
  @namespace = @options.delete(:namespace).to_s
  t = @options.fetch(:timeout, 5)

  @transport = Net::TCPClient.new server: @uri,
                               connect_retry_count: t,
                               connect_timeout: t,
                               read_timeout: t, # write_timeout: t,
                               buffered: false # recommended for RPC
rescue ::SocketError
  raise ConnectionError, "Can't connect to #{@uri}"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class JRPC::BaseClient

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/jrpc/tcp_client.rb', line 8

def logger
  @logger
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



7
8
9
# File 'lib/jrpc/tcp_client.rb', line 7

def namespace
  @namespace
end

#transportObject (readonly)

Returns the value of attribute transport.



7
8
9
# File 'lib/jrpc/tcp_client.rb', line 7

def transport
  @transport
end