Class: Trace::Endpoint

Inherits:
Struct
  • Object
show all
Defined in:
lib/finagle-thrift/tracer.rb

Constant Summary collapse

MAX_I32 =
((2 ** 31) - 1)
MASK =
(2 ** 32) - 1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ipv4Object

Returns the value of attribute ipv4

Returns:

  • (Object)

    the current value of ipv4



206
207
208
# File 'lib/finagle-thrift/tracer.rb', line 206

def ipv4
  @ipv4
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



206
207
208
# File 'lib/finagle-thrift/tracer.rb', line 206

def port
  @port
end

#service_nameObject

Returns the value of attribute service_name

Returns:

  • (Object)

    the current value of service_name



206
207
208
# File 'lib/finagle-thrift/tracer.rb', line 206

def service_name
  @service_name
end

Class Method Details

.host_to_i32(host) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/finagle-thrift/tracer.rb', line 210

def self.host_to_i32(host)
  unsigned_i32 = Socket.getaddrinfo(host, nil)[0][3].split(".").map do |i|
    i.to_i
  end.inject(0) { |a,e| (a << 8) + e }

  signed_i32 = if unsigned_i32 > MAX_I32
    -1 * ((unsigned_i32 ^ MASK) + 1)
  else
    unsigned_i32
  end

  signed_i32
end

Instance Method Details

#to_sObject



240
241
242
# File 'lib/finagle-thrift/tracer.rb', line 240

def to_s
  "#{service_name}@#{ipv4}:#{port}"
end

#to_thriftObject



232
233
234
235
236
237
238
# File 'lib/finagle-thrift/tracer.rb', line 232

def to_thrift
  FinagleThrift::Endpoint.new(
    :ipv4 => self.ipv4,
    :port => self.port,
    :service_name => self.service_name
  )
end

#with_port(port) ⇒ Object



224
225
226
# File 'lib/finagle-thrift/tracer.rb', line 224

def with_port(port)
  Endpoint.new(self.ipv4, port, self.service_name)
end

#with_service_name(service_name) ⇒ Object



228
229
230
# File 'lib/finagle-thrift/tracer.rb', line 228

def with_service_name(service_name)
  Endpoint.new(self.ipv4, self.port, service_name)
end