Warn about not-supported ChannelOption when bootstrap Channels.
Motivation: We not warned about not-supported ChannelOptions when set the options for the ServerChannel. Modifications: - Share code for setting ChannelOptions during bootstrap Result: Warning is logged when a ChannelOption is used that is not supported during bootstrap a Channel. See also [#6192]
This commit is contained in:
parent
01d747ab83
commit
018c6ecd7a
@ -30,6 +30,7 @@ import io.netty.util.AttributeKey;
|
|||||||
import io.netty.util.concurrent.EventExecutor;
|
import io.netty.util.concurrent.EventExecutor;
|
||||||
import io.netty.util.concurrent.GlobalEventExecutor;
|
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -397,6 +398,33 @@ public abstract class AbstractBootstrap<B extends AbstractBootstrap<B, C>, C ext
|
|||||||
return attrs;
|
return attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setChannelOptions(
|
||||||
|
Channel channel, Map<ChannelOption<?>, Object> options, InternalLogger logger) {
|
||||||
|
for (Map.Entry<ChannelOption<?>, Object> e: options.entrySet()) {
|
||||||
|
setChannelOption(channel, e.getKey(), e.getValue(), logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setChannelOptions(
|
||||||
|
Channel channel, Map.Entry<ChannelOption<?>, Object>[] options, InternalLogger logger) {
|
||||||
|
for (Map.Entry<ChannelOption<?>, Object> e: options) {
|
||||||
|
setChannelOption(channel, e.getKey(), e.getValue(), logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static void setChannelOption(
|
||||||
|
Channel channel, ChannelOption<?> option, Object value, InternalLogger logger) {
|
||||||
|
try {
|
||||||
|
if (!channel.config().setOption((ChannelOption<Object>) option, value)) {
|
||||||
|
logger.warn("Unknown channel option '{}' for channel '{}'", option, channel);
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
logger.warn(
|
||||||
|
"Failed to set channel option '{}' with value '{}' for channel '{}'", option, channel, channel, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder buf = new StringBuilder()
|
StringBuilder buf = new StringBuilder()
|
||||||
|
@ -183,15 +183,7 @@ public class Bootstrap extends AbstractBootstrap<Bootstrap, Channel> {
|
|||||||
|
|
||||||
final Map<ChannelOption<?>, Object> options = options();
|
final Map<ChannelOption<?>, Object> options = options();
|
||||||
synchronized (options) {
|
synchronized (options) {
|
||||||
for (Entry<ChannelOption<?>, Object> e: options.entrySet()) {
|
setChannelOptions(channel, options, logger);
|
||||||
try {
|
|
||||||
if (!channel.config().setOption((ChannelOption<Object>) e.getKey(), e.getValue())) {
|
|
||||||
logger.warn("Unknown channel option: " + e);
|
|
||||||
}
|
|
||||||
} catch (Throwable t) {
|
|
||||||
logger.warn("Failed to set a channel option: " + channel, t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<AttributeKey<?>, Object> attrs = attrs();
|
final Map<AttributeKey<?>, Object> attrs = attrs();
|
||||||
|
@ -149,7 +149,7 @@ public class ServerBootstrap extends AbstractBootstrap<ServerBootstrap, ServerCh
|
|||||||
void init(Channel channel) throws Exception {
|
void init(Channel channel) throws Exception {
|
||||||
final Map<ChannelOption<?>, Object> options = options();
|
final Map<ChannelOption<?>, Object> options = options();
|
||||||
synchronized (options) {
|
synchronized (options) {
|
||||||
channel.config().setOptions(options);
|
setChannelOptions(channel, options, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<AttributeKey<?>, Object> attrs = attrs();
|
final Map<AttributeKey<?>, Object> attrs = attrs();
|
||||||
@ -212,13 +212,13 @@ public class ServerBootstrap extends AbstractBootstrap<ServerBootstrap, ServerCh
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static Entry<ChannelOption<?>, Object>[] newOptionArray(int size) {
|
private static Entry<AttributeKey<?>, Object>[] newAttrArray(int size) {
|
||||||
return new Entry[size];
|
return new Entry[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static Entry<AttributeKey<?>, Object>[] newAttrArray(int size) {
|
private static Map.Entry<ChannelOption<?>, Object>[] newOptionArray(int size) {
|
||||||
return new Entry[size];
|
return new Map.Entry[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ServerBootstrapAcceptor extends ChannelInboundHandlerAdapter {
|
private static class ServerBootstrapAcceptor extends ChannelInboundHandlerAdapter {
|
||||||
@ -245,13 +245,7 @@ public class ServerBootstrap extends AbstractBootstrap<ServerBootstrap, ServerCh
|
|||||||
child.pipeline().addLast(childHandler);
|
child.pipeline().addLast(childHandler);
|
||||||
|
|
||||||
for (Entry<ChannelOption<?>, Object> e: childOptions) {
|
for (Entry<ChannelOption<?>, Object> e: childOptions) {
|
||||||
try {
|
setChannelOptions(child, childOptions, logger);
|
||||||
if (!child.config().setOption((ChannelOption<Object>) e.getKey(), e.getValue())) {
|
|
||||||
logger.warn("Unknown channel option: " + e);
|
|
||||||
}
|
|
||||||
} catch (Throwable t) {
|
|
||||||
logger.warn("Failed to set a channel option: " + child, t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Entry<AttributeKey<?>, Object> e: childAttrs) {
|
for (Entry<AttributeKey<?>, Object> e: childAttrs) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user