Class: Roma::Routing::RoutingData::RandomNodeListMaker

Inherits:
Object
  • Object
show all
Defined in:
lib/roma/client/routing/routing_data.rb

Instance Method Summary collapse

Constructor Details

#initialize(nodes, repethost) ⇒ RandomNodeListMaker

Returns a new instance of RandomNodeListMaker.



186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/roma/client/routing/routing_data.rb', line 186

def initialize(nodes,repethost)
  @repethost=repethost
  @nodes=nodes
  @host_idx={}
  nodes.each{|nid|
    h,p=nid.split('_')
    if @host_idx.key?(h)
      @host_idx[h] << nid
    else
      @host_idx[h]=[nid]
    end
  }          
end

Instance Method Details

#get_other_one(exp_hosts, exp_nodes) ⇒ Object

exp_hosts

exceptional hosts(ex.)

exp_nodes

ignore



227
228
229
230
231
232
233
234
235
# File 'lib/roma/client/routing/routing_data.rb', line 227

def get_other_one(exp_hosts,exp_nodes)
  hidx=@host_idx.clone
  exp_hosts.each{|h| hidx.delete(h) }
  return nil if hidx.length == 0
  
  rh=hidx.keys[rand(hidx.keys.length)]
  nodes=hidx[rh]
  nodes[rand(nodes.length)]
end

#get_other_one_repethost(exp_hosts, exp_nodes) ⇒ Object

exp_hosts

ignore

exp_nodes

exceptional nodes(ex.)



219
220
221
222
223
# File 'lib/roma/client/routing/routing_data.rb', line 219

def get_other_one_repethost(exp_hosts,exp_nodes)
  buf=@nodes.clone
  buf.delete_if{|nid| exp_nodes.include?(nid)}
  buf[rand(buf.length)]
end

#list(n) ⇒ Object

Returns the random node-list without repetition.

n

list length



202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/roma/client/routing/routing_data.rb', line 202

def list(n)
  ret=[]
  hosts=[]
  proc_other_one = :get_other_one
  proc_other_one = :get_other_one_repethost if @repethost
  n.times{
    nid=nil
    nid=send(proc_other_one,hosts,ret)
    break unless nid
    hosts << nid.split('_')[0]
    ret << nid
  }
  ret
end