On Wed, Jun 22, 2011 at 4:19 PM, Iραki Baz Castillo <ibc / aliax.net> wrote: > 2011/6/22 Robert Klemme <shortcutter / googlemail.com>: >> Hm... ¨Βοχ αν ξοσυςε αξνοςε χθετθεωοξεεδ ασσογιατιφ>> container at all. ¨Βοχ χε θαφε τθςεστεπσ® ¨Βςοχθατ υξδεςσταξδ >> you do: >> >> 1. items are collected >> 2. items are ordered by priority (what you call second container above) >> 3. items are ordered by some randomization algorithm >> >> I'm obviously missing other access operations out here. ¨Βζα>> don't see any need for a Hash or similar structure. ¨Βθαεμσε ισ ιτ >> that you need to do with these items? ¨Βθαπςοπεςτιεσ δο τθεω θαφε> > > Step 1) > > I get data (DNS SRV records), which is an array with entries like this: > > <EventMachine::Udns::RR_SRV:0x00000001ea4970 @domain="domain.org", > @priority=1, @weight=50, @port=5062> > > Each entry is a SRV record. It has a priority (lowest value is the > best) and weight (higher value means more probability to choose it). > > The client getting such array of SRV records wants to connect to a > server based on SRV priorities/weight, which works as follows: > - SRV records with best priority must be used first. > - If there are various SRV records with same priority, then the > probability of choosing each one depends on its weight value (random > with weight). > - If the chosen SRV record fails to connect (i.e. server down) next > one (based on same priority/weight rules) must be tryed. Aha! This is how I'd probably do it. https://gist.github.com/1040631 Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/