Replace DomainMappingBuilder with DomainNameMappingBuilder

Motivation:

DomainMappingBuilder should have been named as DomainNameMappingBuilder
because it builds a DomainNameMapping.

Modifications:

- Add DomainNameMappingBuilder that does the same job with
  DomainMappingBuilder
- Deprecate DomainMappingBuilder and delegate its logic to
  DomainNameMappingBuilder
- Remove the references to the deprecated methods and classes related
  with domain name mapping
- Miscellaneous:
  - Fix Javadoc of DomainNameMapping.asMap()
  - Pre-create the unmodifiable map in DomainNameMapping

Result:

- Consistent naming
- Less use of deprecated API
This commit is contained in:
Trustin Lee 2016-05-18 18:30:20 +09:00 committed by Norman Maurer
parent 8805971eec
commit 6a7ee52cd4
5 changed files with 247 additions and 173 deletions

View File

@ -16,22 +16,16 @@
package io.netty.util; package io.netty.util;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
/** /**
* Builder for immutable {@link DomainNameMapping} instances. * Builder for immutable {@link DomainNameMapping} instances.
* *
* @param <V> concrete type of value objects * @param <V> concrete type of value objects
* @deprecated Use {@link DomainNameMappingBuilder} instead.
*/ */
@Deprecated
public final class DomainMappingBuilder<V> { public final class DomainMappingBuilder<V> {
private final V defaultValue; private final DomainNameMappingBuilder<V> builder;
private final Map<String, V> map;
/** /**
* Constructor with default initial capacity of the map holding the mappings * Constructor with default initial capacity of the map holding the mappings
@ -40,7 +34,7 @@ public final class DomainMappingBuilder<V> {
* when nothing matches the input * when nothing matches the input
*/ */
public DomainMappingBuilder(V defaultValue) { public DomainMappingBuilder(V defaultValue) {
this(4, defaultValue); builder = new DomainNameMappingBuilder<V>(defaultValue);
} }
/** /**
@ -51,8 +45,7 @@ public final class DomainMappingBuilder<V> {
* when nothing matches the input * when nothing matches the input
*/ */
public DomainMappingBuilder(int initialCapacity, V defaultValue) { public DomainMappingBuilder(int initialCapacity, V defaultValue) {
this.defaultValue = checkNotNull(defaultValue, "defaultValue"); builder = new DomainNameMappingBuilder<V>(initialCapacity, defaultValue);
map = new LinkedHashMap<String, V>(initialCapacity);
} }
/** /**
@ -68,7 +61,7 @@ public final class DomainMappingBuilder<V> {
* when the specified host name matches the specified input host name * when the specified host name matches the specified input host name
*/ */
public DomainMappingBuilder<V> add(String hostname, V output) { public DomainMappingBuilder<V> add(String hostname, V output) {
map.put(checkNotNull(hostname, "hostname"), checkNotNull(output, "output")); builder.add(hostname, output);
return this; return this;
} }
@ -79,126 +72,6 @@ public final class DomainMappingBuilder<V> {
* @return new {@link DomainNameMapping} instance * @return new {@link DomainNameMapping} instance
*/ */
public DomainNameMapping<V> build() { public DomainNameMapping<V> build() {
return new ImmutableDomainNameMapping<V>(defaultValue, map); return builder.build();
}
/**
* Immutable mapping from domain name pattern to its associated value object.
* Mapping is represented by two arrays: keys and values. Key domainNamePatterns[i] is associated with values[i].
*
* @param <V> concrete type of value objects
*/
private static final class ImmutableDomainNameMapping<V> extends DomainNameMapping<V> {
private static final String REPR_HEADER = "ImmutableDomainNameMapping(default: ";
private static final String REPR_MAP_OPENING = ", map: {";
private static final String REPR_MAP_CLOSING = "})";
private static final int REPR_CONST_PART_LENGTH =
REPR_HEADER.length() + REPR_MAP_OPENING.length() + REPR_MAP_CLOSING.length();
private final String[] domainNamePatterns;
private final V[] values;
private final Map<String, V> map;
@SuppressWarnings("unchecked")
private ImmutableDomainNameMapping(V defaultValue, Map<String, V> map) {
super(null, defaultValue);
Set<Map.Entry<String, V>> mappings = map.entrySet();
int numberOfMappings = mappings.size();
domainNamePatterns = new String[numberOfMappings];
values = (V[]) new Object[numberOfMappings];
final Map<String, V> mapCopy = new LinkedHashMap<String, V>(map.size());
int index = 0;
for (Map.Entry<String, V> mapping : mappings) {
final String hostname = normalizeHostname(mapping.getKey());
final V value = mapping.getValue();
domainNamePatterns[index] = hostname;
values[index] = value;
mapCopy.put(hostname, value);
++index;
}
this.map = Collections.unmodifiableMap(mapCopy);
}
@Override
@Deprecated
public DomainNameMapping<V> add(String hostname, V output) {
throw new UnsupportedOperationException(
"Immutable DomainNameMapping does not support modification after initial creation");
}
@Override
public V map(String hostname) {
if (hostname != null) {
hostname = normalizeHostname(hostname);
int length = domainNamePatterns.length;
for (int index = 0; index < length; ++index) {
if (matches(domainNamePatterns[index], hostname)) {
return values[index];
}
}
}
return defaultValue;
}
@Override
public Map<String, V> asMap() {
return map;
}
@Override
public String toString() {
String defaultValueStr = defaultValue.toString();
int numberOfMappings = domainNamePatterns.length;
if (numberOfMappings == 0) {
return REPR_HEADER + defaultValueStr + REPR_MAP_OPENING + REPR_MAP_CLOSING;
}
String pattern0 = domainNamePatterns[0];
String value0 = values[0].toString();
int oneMappingLength = pattern0.length() + value0.length() + 3; // 2 for separator ", " and 1 for '='
int estimatedBufferSize = estimateBufferSize(defaultValueStr.length(), numberOfMappings, oneMappingLength);
StringBuilder sb = new StringBuilder(estimatedBufferSize)
.append(REPR_HEADER).append(defaultValueStr).append(REPR_MAP_OPENING);
appendMapping(sb, pattern0, value0);
for (int index = 1; index < numberOfMappings; ++index) {
sb.append(", ");
appendMapping(sb, index);
}
return sb.append(REPR_MAP_CLOSING).toString();
}
/**
* Estimates the length of string representation of the given instance:
* est = lengthOfConstantComponents + defaultValueLength + (estimatedMappingLength * numOfMappings) * 1.10
*
* @param defaultValueLength length of string representation of {@link #defaultValue}
* @param numberOfMappings number of mappings the given instance holds,
* e.g. {@link #domainNamePatterns#length}
* @param estimatedMappingLength estimated size taken by one mapping
* @return estimated length of string returned by {@link #toString()}
*/
private static int estimateBufferSize(int defaultValueLength,
int numberOfMappings,
int estimatedMappingLength) {
return REPR_CONST_PART_LENGTH + defaultValueLength
+ (int) (estimatedMappingLength * numberOfMappings * 1.10);
}
private StringBuilder appendMapping(StringBuilder sb, int mappingIndex) {
return appendMapping(sb, domainNamePatterns[mappingIndex], values[mappingIndex].toString());
}
private static StringBuilder appendMapping(StringBuilder sb, String domainNamePattern, String value) {
return sb.append(domainNamePattern).append('=').append(value);
}
} }
} }

View File

@ -23,7 +23,6 @@ import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static io.netty.util.internal.StringUtil.commonSuffixOfLength; import static io.netty.util.internal.StringUtil.commonSuffixOfLength;
@ -39,13 +38,14 @@ public class DomainNameMapping<V> implements Mapping<String, V> {
final V defaultValue; final V defaultValue;
private final Map<String, V> map; private final Map<String, V> map;
private final Map<String, V> unmodifiableMap;
/** /**
* Creates a default, order-sensitive mapping. If your hostnames are in conflict, the mapping * Creates a default, order-sensitive mapping. If your hostnames are in conflict, the mapping
* will choose the one you add first. * will choose the one you add first.
* *
* @param defaultValue the default value for {@link #map(String)} to return when nothing matches the input * @param defaultValue the default value for {@link #map(String)} to return when nothing matches the input
* @deprecated use {@link DomainMappingBuilder} to create and fill the mapping instead * @deprecated use {@link DomainNameMappingBuilder} to create and fill the mapping instead
*/ */
@Deprecated @Deprecated
public DomainNameMapping(V defaultValue) { public DomainNameMapping(V defaultValue) {
@ -58,7 +58,7 @@ public class DomainNameMapping<V> implements Mapping<String, V> {
* *
* @param initialCapacity initial capacity for the internal map * @param initialCapacity initial capacity for the internal map
* @param defaultValue the default value for {@link #map(String)} to return when nothing matches the input * @param defaultValue the default value for {@link #map(String)} to return when nothing matches the input
* @deprecated use {@link DomainMappingBuilder} to create and fill the mapping instead * @deprecated use {@link DomainNameMappingBuilder} to create and fill the mapping instead
*/ */
@Deprecated @Deprecated
public DomainNameMapping(int initialCapacity, V defaultValue) { public DomainNameMapping(int initialCapacity, V defaultValue) {
@ -68,6 +68,7 @@ public class DomainNameMapping<V> implements Mapping<String, V> {
DomainNameMapping(Map<String, V> map, V defaultValue) { DomainNameMapping(Map<String, V> map, V defaultValue) {
this.defaultValue = checkNotNull(defaultValue, "defaultValue"); this.defaultValue = checkNotNull(defaultValue, "defaultValue");
this.map = map; this.map = map;
unmodifiableMap = Collections.unmodifiableMap(map);
} }
/** /**
@ -80,7 +81,7 @@ public class DomainNameMapping<V> implements Mapping<String, V> {
* @param hostname the host name (optionally wildcard) * @param hostname the host name (optionally wildcard)
* @param output the output value that will be returned by {@link #map(String)} when the specified host name * @param output the output value that will be returned by {@link #map(String)} when the specified host name
* matches the specified input host name * matches the specified input host name
* @deprecated use {@link DomainMappingBuilder} to create and fill the mapping instead * @deprecated use {@link DomainNameMappingBuilder} to create and fill the mapping instead
*/ */
@Deprecated @Deprecated
public DomainNameMapping<V> add(String hostname, V output) { public DomainNameMapping<V> add(String hostname, V output) {
@ -135,10 +136,10 @@ public class DomainNameMapping<V> implements Mapping<String, V> {
} }
/** /**
* Returns a read-only {@link Set} of the domain mapping patterns and their associated value objects. * Returns a read-only {@link Map} of the domain mapping patterns and their associated value objects.
*/ */
public Map<String, V> asMap() { public Map<String, V> asMap() {
return Collections.unmodifiableMap(map); return unmodifiableMap;
} }
@Override @Override

View File

@ -0,0 +1,204 @@
/*
* Copyright 2016 The Netty Project
*
* The Netty Project 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 io.netty.util;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
/**
* Builder for immutable {@link DomainNameMapping} instances.
*
* @param <V> concrete type of value objects
*/
public final class DomainNameMappingBuilder<V> {
private final V defaultValue;
private final Map<String, V> map;
/**
* Constructor with default initial capacity of the map holding the mappings
*
* @param defaultValue the default value for {@link DomainNameMapping#map(String)} to return
* when nothing matches the input
*/
public DomainNameMappingBuilder(V defaultValue) {
this(4, defaultValue);
}
/**
* Constructor with initial capacity of the map holding the mappings
*
* @param initialCapacity initial capacity for the internal map
* @param defaultValue the default value for {@link DomainNameMapping#map(String)} to return
* when nothing matches the input
*/
public DomainNameMappingBuilder(int initialCapacity, V defaultValue) {
this.defaultValue = checkNotNull(defaultValue, "defaultValue");
map = new LinkedHashMap<String, V>(initialCapacity);
}
/**
* Adds a mapping that maps the specified (optionally wildcard) host name to the specified output value.
* Null values are forbidden for both hostnames and values.
* <p>
* <a href="http://en.wikipedia.org/wiki/Wildcard_DNS_record">DNS wildcard</a> is supported as hostname.
* For example, you can use {@code *.netty.io} to match {@code netty.io} and {@code downloads.netty.io}.
* </p>
*
* @param hostname the host name (optionally wildcard)
* @param output the output value that will be returned by {@link DomainNameMapping#map(String)}
* when the specified host name matches the specified input host name
*/
public DomainNameMappingBuilder<V> add(String hostname, V output) {
map.put(checkNotNull(hostname, "hostname"), checkNotNull(output, "output"));
return this;
}
/**
* Creates a new instance of immutable {@link DomainNameMapping}
* Attempts to add new mappings to the result object will cause {@link UnsupportedOperationException} to be thrown
*
* @return new {@link DomainNameMapping} instance
*/
public DomainNameMapping<V> build() {
return new ImmutableDomainNameMapping<V>(defaultValue, map);
}
/**
* Immutable mapping from domain name pattern to its associated value object.
* Mapping is represented by two arrays: keys and values. Key domainNamePatterns[i] is associated with values[i].
*
* @param <V> concrete type of value objects
*/
private static final class ImmutableDomainNameMapping<V> extends DomainNameMapping<V> {
private static final String REPR_HEADER = "ImmutableDomainNameMapping(default: ";
private static final String REPR_MAP_OPENING = ", map: {";
private static final String REPR_MAP_CLOSING = "})";
private static final int REPR_CONST_PART_LENGTH =
REPR_HEADER.length() + REPR_MAP_OPENING.length() + REPR_MAP_CLOSING.length();
private final String[] domainNamePatterns;
private final V[] values;
private final Map<String, V> map;
@SuppressWarnings("unchecked")
private ImmutableDomainNameMapping(V defaultValue, Map<String, V> map) {
super(null, defaultValue);
Set<Map.Entry<String, V>> mappings = map.entrySet();
int numberOfMappings = mappings.size();
domainNamePatterns = new String[numberOfMappings];
values = (V[]) new Object[numberOfMappings];
final Map<String, V> mapCopy = new LinkedHashMap<String, V>(map.size());
int index = 0;
for (Map.Entry<String, V> mapping : mappings) {
final String hostname = normalizeHostname(mapping.getKey());
final V value = mapping.getValue();
domainNamePatterns[index] = hostname;
values[index] = value;
mapCopy.put(hostname, value);
++index;
}
this.map = Collections.unmodifiableMap(mapCopy);
}
@Override
@Deprecated
public DomainNameMapping<V> add(String hostname, V output) {
throw new UnsupportedOperationException(
"Immutable DomainNameMapping does not support modification after initial creation");
}
@Override
public V map(String hostname) {
if (hostname != null) {
hostname = normalizeHostname(hostname);
int length = domainNamePatterns.length;
for (int index = 0; index < length; ++index) {
if (matches(domainNamePatterns[index], hostname)) {
return values[index];
}
}
}
return defaultValue;
}
@Override
public Map<String, V> asMap() {
return map;
}
@Override
public String toString() {
String defaultValueStr = defaultValue.toString();
int numberOfMappings = domainNamePatterns.length;
if (numberOfMappings == 0) {
return REPR_HEADER + defaultValueStr + REPR_MAP_OPENING + REPR_MAP_CLOSING;
}
String pattern0 = domainNamePatterns[0];
String value0 = values[0].toString();
int oneMappingLength = pattern0.length() + value0.length() + 3; // 2 for separator ", " and 1 for '='
int estimatedBufferSize = estimateBufferSize(defaultValueStr.length(), numberOfMappings, oneMappingLength);
StringBuilder sb = new StringBuilder(estimatedBufferSize)
.append(REPR_HEADER).append(defaultValueStr).append(REPR_MAP_OPENING);
appendMapping(sb, pattern0, value0);
for (int index = 1; index < numberOfMappings; ++index) {
sb.append(", ");
appendMapping(sb, index);
}
return sb.append(REPR_MAP_CLOSING).toString();
}
/**
* Estimates the length of string representation of the given instance:
* est = lengthOfConstantComponents + defaultValueLength + (estimatedMappingLength * numOfMappings) * 1.10
*
* @param defaultValueLength length of string representation of {@link #defaultValue}
* @param numberOfMappings number of mappings the given instance holds,
* e.g. {@link #domainNamePatterns#length}
* @param estimatedMappingLength estimated size taken by one mapping
* @return estimated length of string returned by {@link #toString()}
*/
private static int estimateBufferSize(int defaultValueLength,
int numberOfMappings,
int estimatedMappingLength) {
return REPR_CONST_PART_LENGTH + defaultValueLength
+ (int) (estimatedMappingLength * numberOfMappings * 1.10);
}
private StringBuilder appendMapping(StringBuilder sb, int mappingIndex) {
return appendMapping(sb, domainNamePatterns[mappingIndex], values[mappingIndex].toString());
}
private static StringBuilder appendMapping(StringBuilder sb, String domainNamePattern, String value) {
return sb.append(domainNamePattern).append('=').append(value);
}
}
}

View File

@ -107,22 +107,22 @@ public class DomainNameMappingTest {
@Test(expected = NullPointerException.class) @Test(expected = NullPointerException.class)
public void testNullDefaultValue() { public void testNullDefaultValue() {
new DomainMappingBuilder<String>(null); new DomainNameMappingBuilder<String>(null);
} }
@Test(expected = NullPointerException.class) @Test(expected = NullPointerException.class)
public void testNullDomainNamePatternsAreForbidden() { public void testNullDomainNamePatternsAreForbidden() {
new DomainMappingBuilder<String>("NotFound").add(null, "Some value"); new DomainNameMappingBuilder<String>("NotFound").add(null, "Some value");
} }
@Test(expected = NullPointerException.class) @Test(expected = NullPointerException.class)
public void testNullValuesAreForbidden() { public void testNullValuesAreForbidden() {
new DomainMappingBuilder<String>("NotFound").add("Some key", null); new DomainNameMappingBuilder<String>("NotFound").add("Some key", null);
} }
@Test @Test
public void testDefaultValue() { public void testDefaultValue() {
DomainNameMapping<String> mapping = new DomainMappingBuilder<String>("NotFound") DomainNameMapping<String> mapping = new DomainNameMappingBuilder<String>("NotFound")
.add("*.netty.io", "Netty") .add("*.netty.io", "Netty")
.build(); .build();
@ -131,7 +131,7 @@ public class DomainNameMappingTest {
@Test @Test
public void testStrictEquality() { public void testStrictEquality() {
DomainNameMapping<String> mapping = new DomainMappingBuilder<String>("NotFound") DomainNameMapping<String> mapping = new DomainNameMappingBuilder<String>("NotFound")
.add("netty.io", "Netty") .add("netty.io", "Netty")
.add("downloads.netty.io", "Netty-Downloads") .add("downloads.netty.io", "Netty-Downloads")
.build(); .build();
@ -144,7 +144,7 @@ public class DomainNameMappingTest {
@Test @Test
public void testWildcardMatchesAnyPrefix() { public void testWildcardMatchesAnyPrefix() {
DomainNameMapping<String> mapping = new DomainMappingBuilder<String>("NotFound") DomainNameMapping<String> mapping = new DomainNameMappingBuilder<String>("NotFound")
.add("*.netty.io", "Netty") .add("*.netty.io", "Netty")
.build(); .build();
@ -158,14 +158,14 @@ public class DomainNameMappingTest {
@Test @Test
public void testFirstMatchWins() { public void testFirstMatchWins() {
assertEquals("Netty", assertEquals("Netty",
new DomainMappingBuilder<String>("NotFound") new DomainNameMappingBuilder<String>("NotFound")
.add("*.netty.io", "Netty") .add("*.netty.io", "Netty")
.add("downloads.netty.io", "Netty-Downloads") .add("downloads.netty.io", "Netty-Downloads")
.build() .build()
.map("downloads.netty.io")); .map("downloads.netty.io"));
assertEquals("Netty-Downloads", assertEquals("Netty-Downloads",
new DomainMappingBuilder<String>("NotFound") new DomainNameMappingBuilder<String>("NotFound")
.add("downloads.netty.io", "Netty-Downloads") .add("downloads.netty.io", "Netty-Downloads")
.add("*.netty.io", "Netty") .add("*.netty.io", "Netty")
.build() .build()
@ -174,7 +174,7 @@ public class DomainNameMappingTest {
@Test @Test
public void testToString() { public void testToString() {
DomainNameMapping<String> mapping = new DomainMappingBuilder<String>("NotFound") DomainNameMapping<String> mapping = new DomainNameMappingBuilder<String>("NotFound")
.add("*.netty.io", "Netty") .add("*.netty.io", "Netty")
.add("downloads.netty.io", "Netty-Download") .add("downloads.netty.io", "Netty-Download")
.build(); .build();
@ -199,7 +199,7 @@ public class DomainNameMappingTest {
@Test @Test
public void testAsMapWithImmutableDomainNameMapping() { public void testAsMapWithImmutableDomainNameMapping() {
DomainNameMapping<String> mapping = new DomainMappingBuilder<String>("NotFound") DomainNameMapping<String> mapping = new DomainNameMappingBuilder<String>("NotFound")
.add("netty.io", "Netty") .add("netty.io", "Netty")
.add("downloads.netty.io", "Netty-Downloads") .add("downloads.netty.io", "Netty-Downloads")
.build(); .build();

View File

@ -18,7 +18,6 @@ package io.netty.handler.ssl;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
@ -31,18 +30,17 @@ import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.DecoderException;
import io.netty.util.DomainMappingBuilder;
import io.netty.util.DomainNameMapping; import io.netty.util.DomainNameMapping;
import io.netty.util.DomainNameMappingBuilder;
import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCountUtil;
import org.junit.Test; import org.junit.Test;
import javax.xml.bind.DatatypeConverter;
import java.io.File; import java.io.File;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.xml.bind.DatatypeConverter;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
@ -80,15 +78,14 @@ public class SniHandlerTest {
SslContext leanContext = makeSslContext(); SslContext leanContext = makeSslContext();
SslContext leanContext2 = makeSslContext(); SslContext leanContext2 = makeSslContext();
DomainNameMapping<SslContext> mapping = new DomainNameMapping<SslContext>(nettyContext); DomainNameMapping<SslContext> mapping = new DomainNameMappingBuilder<SslContext>(nettyContext)
mapping.add("*.netty.io", nettyContext); .add("*.netty.io", nettyContext)
// input with custom cases
// input with custom cases .add("*.LEANCLOUD.CN", leanContext)
mapping.add("*.LEANCLOUD.CN", leanContext); // a hostname conflict with previous one, since we are using order-sensitive config, the engine won't
// be used with the handler.
// a hostname conflict with previous one, since we are using order-sensitive config, the engine won't .add("chat4.leancloud.cn", leanContext2)
// be used with the handler. .build();
mapping.add("chat4.leancloud.cn", leanContext2);
SniHandler handler = new SniHandler(mapping); SniHandler handler = new SniHandler(mapping);
EmbeddedChannel ch = new EmbeddedChannel(handler); EmbeddedChannel ch = new EmbeddedChannel(handler);
@ -132,15 +129,14 @@ public class SniHandlerTest {
SslContext leanContext = makeSslContext(); SslContext leanContext = makeSslContext();
SslContext leanContext2 = makeSslContext(); SslContext leanContext2 = makeSslContext();
DomainNameMapping<SslContext> mapping = new DomainNameMapping<SslContext>(nettyContext); DomainNameMapping<SslContext> mapping = new DomainNameMappingBuilder<SslContext>(nettyContext)
mapping.add("*.netty.io", nettyContext); .add("*.netty.io", nettyContext)
// input with custom cases
// input with custom cases .add("*.LEANCLOUD.CN", leanContext)
mapping.add("*.LEANCLOUD.CN", leanContext); // a hostname conflict with previous one, since we are using order-sensitive config, the engine won't
// be used with the handler.
// a hostname conflict with previous one, since we are using order-sensitive config, the engine won't .add("chat4.leancloud.cn", leanContext2)
// be used with the handler. .build();
mapping.add("chat4.leancloud.cn", leanContext2);
SniHandler handler = new SniHandler(mapping); SniHandler handler = new SniHandler(mapping);
EmbeddedChannel ch = new EmbeddedChannel(handler); EmbeddedChannel ch = new EmbeddedChannel(handler);
@ -168,7 +164,7 @@ public class SniHandlerTest {
final CountDownLatch serverApnDoneLatch = new CountDownLatch(1); final CountDownLatch serverApnDoneLatch = new CountDownLatch(1);
final CountDownLatch clientApnDoneLatch = new CountDownLatch(1); final CountDownLatch clientApnDoneLatch = new CountDownLatch(1);
final DomainNameMapping<SslContext> mapping = new DomainMappingBuilder(nettyContext) final DomainNameMapping<SslContext> mapping = new DomainNameMappingBuilder<SslContext>(nettyContext)
.add("*.netty.io", nettyContext) .add("*.netty.io", nettyContext)
.add("sni.fake.site", sniContext).build(); .add("sni.fake.site", sniContext).build();
final SniHandler handler = new SniHandler(mapping); final SniHandler handler = new SniHandler(mapping);