Class: Aws::Xray::Client
- Inherits:
-
Object
- Object
- Aws::Xray::Client
- Defined in:
- lib/aws/xray/client.rb
Overview
Own the responsibility of holding destination address and sending segments.
Instance Method Summary collapse
- #copy ⇒ Object
-
#initialize(host: nil, port: nil, sock: nil) ⇒ Client
constructor
sock is for test.
-
#send_segment(segment) ⇒ Object
When UDPSocket#send can not send all bytes, just give up it.
Constructor Details
#initialize(host: nil, port: nil, sock: nil) ⇒ Client
sock is for test.
9 10 11 12 |
# File 'lib/aws/xray/client.rb', line 9 def initialize(host: nil, port: nil, sock: nil) @host, @port = host, port @sock = sock end |
Instance Method Details
#copy ⇒ Object
14 15 16 |
# File 'lib/aws/xray/client.rb', line 14 def copy self.class.new(host: @host ? @host.dup : nil, port: @port, sock: @sock) end |
#send_segment(segment) ⇒ Object
When UDPSocket#send can not send all bytes, just give up it.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/aws/xray/client.rb', line 20 def send_segment(segment) payload = %!{"format": "json", "version": 1}\n#{segment.to_json}\n! sock = @sock || UDPSocket.new begin len = sock.send(payload, Socket::MSG_DONTWAIT, @host, @port) raise CanNotSendAllByteError.new(payload.size, len) if payload.size != len len rescue SystemCallError, SocketError, CanNotSendAllByteError => e begin Aws::Xray.config.segment_sending_error_handler.call(e, payload, host: @host, port: @port) rescue Exception => e $stderr.puts("Error handler `#{Aws::Xray.config.segment_sending_error_handler}` raised an error: #{e}\n#{e.backtrace.join("\n")}") end ensure sock.close end end |