Class: Droonga::Catalog::Generator::Replicas

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Replicas

Returns a new instance of Replicas.



175
176
177
178
179
180
# File 'lib/droonga/catalog/generator.rb', line 175

def initialize(options={})
  @hosts    = options[:hosts] || DEFAULT_HOSTS
  @port     = options[:port]
  @tag      = options[:tag]
  @n_slices = options[:n_slices]
end

Instance Attribute Details

#hostsObject

Returns the value of attribute hosts.



172
173
174
# File 'lib/droonga/catalog/generator.rb', line 172

def hosts
  @hosts
end

#n_slicesObject (readonly)

Returns the value of attribute n_slices.



173
174
175
# File 'lib/droonga/catalog/generator.rb', line 173

def n_slices
  @n_slices
end

#portObject (readonly)

Returns the value of attribute port.



173
174
175
# File 'lib/droonga/catalog/generator.rb', line 173

def port
  @port
end

#tagObject (readonly)

Returns the value of attribute tag.



173
174
175
# File 'lib/droonga/catalog/generator.rb', line 173

def tag
  @tag
end

Instance Method Details

#load(catalog_replicas) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/droonga/catalog/generator.rb', line 182

def load(catalog_replicas)
  dataset = Catalog::Dataset.new("temporary",
                                 "replicas" => catalog_replicas)
  @hosts = dataset.replicas.collect do |replica|
    replica.slices.first.volume.address.host
  end
  collection_volume = dataset.replicas.first
  slices = collection_volume.slices
  @n_slices = slices.size
  single_volume_address = slices.first.volume.address
  @port = single_volume_address.port
  @tag  = single_volume_address.tag
end

#to_catalogObject



196
197
198
199
200
201
202
203
204
205
# File 'lib/droonga/catalog/generator.rb', line 196

def to_catalog
  catalog_replicas = []
  @hosts.each do |host|
    replica = Replica.new(host, :port => @port,
                                :tag => @tag,
                                :n_slices => @n_slices)
    catalog_replicas << replica.to_catalog
  end
  catalog_replicas
end