1 24 25 package org.objectweb.dream.router; 26 27 import java.util.Collection ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 import java.util.Random ; 31 32 import org.objectweb.dream.Push; 33 import org.objectweb.dream.message.Message; 34 35 40 public class RouterRandomImpl extends AbstractRouterImpl 41 { 42 43 Random random = new Random (); 44 Push[] itfs; 45 46 50 protected Push getOutput(Message message, Map context) 51 { 52 if (!initialized) 53 { 54 Collection values = outPushMap.values(); 55 Iterator iter = values.iterator(); 56 itfs = new Push[values.size()]; 57 int i = 0; 58 while (iter.hasNext()) 59 { 60 itfs[i] = (Push) iter.next(); 61 i++; 62 } 63 initialized = true; 64 } 65 if (itfs.length > 0) 66 { 67 return itfs[random.nextInt(itfs.length)]; 68 } 69 return null; 70 } 71 72 } | Popular Tags |