You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by az...@apache.org on 2008/12/09 05:29:27 UTC
svn commit: r724606 - in /webservices/axis2/trunk/java/modules:
clustering/src/org/apache/axis2/clustering/tribes/
kernel/src/org/apache/axis2/clustering/
Author: azeez
Date: Mon Dec 8 20:29:27 2008
New Revision: 724606
URL: http://svn.apache.org/viewvc?rev=724606&view=rev
Log:
Ability to set member properties which consist of other properties
Modified:
webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java
webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesUtil.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/Member.java
Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java?rev=724606&r1=724605&r2=724606&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java Mon Dec 8 20:29:27 2008
@@ -223,14 +223,14 @@
if (httpTransport != null) {
Parameter port = httpTransport.getParameter("port");
if (port != null) {
- memberInfo.put("HTTP", port.getValue());
+ memberInfo.put("httpPort", port.getValue());
}
}
TransportInDescription httpsTransport = axisConfig.getTransportIn("https");
if (httpsTransport != null) {
Parameter port = httpsTransport.getParameter("port");
if (port != null) {
- memberInfo.put("HTTPS", port.getValue());
+ memberInfo.put("httpPort", port.getValue());
}
}
Parameter isActiveParam = getParameter(ClusteringConstants.Parameters.IS_ACTIVE);
@@ -239,6 +239,9 @@
(String) isActiveParam.getValue());
}
+ memberInfo.setProperty("hostName",
+ TribesUtil.getLocalHost(getParameter(TribesConstants.LOCAL_MEMBER_HOST)));
+
Parameter propsParam = getParameter("properties");
if(propsParam != null){
OMElement paramEle = propsParam.getParameterElement();
@@ -248,13 +251,16 @@
if(nameAttrib != null){
OMAttribute valueAttrib = propEle.getAttribute(new QName("value"));
if (valueAttrib != null) {
- memberInfo.setProperty(nameAttrib.getAttributeValue(),
- valueAttrib.getAttributeValue());
+ String attribVal = valueAttrib.getAttributeValue();
+ attribVal = replaceProperty(attribVal, memberInfo);
+ memberInfo.setProperty(nameAttrib.getAttributeValue(), attribVal);
}
}
}
}
-
+
+ memberInfo.remove("hostName"); // this was needed only to populate other properties. No need to send it.
+
ByteArrayOutputStream bout = new ByteArrayOutputStream();
try {
memberInfo.store(bout, "");
@@ -266,6 +272,26 @@
channel.getMembershipService().setPayload(bout.toByteArray());
}
+ private static String replaceProperty(String text, Properties props) {
+ int indexOfStartingChars;
+ int indexOfClosingBrace;
+
+ // The following condition deals with properties.
+ // Properties are specified as ${system.property},
+ // and are assumed to be System properties
+ if ((indexOfStartingChars = text.indexOf("${")) != -1 &&
+ (indexOfClosingBrace = text.indexOf("}")) != -1) { // Is a property used?
+ String sysProp = text.substring(indexOfStartingChars + 2,
+ indexOfClosingBrace);
+ String propValue = props.getProperty(sysProp);
+ if (propValue != null) {
+ text = text.substring(0, indexOfStartingChars) + propValue +
+ text.substring(indexOfClosingBrace + 1);
+ }
+ }
+ return text;
+ }
+
/**
* Get the membership scheme applicable to this cluster
*
@@ -582,7 +608,7 @@
}
// TODO: If we do not get a response within some time, try to recover from this fault
// }
-// while (responses.length == 0 || responses[0] == null || responses[0].getMessage() == null); // TODO: #### We will need to check this
+// while (responses.length == 0 || responses[0] == null || responses[0].getMessage() == null); // TODO: #### We will need to check this
if (responses.length != 0 && responses[0] != null && responses[0].getMessage() != null) {
((ControlCommand) responses[0].getMessage()).execute(configurationContext); // Do the initialization
break;
Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesUtil.java?rev=724606&r1=724605&r2=724606&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesUtil.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesUtil.java Mon Dec 8 20:29:27 2008
@@ -25,10 +25,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.axis2.clustering.ClusteringConstants;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.util.Utils;
import java.util.Properties;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.net.SocketException;
public class TribesUtil {
@@ -72,6 +75,24 @@
return getName(channel.getLocalMember(true));
}
+ public static String getLocalHost(Parameter tcpListenHost){
+ String host = null;
+ if (tcpListenHost != null) {
+ host = ((String) tcpListenHost.getValue()).trim();
+ } else {
+ try {
+ host = Utils.getIpAddress();
+ } catch (SocketException e) {
+ String msg = "Could not get local IP address";
+ log.error(msg, e);
+ }
+ }
+ if (System.getProperty(ClusteringConstants.LOCAL_IP_ADDRESS) != null) {
+ host = System.getProperty(ClusteringConstants.LOCAL_IP_ADDRESS);
+ }
+ return host;
+ }
+
public static byte[] getRpcMembershipChannelId(byte[] domain) {
return (new String(domain) + ":" + TribesConstants.RPC_MEMBERSHIP_CHANNEL).getBytes();
}
@@ -94,20 +115,23 @@
member.getPort());
Properties props = getProperties(member.getPayload());
- String http = props.getProperty("HTTP");
- if (http != null && http.trim().length() != 0) {
- axis2Member.setHttpPort(Integer.parseInt(http));
+ String httpPort = props.getProperty("httpPort");
+ if (httpPort != null && httpPort.trim().length() != 0) {
+ axis2Member.setHttpPort(Integer.parseInt(httpPort));
}
- String https = props.getProperty("HTTPS");
- if (https != null && https.trim().length() != 0) {
- axis2Member.setHttpsPort(Integer.parseInt(https));
+ String httpsPort = props.getProperty("httpsPort");
+ if (httpsPort != null && httpsPort.trim().length() != 0) {
+ axis2Member.setHttpsPort(Integer.parseInt(httpsPort));
}
String isActive = props.getProperty(ClusteringConstants.Parameters.IS_ACTIVE);
if (isActive != null && isActive.trim().length() != 0) {
axis2Member.setActive(Boolean.valueOf(isActive));
}
+
+ axis2Member.setDomain(new String(member.getDomain()));
+ axis2Member.setProperties(props);
return axis2Member;
}
@@ -122,4 +146,4 @@
}
return props;
}
-}
+}
\ No newline at end of file
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/Member.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/Member.java?rev=724606&r1=724605&r2=724606&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/Member.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/Member.java Mon Dec 8 20:29:27 2008
@@ -1,20 +1,22 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.axis2.clustering;
+import java.util.Properties;
+
/**
* Represents a member in the cluster. This is used with static membership
*/
@@ -45,6 +47,16 @@
*/
private boolean isActive = true;
+ /**
+ * The domain of this member
+ */
+ private String domain;
+
+ /**
+ * Other member specific properties
+ */
+ private Properties properties = new Properties();
+
public Member(String hostName, int port) {
this.hostName = hostName;
this.port = port;
@@ -82,6 +94,22 @@
isActive = active;
}
+ public String getDomain() {
+ return domain;
+ }
+
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+
+ public void setProperties(Properties properties) {
+ this.properties = properties;
+ }
+
+ public Properties getProperties() {
+ return properties;
+ }
+
public boolean equals(Object o) {
if (this == o) {
return true;