CVS update: JGroups/src/org/jgroups/stack ProtocolStack.java Configurator.java
"Bela Ban" <[email protected]> Thu, 16 Sep 2010 14:21:41 +0000
| Newsgroups | gmane.comp.java.javagroups.cvs |
|---|---|
| Message-ID | <[email protected]> |
User: belaban
Date: 10/09/16 14:21:41
Modified: src/org/jgroups/stack ProtocolStack.java Configurator.java
Log:
ns
Revision Changes Path
1.105 +11 -15 JGroups/src/org/jgroups/stack/ProtocolStack.java
Index: ProtocolStack.java
===================================================================
RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/stack/ProtocolStack.java,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -r1.104 -r1.105
--- ProtocolStack.java 13 Sep 2010 12:58:57 -0000 1.104
+++ ProtocolStack.java 16 Sep 2010 14:21:41 -0000 1.105
@@ -4,6 +4,7 @@
import org.jgroups.annotations.Property;
import org.jgroups.conf.ClassConfigurator;
import org.jgroups.conf.PropertyConverter;
+import org.jgroups.conf.ProtocolConfiguration;
import org.jgroups.protocols.TP;
import org.jgroups.util.ThreadFactory;
import org.jgroups.util.TimeScheduler;
@@ -29,7 +30,7 @@
* stacks, and to destroy them again when not needed anymore
*
* @author Bela Ban
- * @version $Id: ProtocolStack.java,v 1.104 2010/09/13 12:58:57 belaban Exp $
+ * @version $Id: ProtocolStack.java,v 1.105 2010/09/16 14:21:41 belaban Exp $
*/
public class ProtocolStack extends Protocol implements Transport {
public static final int ABOVE = 1; // used by insertProtocol()
@@ -44,11 +45,11 @@
- private Protocol top_prot = null;
- private Protocol bottom_prot = null;
- private String setup_string;
- private JChannel channel = null;
- private volatile boolean stopped=true;
+ private Protocol top_prot;
+ private Protocol bottom_prot;
+ protected List<ProtocolConfiguration> configs;
+ private JChannel channel;
+ private volatile boolean stopped=true;
private final TP.ProbeHandler props_handler=new TP.ProbeHandler() {
@@ -71,8 +72,8 @@
};
- public ProtocolStack(JChannel channel, String setup_string) throws ChannelException {
- this.setup_string=setup_string;
+ public ProtocolStack(JChannel channel, List<ProtocolConfiguration> configs) throws ChannelException {
+ this.configs=configs;
this.channel=channel;
Class<?> tmp=ClassConfigurator.class; // load this class, trigger init()
@@ -85,17 +86,12 @@
}
-
/** Only used by Simulator; don't use */
public ProtocolStack() throws ChannelException {
this(null,null);
}
- public String getSetupString() {
- return setup_string;
- }
-
/**
* @deprecated Use {@link org.jgroups.stack.Protocol#getThreadFactory()} instead
* @return
@@ -466,7 +462,7 @@
public void setup() throws Exception {
if(top_prot == null) {
- top_prot=getProtocolStackFactory().setupProtocolStack();
+ top_prot=getProtocolStackFactory().setupProtocolStack(configs);
top_prot.setUpProtocol(this);
this.setDownProtocol(top_prot);
bottom_prot=getBottomProtocol();
@@ -961,7 +957,7 @@
}
public interface ProtocolStackFactory{
- public Protocol setupProtocolStack() throws Exception;
+ public Protocol setupProtocolStack(List<ProtocolConfiguration> cfg) throws Exception;
public Protocol setupProtocolStack(ProtocolStack copySource) throws Exception;
}
1.85 +36 -37 JGroups/src/org/jgroups/stack/Configurator.java
Index: Configurator.java
===================================================================
RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/stack/Configurator.java,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -r1.84 -r1.85
--- Configurator.java 15 Sep 2010 15:49:42 -0000 1.84
+++ Configurator.java 16 Sep 2010 14:21:41 -0000 1.85
@@ -37,23 +37,23 @@
* of the protocol stack and the properties of each layer.
* @author Bela Ban
* @author Richard Achmatowicz
- * @version $Id: Configurator.java,v 1.84 2010/09/15 15:49:42 belaban Exp $
+ * @version $Id: Configurator.java,v 1.85 2010/09/16 14:21:41 belaban Exp $
*/
public class Configurator implements ProtocolStackFactory {
-
protected static final Log log=LogFactory.getLog(Configurator.class);
private final ProtocolStack stack;
+
public Configurator() {
- stack = null;
+ stack=null;
}
public Configurator(ProtocolStack protocolStack) {
stack=protocolStack;
}
- public Protocol setupProtocolStack() throws Exception{
- return setupProtocolStack(stack.getSetupString(), stack);
+ public Protocol setupProtocolStack(List<ProtocolConfiguration> config) throws Exception{
+ return setupProtocolStack(config, stack);
}
public Protocol setupProtocolStack(ProtocolStack copySource)throws Exception{
@@ -85,9 +85,8 @@
* -----------------------
* </pre>
*/
- private static Protocol setupProtocolStack(String configuration, ProtocolStack st) throws Exception {
- Vector<ProtocolConfiguration> protocol_configs=parseConfigurations(configuration);
- Vector<Protocol> protocols=createProtocols(protocol_configs, st);
+ private static Protocol setupProtocolStack(List<ProtocolConfiguration> protocol_configs, ProtocolStack st) throws Exception {
+ List<Protocol> protocols=createProtocols(protocol_configs, st);
if(protocols == null)
return null;
// basic protocol sanity check
@@ -159,14 +158,14 @@
* @param protocol_list List of Protocol elements (from top to bottom)
* @return Protocol stack
*/
- private static Protocol connectProtocols(Vector<Protocol> protocol_list) {
+ private static Protocol connectProtocols(List<Protocol> protocol_list) {
Protocol current_layer=null, next_layer=null;
for(int i=0; i < protocol_list.size(); i++) {
- current_layer=protocol_list.elementAt(i);
+ current_layer=protocol_list.get(i);
if(i + 1 >= protocol_list.size())
break;
- next_layer=protocol_list.elementAt(i + 1);
+ next_layer=protocol_list.get(i + 1);
next_layer.setDownProtocol(current_layer);
current_layer.setUpProtocol(next_layer);
@@ -199,8 +198,8 @@
* @param config_str Configuration string
* @return Vector of strings
*/
- private static Vector<String> parseProtocols(String config_str) throws IOException {
- Vector<String> retval=new Vector<String>();
+ private static List<String> parseProtocols(String config_str) throws IOException {
+ List<String> retval=new LinkedList<String>();
PushbackReader reader=new PushbackReader(new StringReader(config_str));
int ch;
StringBuilder sb;
@@ -261,17 +260,17 @@
/**
* Return a number of ProtocolConfigurations in a vector
* @param configuration protocol-stack configuration string
- * @return Vector of ProtocolConfigurations
+ * @return List of ProtocolConfigurations
*/
- public static Vector<ProtocolConfiguration> parseConfigurations(String configuration) throws Exception {
- Vector<ProtocolConfiguration> retval=new Vector<ProtocolConfiguration>();
- Vector<String> protocol_string=parseProtocols(configuration);
+ public static List<ProtocolConfiguration> parseConfigurations(String configuration) throws Exception {
+ List<ProtocolConfiguration> retval=new ArrayList<ProtocolConfiguration>();
+ List<String> protocol_string=parseProtocols(configuration);
if(protocol_string == null)
return null;
- for(String component_string:protocol_string) {
- retval.addElement(new ProtocolConfiguration(component_string));
+ for(String component_string: protocol_string) {
+ retval.add(new ProtocolConfiguration(component_string));
}
return retval;
}
@@ -328,16 +327,16 @@
* each ProtocolConfiguration and returns all Protocols in a vector.
* @param protocol_configs Vector of ProtocolConfigurations
* @param stack The protocol stack
- * @return Vector of Protocols
+ * @return List of Protocols
*/
- private static Vector<Protocol> createProtocols(Vector<ProtocolConfiguration> protocol_configs, final ProtocolStack stack) throws Exception {
- Vector<Protocol> retval=new Vector<Protocol>();
+ private static List<Protocol> createProtocols(List<ProtocolConfiguration> protocol_configs, final ProtocolStack stack) throws Exception {
+ List<Protocol> retval=new LinkedList<Protocol>();
ProtocolConfiguration protocol_config;
Protocol layer;
String singleton_name;
for(int i=0; i < protocol_configs.size(); i++) {
- protocol_config=protocol_configs.elementAt(i);
+ protocol_config=protocol_configs.get(i);
singleton_name=protocol_config.getProperties().get(Global.SINGLETON_NAME);
if(singleton_name != null && singleton_name.trim().length() > 0) {
Map<String,Tuple<TP, ProtocolStack.RefCounter>> singleton_transports=ProtocolStack.getSingletonTransports();
@@ -356,7 +355,7 @@
if(layer == null)
return null;
singleton_transports.put(singleton_name, new Tuple<TP, ProtocolStack.RefCounter>((TP)layer,new ProtocolStack.RefCounter((short)0,(short)0)));
- retval.addElement(layer);
+ retval.add(layer);
}
}
continue;
@@ -364,7 +363,7 @@
layer=createLayer(stack, protocol_config);
if(layer == null)
return null;
- retval.addElement(layer);
+ retval.add(layer);
}
return retval;
}
@@ -444,23 +443,23 @@
/**
Throws an exception if sanity check fails. Possible sanity check is uniqueness of all protocol names
*/
- public static void sanityCheck(Vector<Protocol> protocols) throws Exception {
- Vector<String> names=new Vector<String>();
+ public static void sanityCheck(List<Protocol> protocols) throws Exception {
+ List<String> names=new ArrayList<String>();
Protocol prot;
String name;
- Vector<ProtocolReq> req_list=new Vector<ProtocolReq>();
+ List<ProtocolReq> req_list=new ArrayList<ProtocolReq>();
// Checks for unique names
for(int i=0; i < protocols.size(); i++) {
- prot=protocols.elementAt(i);
+ prot=protocols.get(i);
name=prot.getName();
for(int j=0; j < names.size(); j++) {
- if(name.equals(names.elementAt(j))) {
+ if(name.equals(names.get(j))) {
throw new Exception("Configurator.sanityCheck(): protocol name " + name +
" has been used more than once; protocol names have to be unique !");
}
}
- names.addElement(name);
+ names.add(name);
}
// check for unique IDs
@@ -568,8 +567,8 @@
* where InetAddressInfo instances encapsulate the InetAddress related information
* of the Fields and Methods.
*/
- public static Map<String, Map<String,InetAddressInfo>> createInetAddressMap(Vector<ProtocolConfiguration> protocol_configs,
- Vector<Protocol> protocols) throws Exception {
+ public static Map<String, Map<String,InetAddressInfo>> createInetAddressMap(List<ProtocolConfiguration> protocol_configs,
+ List<Protocol> protocols) throws Exception {
// Map protocol -> Map<String, InetAddressInfo>, where the latter is protocol specific
Map<String, Map<String,InetAddressInfo>> inetAddressMap = new HashMap<String, Map<String, InetAddressInfo>>() ;
@@ -664,7 +663,7 @@
* - if the defaultValue attribute is not "", generate a value for the field using the
* property converter for that property and assign it to the field
*/
- public static void setDefaultValues(Vector<ProtocolConfiguration> protocol_configs, Vector<Protocol> protocols,
+ public static void setDefaultValues(List<ProtocolConfiguration> protocol_configs, List<Protocol> protocols,
StackType ip_version) throws Exception {
InetAddress default_ip_address=Util.getNonLoopbackAddress();
if(default_ip_address == null) {
@@ -770,7 +769,7 @@
/** Check whether any of the protocols 'below' provide evt_type */
- static boolean providesUpServices(Vector<ProtocolReq> req_list, int evt_type) {
+ static boolean providesUpServices(List<ProtocolReq> req_list, int evt_type) {
for (ProtocolReq pr:req_list){
if(pr.providesUpService(evt_type))
return true;
@@ -780,8 +779,8 @@
/** Checks whether any of the protocols 'above' provide evt_type */
- static boolean providesDownServices(Vector<ProtocolReq> req_list, int evt_type) {
- for (ProtocolReq pr:req_list){
+ static boolean providesDownServices(List<ProtocolReq> req_list, int evt_type) {
+ for(ProtocolReq pr:req_list){
if(pr.providesDownService(evt_type))
return true;
}
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev