Class: LeelaClient::UDPTransport

Inherits:
Object
  • Object
show all
Defined in:
lib/leela_client/transport.rb

Constant Summary collapse

MAXPAYLOAD =
1472
DEFAULT_PORT =
6968

Instance Method Summary collapse

Constructor Details

#initialize(ring, opts) ⇒ UDPTransport

Returns a new instance of UDPTransport.



78
79
80
81
82
# File 'lib/leela_client/transport.rb', line 78

def initialize(ring, opts)
  @ring = ring
  @opts = opts
  @sock = UDPSocket.new
end

Instance Method Details

#send(metrics) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/leela_client/transport.rb', line 88

def send(metrics)
  sent = 0
  LeelaClient::LoadBalancer.group_limit(@ring, metrics, MAXPAYLOAD).each do |addr, mms|
    mms.each do |ms|
      @sock.send(serialize_list(ms), 0, addr[0], @opts[:port] || DEFAULT_PORT)
      sent += ms.size # yeah, hopefully!
    end
  end
  return(sent)
end

#serialize_list(metrics) ⇒ Object



84
85
86
# File 'lib/leela_client/transport.rb', line 84

def serialize_list(metrics)
  metrics.map(&:serialize).join("")
end