zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] anmolnar commented on a change in pull request #730: Zookeeper-3188: Improve resilience to network
Date Wed, 27 Feb 2019 14:41:42 GMT
anmolnar commented on a change in pull request #730: Zookeeper-3188: Improve resilience to
network
URL: https://github.com/apache/zookeeper/pull/730#discussion_r260761623
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/MultipleAddresses.java
 ##########
 @@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.zookeeper.server.quorum;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.NoRouteToHostException;
+import java.net.UnknownHostException;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * This class allows to store several quorum and electing addresses.
+ *
+ * See ZOOKEEPER-3188 for a discussion of this feature.
+ */
+public class MultipleAddresses {
+
+    private Set<InetSocketAddress> addresses;
+    private int timeout;
+
+    public MultipleAddresses() {
+        addresses = Collections.newSetFromMap(new ConcurrentHashMap<>());
+        timeout = 100;
+    }
+
+    public MultipleAddresses(List<InetSocketAddress> addresses) {
+        this(addresses, 100);
+    }
+
+    public MultipleAddresses(InetSocketAddress address) {
+        this(address, 100);
+    }
+
+    public MultipleAddresses(List<InetSocketAddress> addresses, int timeout) {
+        this.addresses = Collections.newSetFromMap(new ConcurrentHashMap<>());
+        this.addresses.addAll(addresses);
+        this.timeout = timeout;
+    }
+
+    public MultipleAddresses(InetSocketAddress address,  int timeout) {
+        addresses = Collections.newSetFromMap(new ConcurrentHashMap<>());
+        addresses.add(address);
+        this.timeout = timeout;
+    }
+
+    public int getTimeout() {
+        return timeout;
+    }
+
+    public void setTimeout(int timeout) {
+        this.timeout = timeout;
+    }
+
+    public boolean isEmpty() {
+        return addresses.isEmpty();
+    }
+
+    /**
+     * Returns all addresses.
+     *
+     * @return list of all InetSocketAddress
+     */
+    public List<InetSocketAddress> getAllAddresses() {
+        return new LinkedList<>(addresses);
 
 Review comment:
   Use `unmodifiableSet()` instead?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message