Class: Riak::Client::Node

Inherits:
Object show all
Includes:
Util::Escape, Util::Translation
Defined in:
lib/riak/client/node.rb

Constant Summary collapse

VALID_OPTIONS =
[:host, :http_port, :pb_port, :http_paths, :prefix,
:mapred, :luwak, :solr, :port, :basic_auth, :ssl_options, :ssl]
ERRORS_DECAY_RATE =

For a score which halves in 10 seconds, choose ln(1/2)/10

Math.log(0.5)/10

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Escape

#escape, #maybe_escape, #maybe_unescape, #unescape

Methods included from Util::Translation

#i18n_scope, #t

Constructor Details

#initialize(client, opts = {}) ⇒ Node

Returns a new instance of Node.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/riak/client/node.rb', line 30

def initialize(client, opts = {})
  @client = client
  @ssl = opts[:ssl]
  @ssl_options = opts[:ssl_options]
  @host = opts[:host] || "127.0.0.1"
  @http_port = opts[:http_port] || opts[:port] || 8098
  @pb_port = opts[:pb_port] || 8087
  @http_paths = {
    :prefix => opts[:prefix] || "/riak/",
    :mapred => opts[:mapred] || "/mapred",
    :luwak =>  opts[:luwak]  || "/luwak",
    :solr =>   opts[:solr]   || "/solr" # Unused?
  }.merge(opts[:http_paths] || {})
  self.basic_auth = opts[:basic_auth]

  @error_rate = Decaying.new
end

Instance Attribute Details

#basic_authObject

A “user:password” string.



25
26
27
# File 'lib/riak/client/node.rb', line 25

def basic_auth
  @basic_auth
end

#error_rateObject (readonly)

A Decaying rate of errors.



28
29
30
# File 'lib/riak/client/node.rb', line 28

def error_rate
  @error_rate
end

#hostObject

What IP address or hostname does this node listen on?



17
18
19
# File 'lib/riak/client/node.rb', line 17

def host
  @host
end

#http_pathsObject

A hash of HTTP paths used on this node.



23
24
25
# File 'lib/riak/client/node.rb', line 23

def http_paths
  @http_paths
end

#http_portObject

Which port does the HTTP interface listen on?



19
20
21
# File 'lib/riak/client/node.rb', line 19

def http_port
  @http_port
end

#pb_portObject

Which port does the protocol buffers interface listen on?



21
22
23
# File 'lib/riak/client/node.rb', line 21

def pb_port
  @pb_port
end

#ssl_optionsObject

Returns the value of attribute ssl_options.



26
27
28
# File 'lib/riak/client/node.rb', line 26

def ssl_options
  @ssl_options
end

Instance Method Details

#==(o) ⇒ Object



48
49
50
51
52
53
# File 'lib/riak/client/node.rb', line 48

def ==(o)
  o.kind_of? Node and
    @host == o.host and
    @http_port == o.http_port and
    @pb_port == o.pb_port
end

#http?Boolean

Can this node be used for HTTP requests?

Returns:

  • (Boolean)


68
69
70
71
# File 'lib/riak/client/node.rb', line 68

def http?
  # TODO: Need to sort out capabilities
  true
end

#inspectObject



98
99
100
# File 'lib/riak/client/node.rb', line 98

def inspect
  "#<Node #{@host}:#{@http_port}:#{@pb_port}>"
end

#protobuffs?Boolean

Can this node be used for protocol buffers requests?

Returns:

  • (Boolean)


74
75
76
77
# File 'lib/riak/client/node.rb', line 74

def protobuffs?
  # TODO: Need to sort out capabilities
  true
end

#ssl=(value) ⇒ Object

Enables or disables SSL on this node to be utilized by the HTTP Backends



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/riak/client/node.rb', line 81

def ssl=(value)
  @ssl_options = {} if(!@ssl_options)
  if((!!value).class === value)
    # Got a boolean...
    @ssl_options = {}
  else
    value = Hash === value ? value : {}
    @ssl_options.merge!(value)
  end
  value ? ssl_enable : ssl_disable
end

#ssl_enabled?Boolean

Checks if SSL is enabled for HTTP

Returns:

  • (Boolean)


94
95
96
# File 'lib/riak/client/node.rb', line 94

def ssl_enabled?
  @client.protocol == 'https' && @ssl_options.present?
end