Class: Hypertube::Utils::PluginConnectionData

Inherits:
ConnectionData show all
Defined in:
lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb

Constant Summary

Constants inherited from ConnectionData

ConnectionData::THREAD_LOCAL_HEADERS_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ConnectionData

#get_headers, #get_thread_local_headers, #set_headers, #set_thread_local_headers, #to_canonical_key

Constructor Details

#initialize(hostname, plugin_config) ⇒ PluginConnectionData

Returns a new instance of PluginConnectionData.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 9

def initialize(hostname, plugin_config)
  super()
  host_only, port = parse_hostname(hostname)
  @hostname = "#{host_only}:#{port}"
  @port = port
  @plugin_config = plugin_config.to_s
  if host_only == 'localhost'
    @ip_address = '127.0.0.1'
  else
    begin
      @ip_address = IPSocket.getaddress(host_only)
    rescue SocketError
      raise 'Unable to resolve hostname to an IP address.'
    end
  end
end

Instance Attribute Details

#hostnameObject (readonly)

Returns the value of attribute hostname.



7
8
9
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 7

def hostname
  @hostname
end

#ip_addressObject (readonly)

Returns the value of attribute ip_address.



7
8
9
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 7

def ip_address
  @ip_address
end

#plugin_configObject (readonly)

Returns the value of attribute plugin_config.



7
8
9
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 7

def plugin_config
  @plugin_config
end

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 7

def port
  @port
end

Instance Method Details

#connection_typeObject



26
27
28
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 26

def connection_type
  ConnectionType::PLUGIN
end

#get_address_bytesObject



38
39
40
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 38

def get_address_bytes
  @ip_address.split('.').map(&:to_i)
end

#get_configObject



34
35
36
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 34

def get_config
  @plugin_config
end

#get_port_bytesObject



42
43
44
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 42

def get_port_bytes
  [@port & 0xFF, @port >> 8]
end

#serialize_connection_dataObject



46
47
48
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 46

def serialize_connection_data
  [Hypertube::Utils::ConnectionType::PLUGIN] + get_address_bytes + get_port_bytes
end

#to_sObject



30
31
32
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 30

def to_s
  "plugin|#{@hostname}"
end