Github user aweisberg commented on a diff in the pull request:
https://github.com/apache/cassandra/pull/184#discussion_r163074165
--- Diff: src/java/org/apache/cassandra/locator/InetAddressAndPort.java ---
@@ -0,0 +1,193 @@
+/*
+ * 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.cassandra.locator;
+
+import java.io.Serializable;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+import java.util.regex.Pattern;
+
+import com.google.common.base.Preconditions;
+import com.google.common.net.HostAndPort;
+
+import org.apache.cassandra.config.Config;
+
+/**
+ * A class to replace the usage of InetAddress to identify hosts in the
cluster.
+ * Opting for a full replacement class so that in the future if we change
the nature
+ * of the identifier the refactor will be easier in that we don't have to
change the type
+ * just the methods.
+ *
+ * Because an IP might contain multiple C* instances the identification
must be done
+ * using the IP + port. InetSocketAddress is undesirable for a couple of
reasons. It's not comparable,
+ * it's toString() method doesn't correctly bracket IPv6, it doesn't
handle optional default values,
+ * and a couple of other minor behaviors that are slightly less
troublesome like handling the
+ * need to sometimes return a port and sometimes not.
+ *
+ */
+public final class InetAddressAndPort implements
Comparable<InetAddressAndPort>, Serializable
+{
+ private static final long serialVersionUID = 0;
+
+ //Store these here to avoid requiring DatabaseDescriptor to be loaded.
DatabaseDescriptor will set
+ //these when it loads the config. A lot of unit tests won't end up
loading DatabaseDescriptor.
+ //Tools that might use this class also might not load database
descriptor. Those tools are expected
+ //to always override the defaults.
+ static volatile int defaultPort = 7000;
+
+ public final InetAddress address;
+ public final int port;
+
+ private InetAddressAndPort(InetAddress address, int port)
+ {
+ Preconditions.checkNotNull(address);
+ validatePortRange(port);
+ this.address = address;
+ this.port = port;
+ }
+
+ private static void validatePortRange(int port)
+ {
+ if (port < 0 | port > 65535)
+ {
+ throw new IllegalArgumentException("Port " + port + " is not a
valid port number in the range 0-65535");
+ }
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ InetAddressAndPort that = (InetAddressAndPort) o;
+
+ if (port != that.port) return false;
+ return address.equals(that.address);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = address.hashCode();
+ result = 31 * result + port;
+ return result;
+ }
+
+ @Override
+ public int compareTo(InetAddressAndPort o)
+ {
+ int retval =
ByteBuffer.wrap(address.getAddress()).compareTo(ByteBuffer.wrap(o.address.getAddress()));
--- End diff --
Get HostAddress is the same thing.
I think InetAddress implementations for whatever reason choose to trade
footprint for allocations.
For us it's fine to just store the allocation. We don't plan on storing a
ton of these I think.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]