Class: Clustr::Adapter::SimpleDB

Inherits:
Base
  • Object
show all
Defined in:
lib/clustr/adapter/simpledb.rb

Overview

Implements the SimpleDB adapter, which controls a cluster and its members through the usage of SimpleDB as a centralized, high-availability data store.

SimpleDB is capable of storing unique node identifiers along with additional information that is to be associated with them.

Instance Attribute Summary

Attributes inherited from Base

#key

Instance Method Summary collapse

Constructor Details

#initialize(*a) ⇒ SimpleDB

Initializes a new SimpleDB Adapter class. If the domain that has been defined in the @key attribute does not exist, it will create it.



14
15
16
17
# File 'lib/clustr/adapter/simpledb.rb', line 14

def initialize(*a)
  super
  sdb.domains.create(@key) unless domain.exists?
end

Instance Method Details

#add(id, created, properties = {}) ⇒ boolean

Add a new node to the SimpleDB domain.

Parameters:

  • Unique ID of the node to add.

  • timestamp of the node.

  • (defaults to: {})

    additional properties to add for the node.

Returns:

  • True if node was added successfully, false otherwise.



26
27
28
29
30
31
# File 'lib/clustr/adapter/simpledb.rb', line 26

def add(id, created, properties = {})
  item = domain.items[id]
  properties.each { |k, v| item.attributes[k] = v }
  item.attributes["joined"] = created
  true
end

#membersarray

Return an array of the unique identifiers for each node in the cluster.

Returns:

  • an array containing the unique ids for each node.



37
38
39
# File 'lib/clustr/adapter/simpledb.rb', line 37

def members
  domain.items.collect(&:name)
end