1 package org.sapia.ubik.rmi.server.transport.nio.tcp; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 import java.util.Properties ; 6 7 import org.sapia.ubik.rmi.PropUtil; 8 9 33 public class DispatcherStrategyFactory { 34 35 40 public static final String STRATEGY = "ubik.rmi.transport.nio-tcp.dispatcher.strategy"; 41 42 47 public static final String RWP_STRATEGY = "rwp"; 48 49 54 public static final String SINGLE_THREADED_STRATEGY = "single-threaded"; 55 56 private static Map _strategies = new HashMap (); 57 58 static { 59 _strategies.put(RWP_STRATEGY, new RWPStrategy()); 60 _strategies.put(SINGLE_THREADED_STRATEGY, new SingleThreadedStrategy()); 61 } 62 63 69 public static void registerStrategy(String name, DispatcherStrategy strat) { 70 if(_strategies.get(name) != null) { 71 throw new IllegalArgumentException ("Strategy already registered for: " 72 + name); 73 } 74 _strategies.put(name, strat); 75 } 76 77 82 public static DispatcherStrategy newStrategy(Properties props) { 83 PropUtil propUtil = new PropUtil().addProperties(props).addProperties( 84 System.getProperties()); 85 String strategyName = props.getProperty(STRATEGY, RWP_STRATEGY); 86 DispatcherStrategy strat = (DispatcherStrategy) _strategies 87 .get(strategyName); 88 if(strat == null) 89 throw new IllegalArgumentException ( 90 "Dispatcher strategy could not be found for: " + strategyName); 91 return strat; 92 } 93 94 } 95 | Popular Tags |