Skip to content

Commit 49a2ebf

Browse files
author
alexsa
committed
Add License header, use splitterator and fill typed driver options
1 parent bce2289 commit 49a2ebf

File tree

5 files changed

+89
-5
lines changed

5 files changed

+89
-5
lines changed

core/src/main/java/com/datastax/oss/driver/api/core/config/TypedDriverOption.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,20 @@ public String toString() {
896896
DefaultDriverOption.LOAD_BALANCING_DC_FAILOVER_ALLOW_FOR_LOCAL_CONSISTENCY_LEVELS,
897897
GenericType.BOOLEAN);
898898

899+
public static final TypedDriverOption<String> ADDRESS_TRANSLATOR_ADVERTISED_HOSTNAME =
900+
new TypedDriverOption<>(
901+
DefaultDriverOption.ADDRESS_TRANSLATOR_ADVERTISED_HOSTNAME, GenericType.STRING);
902+
public static final TypedDriverOption<Map<String, String>> ADDRESS_TRANSLATOR_SUBNET_ADDRESSES =
903+
new TypedDriverOption<>(
904+
DefaultDriverOption.ADDRESS_TRANSLATOR_SUBNET_ADDRESSES,
905+
GenericType.mapOf(GenericType.STRING, GenericType.STRING));
906+
public static final TypedDriverOption<String> ADDRESS_TRANSLATOR_DEFAULT_ADDRESS =
907+
new TypedDriverOption<>(
908+
DefaultDriverOption.ADDRESS_TRANSLATOR_DEFAULT_ADDRESS, GenericType.STRING);
909+
public static final TypedDriverOption<Boolean> ADDRESS_TRANSLATOR_RESOLVE_ADDRESSES =
910+
new TypedDriverOption<>(
911+
DefaultDriverOption.ADDRESS_TRANSLATOR_RESOLVE_ADDRESSES, GenericType.BOOLEAN);
912+
899913
/**
900914
* Ordered preference list of remote dcs optionally supplied for automatic failover and included
901915
* in query plan. This feature is enabled only when max-nodes-per-remote-dc is greater than 0.

core/src/main/java/com/datastax/oss/driver/internal/core/addresstranslation/Subnet.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
118
package com.datastax.oss.driver.internal.core.addresstranslation;
219

320
import com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting;
21+
import com.google.common.base.Splitter;
422
import java.net.InetAddress;
523
import java.net.UnknownHostException;
624
import java.util.Arrays;
25+
import java.util.List;
726

827
class Subnet {
928
private final byte[] subnet;
@@ -26,17 +45,17 @@ private Subnet(byte[] subnet, byte[] networkMask) {
2645
}
2746

2847
static Subnet parse(String subnetCIDR) throws UnknownHostException {
29-
String[] parts = subnetCIDR.split("/");
30-
if (parts.length != 2) {
48+
List<String> parts = Splitter.on("/").splitToList("/");
49+
if (parts.size() != 2) {
3150
throw new IllegalArgumentException("Invalid subnet: " + subnetCIDR);
3251
}
3352

34-
boolean isIPv6 = parts[0].contains(":");
35-
byte[] subnet = InetAddress.getByName(parts[0]).getAddress();
53+
boolean isIPv6 = parts.get(0).contains(":");
54+
byte[] subnet = InetAddress.getByName(parts.get(0)).getAddress();
3655
if (isIPv4(subnet) && isIPv6) {
3756
subnet = toIPv6(subnet);
3857
}
39-
int prefixLength = Integer.parseInt(parts[1]);
58+
int prefixLength = Integer.parseInt(parts.get(1));
4059
validatePrefixLength(subnet, prefixLength);
4160

4261
byte[] networkMask = toNetworkMask(subnet, prefixLength);

core/src/main/java/com/datastax/oss/driver/internal/core/addresstranslation/SubnetAddress.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
118
package com.datastax.oss.driver.internal.core.addresstranslation;
219

320
import java.net.InetSocketAddress;

core/src/test/java/com/datastax/oss/driver/internal/core/addresstranslation/SubnetAddressTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
118
package com.datastax.oss.driver.internal.core.addresstranslation;
219

320
import static org.assertj.core.api.Assertions.assertThat;

core/src/test/java/com/datastax/oss/driver/internal/core/addresstranslation/SubnetTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
118
package com.datastax.oss.driver.internal.core.addresstranslation;
219

320
import static org.assertj.core.api.Assertions.assertThat;

0 commit comments

Comments
 (0)