Class: Droonga::CatalogGenerator::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.



174
175
176
177
178
179
# File 'lib/droonga/catalog_generator.rb', line 174

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.



171
172
173
# File 'lib/droonga/catalog_generator.rb', line 171

def hosts
  @hosts
end

#n_slicesObject (readonly)

Returns the value of attribute n_slices.



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

def n_slices
  @n_slices
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

#tagObject (readonly)

Returns the value of attribute tag.



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

def tag
  @tag
end

Instance Method Details

#load(catalog_replicas) ⇒ Object



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

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



195
196
197
198
199
200
201
202
203
204
# File 'lib/droonga/catalog_generator.rb', line 195

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