Class: Droonga::NodeRole

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/node_role.rb

Constant Summary collapse

SERVICE_PROVIDER =
"service-provider".downcase
ABSORB_SOURCE =
"absorb-source".downcase
ABSORB_DESTINATION =
"absorb-destination".downcase
ANY =
"any".downcase
ROLES =

XXX ANY is not a valid role for a node. It is used just for checking acceptability of messages.

[
  SERVICE_PROVIDER,
  ABSORB_SOURCE,
  ABSORB_DESTINATION,
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role) ⇒ NodeRole

Returns a new instance of NodeRole.



55
56
57
# File 'lib/droonga/node_role.rb', line 55

def initialize(role)
  @role = normalize(role)
end

Class Method Details

.mineObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/droonga/node_role.rb', line 42

def mine
  if Path.serf_tags_file.exist?
    tags = Path.serf_tags_file.read
    tags = JSON.parse(tags)
    role_from_tag = tags[Serf::Tag.node_role]
    return role_from_tag.downcase if role_from_tag
  end
  SERVICE_PROVIDER
rescue Errno::ENOENT, JSON::ParserError
  SERVICE_PROVIDER
end

.normalize(role) ⇒ Object



38
39
40
# File 'lib/droonga/node_role.rb', line 38

def normalize(role)
  new(role).to_s
end

Instance Method Details

#to_sObject



59
60
61
# File 'lib/droonga/node_role.rb', line 59

def to_s
  @role
end