geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject incubator-geode git commit: GEODE-420: Cleaning up code parsing locators string
Date Sun, 11 Sep 2016 23:34:53 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-420 9626269f3 -> 3edfdf2d3


GEODE-420: Cleaning up code parsing locators string


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/3edfdf2d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/3edfdf2d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/3edfdf2d

Branch: refs/heads/feature/GEODE-420
Commit: 3edfdf2d3e455bca113c0800532b2f12d3c0b19f
Parents: 9626269
Author: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Authored: Mon Sep 12 09:34:42 2016 +1000
Committer: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Committed: Mon Sep 12 09:34:42 2016 +1000

----------------------------------------------------------------------
 .../admin/remote/RemoteTransportConfig.java     | 192 +++++++++----------
 1 file changed, 88 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3edfdf2d/geode-core/src/main/java/com/gemstone/gemfire/internal/admin/remote/RemoteTransportConfig.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/admin/remote/RemoteTransportConfig.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/admin/remote/RemoteTransportConfig.java
index d846fa1..0272685 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/admin/remote/RemoteTransportConfig.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/admin/remote/RemoteTransportConfig.java
@@ -16,23 +16,28 @@
  */
 package com.gemstone.gemfire.internal.admin.remote;
 
+import static com.gemstone.gemfire.distributed.ConfigurationProperties.*;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+import java.util.StringTokenizer;
+
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.internal.Assert;
 import com.gemstone.gemfire.internal.admin.SSLConfig;
 import com.gemstone.gemfire.internal.admin.TransportConfig;
 import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
-
-import java.util.*;
-
-import static com.gemstone.gemfire.distributed.ConfigurationProperties.*;
+import com.gemstone.gemfire.internal.lang.StringUtils;
 
 /**
  * Tranport config for RemoteGfManagerAgent.
- * 
- *
  */
 public class RemoteTransportConfig implements TransportConfig {
-  
+
   private final boolean mcastEnabled;
   private final boolean tcpDisabled;
   private final boolean disableAutoReconnect;
@@ -55,7 +60,6 @@ public class RemoteTransportConfig implements TransportConfig {
    * configuration information in a <code>DistributionConfig</code>.
    * We assume that <code>config</code> already been checked for
    * errors.
-   *
    * @since GemFire 3.0
    */
   public RemoteTransportConfig(DistributionConfig config, int vmKind) {
@@ -66,27 +70,23 @@ public class RemoteTransportConfig implements TransportConfig {
     }
     this.vmKind = vmKind;
     this.tcpPort = config.getTcpPort();
-    this.membershipPortRange = 
-            getMembershipPortRangeString(config.getMembershipPortRange());
+    this.membershipPortRange = getMembershipPortRangeString(config.getMembershipPortRange());
     this.sslConfig = new SSLConfig();
-    
+
     String initialHosts = config.getLocators();
-    if (initialHosts == null)
+    if (initialHosts == null) {
       initialHosts = "";
+    }
     initialHosts = initialHosts.trim();
-    
+
     if (config.getMcastPort() > 0) {
-      this.mcastId = new DistributionLocatorId(config.getMcastAddress(), 
-                                               config.getMcastPort(), 
-                                               config.getBindAddress(),
-                                               this.sslConfig);
+      this.mcastId = new DistributionLocatorId(config.getMcastAddress(), config.getMcastPort(),
config.getBindAddress(), this.sslConfig);
       this.mcastEnabled = true;
-    }
-    else {
+    } else {
       this.mcastEnabled = false;
       this.mcastId = null;
     }
-    
+
     this.tcpDisabled = config.getDisableTcp();
     this.disableAutoReconnect = config.getDisableAutoReconnect();
 
@@ -95,24 +95,16 @@ public class RemoteTransportConfig implements TransportConfig {
       // loner system
       this.ids = Collections.EMPTY_SET;
       return;
-    }
-    else {
+    } else {
       HashSet locators = new HashSet();
-      int startIdx = 0;
-      int endIdx = -1;
-      do {
-        String locator;
-        endIdx = initialHosts.indexOf(',', startIdx);
-        if (endIdx == -1) {
-          locator = initialHosts.substring(startIdx);
-        } else {
-          locator = initialHosts.substring(startIdx, endIdx);
-          startIdx = endIdx+1;
+      StringTokenizer stringTokenizer = new StringTokenizer(initialHosts, ",");
+      while (stringTokenizer.hasMoreTokens()) {
+        String locator = stringTokenizer.nextToken();
+        if (!StringUtils.isEmpty(locator)) {
+          locators.add(new DistributionLocatorId(locator));
         }
-        locators.add(new DistributionLocatorId(locator));
+      }
 
-      } while (endIdx != -1);
-    
       if (this.mcastEnabled) {
         locators.add(this.mcastId);
       }
@@ -127,25 +119,25 @@ public class RemoteTransportConfig implements TransportConfig {
    * Constructs a transport config given a collection of {@link
    * DistributionLocatorId} instances.
    */
-  public RemoteTransportConfig(
-    boolean isMcastEnabled,
-    boolean isTcpDisabled,
-    boolean isAutoReconnectDisabled,
-    String bindAddress, 
-    SSLConfig sslConfig,
-    Collection ids, String membershipPortRange,
-    int tcpPort, int vmKind)
-  {
+  public RemoteTransportConfig(boolean isMcastEnabled,
+                               boolean isTcpDisabled,
+                               boolean isAutoReconnectDisabled,
+                               String bindAddress,
+                               SSLConfig sslConfig,
+                               Collection ids,
+                               String membershipPortRange,
+                               int tcpPort,
+                               int vmKind) {
     DistributionLocatorId mid = null;
-    
+
     if (bindAddress == null) {
       this.bindAddress = DistributionConfig.DEFAULT_BIND_ADDRESS;
     } else {
       this.bindAddress = bindAddress;
     }
-    
+
     this.sslConfig = sslConfig;
-    
+
     this.mcastEnabled = isMcastEnabled;
     this.tcpDisabled = isTcpDisabled;
     this.disableAutoReconnect = isAutoReconnectDisabled;
@@ -155,12 +147,11 @@ public class RemoteTransportConfig implements TransportConfig {
       }
       Iterator it = ids.iterator();
       while (it.hasNext() && mid == null) {
-        DistributionLocatorId id = (DistributionLocatorId)it.next();
+        DistributionLocatorId id = (DistributionLocatorId) it.next();
         if (id.isMcastId()) {
           mid = id;
           //System.out.println("mcast id: " + id);
-        }
-        else {
+        } else {
           //System.out.println("non-mcast id: " + id);
         }
       }
@@ -173,24 +164,22 @@ public class RemoteTransportConfig implements TransportConfig {
     this.membershipPortRange = membershipPortRange;
     this.tcpPort = tcpPort;
     this.vmKind = vmKind;
- }
-  
-  
+  }
+
+
   private static String getMembershipPortRangeString(int[] membershipPortRange) {
     String membershipPortRangeString = "";
-    if (membershipPortRange != null && 
-        membershipPortRange.length == 2) {
-      membershipPortRangeString = membershipPortRange[0] + "-" + 
-                                  membershipPortRange[1];
+    if (membershipPortRange != null && membershipPortRange.length == 2) {
+      membershipPortRangeString = membershipPortRange[0] + "-" + membershipPortRange[1];
     }
-    
+
     return membershipPortRangeString;
   }
 
   // -------------------------------------------------------------------------
   //   Attribute(s)
   // -------------------------------------------------------------------------
-  
+
   /**
    * Returns the set of DistributionLocatorId instances that define this
    * transport. The set is unmodifiable.
@@ -198,7 +187,7 @@ public class RemoteTransportConfig implements TransportConfig {
   public Set getIds() {
     return this.ids;
   }
-  
+
   /**
    * Returns true iff multicast is enabled in this transport.
    * Multicast must be enabled in order to use multicast discovery.
@@ -206,35 +195,35 @@ public class RemoteTransportConfig implements TransportConfig {
   public boolean isMcastEnabled() {
     return this.mcastEnabled;
   }
-  
+
   public DistributionLocatorId getMcastId() {
     return this.mcastId;
   }
-  
+
   public int getVmKind() {
     return this.vmKind;
   }
-  
+
   public boolean isTcpDisabled() {
     return this.tcpDisabled;
   }
 
   public String getBindAddress() {
-	  return this.bindAddress;
+    return this.bindAddress;
   }
-  
+
   public SSLConfig getSSLConfig() {
-	  return this.sslConfig;
+    return this.sslConfig;
   }
-  
+
   public String getMembershipPortRange() {
     return this.membershipPortRange;
   }
-  
+
   public int getTcpPort() {
     return this.tcpPort;
   }
-  
+
   public boolean getIsReconnectingDS() {
     return isReconnectingDS;
   }
@@ -255,14 +244,12 @@ public class RemoteTransportConfig implements TransportConfig {
    * Returns a <code>Properties</code> based on this config that is
    * appropriate to use with {@link
    * com.gemstone.gemfire.distributed.DistributedSystem#connect}.
-   *
    * @since GemFire 4.0
    */
   Properties toDSProperties() {
     Properties props = new Properties();
-    props.setProperty(BIND_ADDRESS,
-                      bindAddress);
-//    System.out.println("entering ds port range property of " + this.membershipPortRange);
+    props.setProperty(BIND_ADDRESS, bindAddress);
+    //    System.out.println("entering ds port range property of " + this.membershipPortRange);
     if (this.membershipPortRange != null) {
       props.setProperty(MEMBERSHIP_PORT_RANGE, this.membershipPortRange);
     }
@@ -270,28 +257,22 @@ public class RemoteTransportConfig implements TransportConfig {
       props.setProperty(TCP_PORT, String.valueOf(this.tcpPort));
     }
     if (this.mcastEnabled) {
-       // Fix bug 32849
-      props.setProperty(MCAST_ADDRESS,
-                         String.valueOf(this.mcastId.getHost().getHostAddress()));
-      props.setProperty(MCAST_PORT,
-                        String.valueOf(this.mcastId.getPort()));
+      // Fix bug 32849
+      props.setProperty(MCAST_ADDRESS, String.valueOf(this.mcastId.getHost().getHostAddress()));
+      props.setProperty(MCAST_PORT, String.valueOf(this.mcastId.getPort()));
 
-    }
-    else {
-      props.setProperty(MCAST_PORT,
-                        String.valueOf(0));
+    } else {
+      props.setProperty(MCAST_PORT, String.valueOf(0));
     }
     // Create locator string
     StringBuffer locators = new StringBuffer();
     for (Iterator iter = this.ids.iterator(); iter.hasNext(); ) {
-      DistributionLocatorId locator =
-          (DistributionLocatorId) iter.next();
+      DistributionLocatorId locator = (DistributionLocatorId) iter.next();
       if (!locator.isMcastId()) {
         String baddr = locator.getBindAddress();
         if (baddr != null && baddr.trim().length() > 0) {
           locators.append(baddr);
-        }
-        else {
+        } else {
           locators.append(locator.getHost().getCanonicalHostName());
         }
         locators.append("[");
@@ -303,16 +284,18 @@ public class RemoteTransportConfig implements TransportConfig {
         }
       }
     }
+    String tempLocatorString = locators.toString();
+    if (tempLocatorString.endsWith(",")) {
+      tempLocatorString = tempLocatorString.substring(0, tempLocatorString.length() - 1);
+    }
 
-    props.setProperty(LOCATORS,
-        locators.toString());
+    props.setProperty(LOCATORS, tempLocatorString);
 
     this.sslConfig.toDSProperties(props);
-    
-    props.setProperty(DISABLE_TCP,
-      this.tcpDisabled? "true" : "false");
-    
-    props.setProperty(DISABLE_AUTO_RECONNECT, this.disableAutoReconnect? "true" : "false");
+
+    props.setProperty(DISABLE_TCP, this.tcpDisabled ? "true" : "false");
+
+    props.setProperty(DISABLE_AUTO_RECONNECT, this.disableAutoReconnect ? "true" : "false");
 
     return props;
   }
@@ -322,7 +305,7 @@ public class RemoteTransportConfig implements TransportConfig {
     boolean first = true;
     Iterator it = ids.iterator();
     while (it.hasNext()) {
-      DistributionLocatorId dli = (DistributionLocatorId)it.next();
+      DistributionLocatorId dli = (DistributionLocatorId) it.next();
       if (noMcast && dli.isMcastId()) {
         continue;
       }
@@ -335,17 +318,19 @@ public class RemoteTransportConfig implements TransportConfig {
     }
     return result.toString();
   }
-  
-  /** returns a locators string suitable for use in locators= in gemfire.properties */
+
+  /**
+   * returns a locators string suitable for use in locators= in gemfire.properties
+   */
   public String locatorsString() {
     return this.toString(true);
   }
-  
 
- // -------------------------------------------------------------------------
+
+  // -------------------------------------------------------------------------
   //   Methods overridden from java.lang.Object
   // -------------------------------------------------------------------------
-  
+
   @Override
   public String toString() {
     return toString(false);
@@ -354,16 +339,15 @@ public class RemoteTransportConfig implements TransportConfig {
   @Override
   public boolean equals(Object o) {
     if (o != null && o instanceof RemoteTransportConfig) {
-      RemoteTransportConfig other = (RemoteTransportConfig)o;
-      return (this.mcastEnabled == other.mcastEnabled)
-        && this.ids.equals(other.ids);
+      RemoteTransportConfig other = (RemoteTransportConfig) o;
+      return (this.mcastEnabled == other.mcastEnabled) && this.ids.equals(other.ids);
     }
     return false;
   }
-  
+
   @Override
   public int hashCode() {
     return this.ids.hashCode();
   }
-  
+
 }


Mime
View raw message