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



209
210
211
# File 'lib/finagle-thrift/tracer.rb', line 209

def ipv4
  @ipv4
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



209
210
211
# File 'lib/finagle-thrift/tracer.rb', line 209

def port
  @port
end

#service_nameObject

Returns the value of attribute service_name

Returns:

  • (Object)

    the current value of service_name



209
210
211
# File 'lib/finagle-thrift/tracer.rb', line 209

def service_name
  @service_name
end

Class Method Details

.host_to_i32(host) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/finagle-thrift/tracer.rb', line 213

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



243
244
245
# File 'lib/finagle-thrift/tracer.rb', line 243

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

#to_thriftObject



235
236
237
238
239
240
241
# File 'lib/finagle-thrift/tracer.rb', line 235

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

#with_port(port) ⇒ Object



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

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

#with_service_name(service_name) ⇒ Object



231
232
233
# File 'lib/finagle-thrift/tracer.rb', line 231

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