class Roma::Routing::RoutingData::RandomNodeListMaker

Public Class Methods

new(nodes,repethost) click to toggle source
    # File lib/roma/routing/routing_data.rb
267 def initialize(nodes,repethost)
268   @repethost=repethost
269   @nodes=nodes
270   @host_idx={}
271   nodes.each{|nid|
272     h,p=nid.split('_')
273     if @host_idx.key?(h)
274       @host_idx[h] << nid
275     else
276       @host_idx[h]=[nid]
277     end
278   }          
279 end

Public Instance Methods

get_other_one(exp_hosts,exp_nodes) click to toggle source
exp_hosts

exceptional hosts(ex.)

exp_nodes

ignore

    # File lib/roma/routing/routing_data.rb
308 def get_other_one(exp_hosts,exp_nodes)
309   hidx=@host_idx.clone
310   exp_hosts.each{|h| hidx.delete(h) }
311   return nil if hidx.length == 0
312   
313   rh=hidx.keys[rand(hidx.keys.length)]
314   nodes=hidx[rh]
315   nodes[rand(nodes.length)]
316 end
get_other_one_repethost(exp_hosts,exp_nodes) click to toggle source
exp_hosts

ignore

exp_nodes

exceptional nodes(ex.)

    # File lib/roma/routing/routing_data.rb
300 def get_other_one_repethost(exp_hosts,exp_nodes)
301   buf=@nodes.clone
302   buf.delete_if{|nid| exp_nodes.include?(nid)}
303   buf[rand(buf.length)]
304 end
list(n) click to toggle source

Returns the random node-list without repetition.

n

list length

    # File lib/roma/routing/routing_data.rb
283 def list(n)
284   ret=[]
285   hosts=[]
286   proc_other_one = :get_other_one
287   proc_other_one = :get_other_one_repethost if @repethost
288   n.times{
289     nid=nil
290     nid=send(proc_other_one,hosts,ret)
291     break unless nid
292     hosts << nid.split('_')[0]
293     ret << nid
294   }
295   ret
296 end