KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > server > transport > nio > tcp > DispatcherStrategyFactory


1 package org.sapia.ubik.rmi.server.transport.nio.tcp;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5 import java.util.Properties JavaDoc;
6
7 import org.sapia.ubik.rmi.PropUtil;
8
9 /**
10  * A factory of <code>DispatcherStrategy</code> instances. This class expects
11  * the following property:
12  * <ul>
13  * <li><code>ubik.rmi.transport.nio-tcp.dispatcher.strategy</code>
14  * </ul>
15  * <p>
16  * The property's value should correspond to the logical name of a registered
17  * strategy.
18  *
19  * @author Yanick Duchesne
20  *
21  * <dl>
22  * <dt><b>Copyright: </b>
23  * <dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open
24  * Source Software </a>. All Rights Reserved.</dd>
25  * </dt>
26  * <dt><b>License: </b>
27  * <dd>Read the license.txt file of the jar or visit the <a
28  * HREF="http://www.sapia-oss.org/license.html">license page </a> at the Sapia
29  * OSS web site</dd>
30  * </dt>
31  * </dl>
32  */

33 public class DispatcherStrategyFactory {
34
35   /**
36    * This constant corresponds to the
37    * <code>ubik.rmi.transport.nio-tcp.dispatcher.strategy</code> system
38    * property.
39    */

40   public static final String JavaDoc STRATEGY = "ubik.rmi.transport.nio-tcp.dispatcher.strategy";
41
42   /**
43    * This propety corresponds to the <code>RWPStrategy</code> (property value: <code>rwp</code>).
44    *
45    * @see RWPStrategy
46    */

47   public static final String JavaDoc RWP_STRATEGY = "rwp";
48
49   /**
50    * This propety corresponds to the <code>SingleThreadedStrategy</code> (property value: <code>single-threaded</code>).
51    *
52    * @see SingleThreadedStrategy
53    */

54   public static final String JavaDoc SINGLE_THREADED_STRATEGY = "single-threaded";
55
56   private static Map JavaDoc _strategies = new HashMap JavaDoc();
57
58   static {
59     _strategies.put(RWP_STRATEGY, new RWPStrategy());
60     _strategies.put(SINGLE_THREADED_STRATEGY, new SingleThreadedStrategy());
61   }
62
63   /**
64    * @param name
65    * the logical name of the given strategy.
66    * @param strat
67    * a <code>DispatcherStrategy</code>.
68    */

69   public static void registerStrategy(String JavaDoc name, DispatcherStrategy strat) {
70     if(_strategies.get(name) != null) {
71       throw new IllegalArgumentException JavaDoc("Strategy already registered for: "
72           + name);
73     }
74     _strategies.put(name, strat);
75   }
76
77   /**
78    * @param props
79    * some <code>Properties</code>
80    * @return a <code>DispatcherStrategy</code>.
81    */

82   public static DispatcherStrategy newStrategy(Properties JavaDoc props) {
83     PropUtil propUtil = new PropUtil().addProperties(props).addProperties(
84         System.getProperties());
85     String JavaDoc strategyName = props.getProperty(STRATEGY, RWP_STRATEGY);
86     DispatcherStrategy strat = (DispatcherStrategy) _strategies
87         .get(strategyName);
88     if(strat == null)
89       throw new IllegalArgumentException JavaDoc(
90           "Dispatcher strategy could not be found for: " + strategyName);
91     return strat;
92   }
93
94 }
95
Popular Tags