axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From az...@apache.org
Subject svn commit: r706739 - /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ClusterBuilder.java
Date Tue, 21 Oct 2008 20:01:36 GMT
Author: azeez
Date: Tue Oct 21 13:01:36 2008
New Revision: 706739

URL: http://svn.apache.org/viewvc?rev=706739&view=rev
Log:
Adding the ability to provide WKA member details as System properties or environment variables
in the axis2.xml's cluster configuration section. This will be very handy even for other Axis2
configuration builders. If so, the replaceVariables should be moved to a utility class.

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ClusterBuilder.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ClusterBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ClusterBuilder.java?rev=706739&r1=706738&r2=706739&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ClusterBuilder.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ClusterBuilder.java
Tue Oct 21 13:01:36 2008
@@ -96,7 +96,7 @@
             loadApplicationDomains(clusterManager, clusterElement);
 
             // loading the members
-            loadMembers(clusterManager, clusterElement);
+            loadWellKnownMembers(clusterManager, clusterElement);
 
             //loading the ConfigurationManager
             loadConfigManager(clusterElement, clusterManager);
@@ -124,7 +124,7 @@
     private void loadApplicationDomains(ClusterManager clusterManager,
                                         OMElement clusterElement) throws DeploymentException
{
         OMElement lbEle = clusterElement.getFirstChildWithName(new QName("loadBalancer"));
-        if(lbEle != null){
+        if (lbEle != null) {
             if (isEnabled(lbEle)) {
                 log.info("Running in load balance mode");
             } else {
@@ -132,8 +132,8 @@
                 return;
             }
 
-            for(Iterator iter= lbEle.getChildrenWithName(new QName("applicationDomain"));
-                iter.hasNext();){
+            for (Iterator iter = lbEle.getChildrenWithName(new QName("applicationDomain"));
+                 iter.hasNext();) {
                 OMElement omElement = (OMElement) iter.next();
                 String domainName = omElement.getAttributeValue(new QName("name")).trim();
                 String handlerClass = omElement.getAttributeValue(new QName("handler")).trim();
@@ -150,8 +150,8 @@
             }
         }
     }
-            
-    private void loadMembers(ClusterManager clusterManager, OMElement clusterElement) {
+
+    private void loadWellKnownMembers(ClusterManager clusterManager, OMElement clusterElement)
{
         clusterManager.setMembers(new ArrayList<Member>());
         Parameter membershipSchemeParam = clusterManager.getParameter("membershipScheme");
         if (membershipSchemeParam != null) {
@@ -161,14 +161,14 @@
                 OMElement membersEle =
                         clusterElement.getFirstChildWithName(new QName("members"));
                 if (membersEle != null) {
-                    for (Iterator iter = membersEle.getChildrenWithLocalName("member"); iter.hasNext();)
-                    {
+                    for (Iterator iter = membersEle.getChildrenWithLocalName("member"); iter.hasNext();)
{
                         OMElement memberEle = (OMElement) iter.next();
                         String hostName =
                                 memberEle.getFirstChildWithName(new QName("hostName")).getText().trim();
                         String port =
                                 memberEle.getFirstChildWithName(new QName("port")).getText().trim();
-                        members.add(new Member(hostName, Integer.parseInt(port)));
+                        members.add(new Member(replaceVariables(hostName),
+                                               Integer.parseInt(replaceVariables(port))));
                     }
                 }
                 clusterManager.setMembers(members);
@@ -176,6 +176,30 @@
         }
     }
 
+    private String replaceVariables(String text) {
+        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 var = text.substring(indexOfStartingChars + 2,
+                                        indexOfClosingBrace);
+
+            String propValue = System.getProperty(var);
+            if (propValue == null) {
+                propValue = System.getenv(var);
+            }
+            if (propValue != null) {
+                text = text.substring(0, indexOfStartingChars) + propValue +
+                       text.substring(indexOfClosingBrace + 1);
+            }
+        }
+        return text;
+    }
+
     private void loadContextManager(OMElement clusterElement,
                                     ClusterManager clusterManager) throws DeploymentException,
                                                                           InstantiationException,



Mime
View raw message