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, BaseClient::REQUEST_TYPES

Instance Attribute Summary collapse

Attributes inherited from BaseClient

#options, #uri

Instance Method Summary collapse

Methods inherited from BaseClient

#invoke_notification, #invoke_request, #method_missing, #perform_request

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
27
28
29
30
31
32
# 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

  timeout = @options.fetch(:timeout, 5)
  connect_timeout = @options.fetch(:connect_timeout, timeout)
  read_timeout = @options.fetch(:read_timeout, timeout)
  write_timeout = @options.fetch(:write_timeout, nil) # default 60
  connect_retry_count = @options.fetch(:connect_retry_count, nil) # default 10

  @transport = Net::TCPClient.new server: @uri,
                               connect_retry_count: connect_retry_count,
                               connect_timeout: connect_timeout,
                               read_timeout: read_timeout,
                               write_timeout: write_timeout,
                               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