On Wed, Jun 22, 2011 at 4:19 PM, Iki 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/