CVS update: JGroups/src/org/jgroups/conf ProtocolConfiguration.java ProtocolData.java ConfiguratorFactory.java
"Bela Ban" <[email protected]> Thu, 16 Sep 2010 07:30:08 +0000
| Newsgroups | gmane.comp.java.javagroups.cvs |
|---|---|
| Message-ID | <[email protected]> |
User: belaban
Date: 10/09/16 07:30:08
Modified: src/org/jgroups/conf ProtocolConfiguration.java
ProtocolData.java ConfiguratorFactory.java
Log:
ns
Revision Changes Path
1.2 +77 -19 JGroups/src/org/jgroups/conf/ProtocolConfiguration.java
Index: ProtocolConfiguration.java
===================================================================
RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/conf/ProtocolConfiguration.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProtocolConfiguration.java 15 Sep 2010 15:48:55 -0000 1.1
+++ ProtocolConfiguration.java 16 Sep 2010 07:30:08 -0000 1.2
@@ -13,7 +13,7 @@
* Parses and encapsulates the specification for 1 protocol of the protocol stack, e.g.
* <code>UNICAST(timeout=5000)</code>
* @author Bela Ban
- * @version $Id: ProtocolConfiguration.java,v 1.1 2010/09/15 15:48:55 belaban Exp $
+ * @version $Id: ProtocolConfiguration.java,v 1.2 2010/09/16 07:30:08 belaban Exp $
*/
public class ProtocolConfiguration {
private final String protocol_name;
@@ -63,25 +63,7 @@
return props;
}
- private void parsePropertiesString(String properties_str, Map<String, String> properties) throws Exception {
- int index=0;
- /* "in_port=5555;out_port=6666" */
- if(properties_str.length() > 0) {
- String[] components=properties_str.split(";");
- for(String property : components) {
- String name, value;
- index=property.indexOf('=');
- if(index == -1) {
- throw new Exception("Configurator.ProtocolConfiguration(): '=' not found in " + property
- + " of " + protocol_name);
- }
- name=property.substring(0, index);
- value=property.substring(index + 1, property.length());
- properties.put(name, value);
- }
- }
- }
public void substituteVariables() {
for(Iterator<Map.Entry<String, String>> it=properties.entrySet().iterator(); it.hasNext();) {
@@ -120,5 +102,81 @@
return Util.printMapWithDelimiter(properties, ";");
}
+ public String getProtocolString(boolean new_format) {
+ return new_format? getProtocolStringNewXml() : getProtocolString();
+ }
+
+ public String getProtocolString() {
+ StringBuilder buf=new StringBuilder(protocol_name);
+ if(!properties.isEmpty()) {
+ boolean first=true;
+ buf.append('(');
+ for(Map.Entry<String,String> entry: properties.entrySet()) {
+ String key=entry.getKey();
+ String val=entry.getValue();
+ if(first)
+ first=false;
+ else
+ buf.append(';');
+ buf.append(getParameterString(key, val));
+ }
+ buf.append(')');
+ }
+ return buf.toString();
+ }
+
+
+ public String getProtocolStringNewXml() {
+ StringBuilder buf=new StringBuilder(protocol_name + ' ');
+ if(!properties.isEmpty()) {
+ boolean first=true;
+ for(Map.Entry<String,String> entry: properties.entrySet()) {
+ String key=entry.getKey();
+ String val=entry.getValue();
+ if(first)
+ first=false;
+ else
+ buf.append(' ');
+ buf.append(getParameterStringXml(key, val));
+ }
+ }
+ return buf.toString();
+ }
+
+ protected static String getParameterString(String name, String value) {
+ StringBuilder buf=new StringBuilder(name);
+ if(value != null)
+ buf.append('=').append(value);
+ return buf.toString();
+ }
+
+ protected static String getParameterStringXml(String name, String val) {
+ StringBuilder buf=new StringBuilder(name);
+ if(val != null)
+ buf.append("=\"").append(val).append('\"');
+ return buf.toString();
+ }
+
+
+
+ protected void parsePropertiesString(String properties_str, Map<String, String> properties) throws Exception {
+ int index=0;
+
+ /* "in_port=5555;out_port=6666" */
+ if(properties_str.length() > 0) {
+ String[] components=properties_str.split(";");
+ for(String property : components) {
+ String name, value;
+ index=property.indexOf('=');
+ if(index == -1) {
+ throw new Exception("Configurator.ProtocolConfiguration(): '=' not found in " + property
+ + " of " + protocol_name);
+ }
+ name=property.substring(0, index);
+ value=property.substring(index + 1, property.length());
+ properties.put(name, value);
+ }
+ }
+ }
}
\ No newline at end of file
1.14 +5 -3 JGroups/src/org/jgroups/conf/ProtocolData.java
Index: ProtocolData.java
===================================================================
RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/conf/ProtocolData.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ProtocolData.java 16 Sep 2010 07:13:53 -0000 1.13
+++ ProtocolData.java 16 Sep 2010 07:30:08 -0000 1.14
@@ -5,13 +5,15 @@
* Data holder for protocol
* @author Filip Hanik (<a href="mailto:[email protected]">[email protected])
* @author Bela Ban
- * @version $Id: ProtocolData.java,v 1.13 2010/09/16 07:13:53 belaban Exp $
+ * @version $Id: ProtocolData.java,v 1.14 2010/09/16 07:30:08 belaban Exp $
*/
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
+
+
+
public class ProtocolData {
/** Map<String,ProtocolParameter> of property keys and values */
private final Map<String,String> mParameters=new HashMap<String,String>();
@@ -44,7 +46,7 @@
}
- public Map getParameters() {
+ public Map<String,String> getParameters() {
return mParameters;
}
1.30 +10 -19 JGroups/src/org/jgroups/conf/ConfiguratorFactory.java
Index: ConfiguratorFactory.java
===================================================================
RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/conf/ConfiguratorFactory.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- ConfiguratorFactory.java 13 May 2009 13:07:04 -0000 1.29
+++ ConfiguratorFactory.java 16 Sep 2010 07:30:08 -0000 1.30
@@ -25,7 +25,7 @@
*
* @author Filip Hanik (<a href="mailto:[email protected]">[email protected])
* @author Bela Ban
- * @version $Id: ConfiguratorFactory.java,v 1.29 2009/05/13 13:07:04 belaban Exp $
+ * @version $Id: ConfiguratorFactory.java,v 1.30 2010/09/16 07:30:08 belaban Exp $
*/
public class ConfiguratorFactory {
public static final String JAXP_MISSING_ERROR_MSG=
@@ -408,28 +408,19 @@
* @param configurator
*/
public static void substituteVariables(ProtocolStackConfigurator configurator) {
-
- ProtocolData[] protocols=null;
- try {
- protocols=configurator.getProtocolStack();
-
- for(ProtocolData protocol:protocols) {
- if(protocol != null) {
- Map<String,ProtocolParameter> parms=protocol.getParameters();
- ProtocolParameter parm;
- for(Map.Entry<String,ProtocolParameter> entry:parms.entrySet()) {
- parm=entry.getValue();
- String val=parm.getValue();
- String replacement=Util.substituteVariable(val);
- if(!replacement.equals(val)) {
- parm.setValue(replacement);
- }
+ ProtocolData[] protocols=configurator.getProtocolStack();
+ for(ProtocolData data: protocols) {
+ if(data != null) {
+ Map<String,String> parms=data.getParameters();
+ for(Map.Entry<String,String> entry:parms.entrySet()) {
+ String val=entry.getValue();
+ String replacement=Util.substituteVariable(val);
+ if(!replacement.equals(val)) {
+ entry.setValue(replacement);
}
}
}
}
- catch(Exception ignored) {
- }
}
}
------------------------------------------------------------------------------
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