Class: Riak::Client::Node

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

Constant Summary

VALID_OPTIONS =
[:host, :http_port, :pb_port, :http_paths, :prefix,
:mapred, :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

- (Node) initialize(client, opts = {})

Returns a new instance of Node



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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",
    :solr =>   opts[:solr]   || "/solr" # Unused?
  }.merge(opts[:http_paths] || {})
  self.basic_auth = opts[:basic_auth]

  @error_rate = Decaying.new
end

Instance Attribute Details

- (Object) basic_auth

A “user:password” string.



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

def basic_auth
  @basic_auth
end

- (Object) error_rate (readonly)

A Decaying rate of errors.



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

def error_rate
  @error_rate
end

- (Object) host

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

- (Object) http_paths

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

- (Object) http_port

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

- (Object) pb_port

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

- (Object) ssl_options

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

- (Object) ==(o)



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

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

- (Boolean) http?

Can this node be used for HTTP requests?

Returns:

  • (Boolean)


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

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

- (Object) inspect



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

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

- (Boolean) protobuffs?

Can this node be used for protocol buffers requests?

Returns:

  • (Boolean)


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

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

- (Object) ssl=(value)

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



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

def ssl=(value)
  case value
  when TrueClass
    @ssl_options ||= {}
  when Hash
    (@ssl_options ||= {}).merge!(value)
  end
  value ? ssl_enable : ssl_disable
end

- (Boolean) ssl_enabled?

Checks if SSL is enabled for HTTP

Returns:

  • (Boolean)


91
92
93
# File 'lib/riak/client/node.rb', line 91

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