Check if logging level is enabled before log. See #192
This commit is contained in:
parent
1b099acde0
commit
479def20bd
@ -518,10 +518,13 @@ public class HashedWheelTimer implements Timer {
|
||||
try {
|
||||
task.run(this);
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"An exception was thrown by " +
|
||||
TimerTask.class.getSimpleName() + ".", t);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,6 +43,7 @@ public class SharedResourceMisuseDetector {
|
||||
|
||||
public void increase() {
|
||||
if (activeInstances.incrementAndGet() > MAX_ACTIVE_INSTANCES) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
if (logged.compareAndSet(false, true)) {
|
||||
logger.warn(
|
||||
"You are creating too many " + type.getSimpleName() +
|
||||
@ -52,6 +53,7 @@ public class SharedResourceMisuseDetector {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void decrease() {
|
||||
activeInstances.decrementAndGet();
|
||||
|
@ -81,8 +81,11 @@ public class AutobahnServerHandler extends SimpleChannelUpstreamHandler {
|
||||
}
|
||||
|
||||
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String
|
||||
.format("Channel %s received %s", ctx.getChannel().getId(), frame.getClass().getSimpleName()));
|
||||
}
|
||||
|
||||
|
||||
if (frame instanceof CloseWebSocketFrame) {
|
||||
this.handshaker.close(ctx.getChannel(), (CloseWebSocketFrame) frame);
|
||||
|
@ -116,7 +116,9 @@ public class WebSocketServerHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
// Send the uppercase string back.
|
||||
String request = ((TextWebSocketFrame) frame).getText();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Channel %s received %s", ctx.getChannel().getId(), request));
|
||||
}
|
||||
ctx.getChannel().write(new TextWebSocketFrame(request.toUpperCase()));
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,9 @@ public class WebSocketSslServerHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
// Send the uppercase string back.
|
||||
String request = ((TextWebSocketFrame) frame).getText();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Channel %s received %s", ctx.getChannel().getId(), request));
|
||||
}
|
||||
ctx.getChannel().write(new TextWebSocketFrame(request.toUpperCase()));
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,9 @@ public final class WebSocketSslServerSslContext {
|
||||
}
|
||||
_serverContext = serverContext;
|
||||
} catch (Exception ex) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("Error initializing SslContextManager. " + ex.getMessage(), ex);
|
||||
}
|
||||
System.exit(1);
|
||||
|
||||
}
|
||||
|
@ -58,7 +58,9 @@ public class CIDR6 extends CIDR {
|
||||
try {
|
||||
return bigIntToIPv6Address(addressEndBigInt);
|
||||
} catch (UnknownHostException e) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("invalid ip address calculated as an end address");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,9 @@ public class IpFilterRuleList extends ArrayList<IpFilterRule> {
|
||||
return;
|
||||
}
|
||||
if (!(rule.startsWith("+") || rule.startsWith("-"))) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("syntax error in ip filter rule:" + rule);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -80,10 +82,14 @@ public class IpFilterRuleList extends ArrayList<IpFilterRule> {
|
||||
try {
|
||||
this.add(new IpSubnetFilterRule(allow, rule.substring(3)));
|
||||
} catch (UnknownHostException e) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("error parsing ip filter " + rule, e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("syntax error in ip filter rule:" + rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,8 +158,10 @@ public class PatternRule implements IpFilterRule, Comparable<Object> {
|
||||
return true;
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("error getting ip of localhost", e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
InetAddress[] addrs = InetAddress.getAllByName("127.0.0.1");
|
||||
for (InetAddress addr : addrs) {
|
||||
@ -168,8 +170,10 @@ public class PatternRule implements IpFilterRule, Comparable<Object> {
|
||||
}
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("error getting ip of localhost", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
@ -497,11 +497,13 @@ public class SslHandler extends FrameDecoder
|
||||
try {
|
||||
engine.closeInbound();
|
||||
} catch (SSLException ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Failed to clean up SSLEngine.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
|
||||
@ -513,9 +515,12 @@ public class SslHandler extends FrameDecoder
|
||||
synchronized (ignoreClosedChannelExceptionLock) {
|
||||
if (ignoreClosedChannelException > 0) {
|
||||
ignoreClosedChannelException --;
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"Swallowing an exception raised while " +
|
||||
"writing non-app data", cause);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -524,10 +529,12 @@ public class SslHandler extends FrameDecoder
|
||||
if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
|
||||
// It is safe to ignore the 'connection reset by peer' or
|
||||
// 'broken pipe' error after sending closure_notify.
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"Swallowing a 'connection reset by peer / " +
|
||||
"broken pipe' error occurred while writing " +
|
||||
"'closure_notify'", cause);
|
||||
}
|
||||
|
||||
// Close the connection explicitly just in case the transport
|
||||
// did not close the connection automatically.
|
||||
@ -1085,10 +1092,13 @@ public class SslHandler extends FrameDecoder
|
||||
try {
|
||||
engine.closeInbound();
|
||||
} catch (SSLException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"SSLEngine.closeInbound() raised an exception after " +
|
||||
"a handshake failure.", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
handshakeFuture.setFailure(cause);
|
||||
@ -1106,8 +1116,10 @@ public class SslHandler extends FrameDecoder
|
||||
try {
|
||||
unwrap(context, e.getChannel(), ChannelBuffers.EMPTY_BUFFER, 0, 0);
|
||||
} catch (SSLException ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Failed to unwrap before sending a close_notify message", ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (!engine.isInboundDone()) {
|
||||
if (sentCloseNotify.compareAndSet(false, true)) {
|
||||
@ -1118,9 +1130,11 @@ public class SslHandler extends FrameDecoder
|
||||
new ClosingChannelFutureListener(context, e));
|
||||
success = true;
|
||||
} catch (SSLException ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Failed to encode a close_notify message", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
success = true;
|
||||
}
|
||||
|
@ -92,9 +92,11 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
|
||||
try {
|
||||
flush(ctx);
|
||||
} catch (Exception e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Unexpected exception while sending chunks.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
|
||||
@ -270,7 +272,9 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
|
||||
try {
|
||||
chunks.close();
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to close a chunked input.", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,9 @@ public abstract class AbstractSocketSslEchoTest {
|
||||
ChannelFuture ccf = cb.connect(new InetSocketAddress(SocketAddresses.LOCALHOST, port));
|
||||
ccf.awaitUninterruptibly();
|
||||
if (!ccf.isSuccess()) {
|
||||
if(logger.isErrorEnabled()) {
|
||||
logger.error("Connection attempt failed", ccf.getCause());
|
||||
}
|
||||
sc.close().awaitUninterruptibly();
|
||||
}
|
||||
assertTrue(ccf.isSuccess());
|
||||
@ -238,9 +240,11 @@ public abstract class AbstractSocketSslEchoTest {
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
|
||||
throws Exception {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Unexpected exception from the " +
|
||||
(server? "server" : "client") + " side", e.getCause());
|
||||
}
|
||||
|
||||
exception.compareAndSet(null, e.getCause());
|
||||
e.getChannel().close();
|
||||
|
@ -53,6 +53,7 @@ class DefaultNioSctpChannelConfig extends DefaultSctpChannelConfig implements Ni
|
||||
if (getWriteBufferHighWaterMark() < getWriteBufferLowWaterMark()) {
|
||||
// Recover the integrity of the configuration with a sensible value.
|
||||
setWriteBufferLowWaterMark0(getWriteBufferHighWaterMark() >>> 1);
|
||||
if (logger.isWarnEnabled()) {
|
||||
// Notify the user about misconfiguration.
|
||||
logger.warn(
|
||||
"writeBufferLowWaterMark cannot be greater than " +
|
||||
@ -60,6 +61,7 @@ class DefaultNioSctpChannelConfig extends DefaultSctpChannelConfig implements Ni
|
||||
"writeBufferHighWaterMark.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOption(String key, Object value) {
|
||||
|
@ -55,12 +55,14 @@ final class SctpClientChannel extends SctpChannelImpl {
|
||||
try {
|
||||
underlayingChannel.close();
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to close a partially initialized socket.",
|
||||
e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return underlayingChannel;
|
||||
}
|
||||
|
@ -289,8 +289,10 @@ class SctpClientPipelineSink extends AbstractChannelSink {
|
||||
try {
|
||||
selector.close();
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to close a selector.", e);
|
||||
}
|
||||
} finally {
|
||||
this.selector = null;
|
||||
}
|
||||
@ -307,8 +309,10 @@ class SctpClientPipelineSink extends AbstractChannelSink {
|
||||
shutdown = false;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Unexpected exception in the selector loop.", t);
|
||||
}
|
||||
|
||||
// Prevent possible consecutive immediate failures.
|
||||
try {
|
||||
|
@ -24,17 +24,12 @@ import com.sun.nio.sctp.SendFailedNotification;
|
||||
import com.sun.nio.sctp.ShutdownNotification;
|
||||
|
||||
import io.netty.channel.Channels;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
class SctpNotificationHandler extends AbstractNotificationHandler {
|
||||
|
||||
private static final InternalLogger logger =
|
||||
InternalLoggerFactory.getInstance(SctpNotificationHandler.class);
|
||||
|
||||
private final SctpChannelImpl sctpChannel;
|
||||
private final SctpWorker sctpWorker;
|
||||
|
||||
|
@ -61,29 +61,37 @@ final class SctpProviderMetadata {
|
||||
}
|
||||
|
||||
if (constraintLevel >= 0) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"Setting the NIO constraint level to: " + constraintLevel);
|
||||
}
|
||||
}
|
||||
|
||||
if (constraintLevel < 0) {
|
||||
constraintLevel = detectConstraintLevelFromSystemProperties();
|
||||
|
||||
if (constraintLevel < 0) {
|
||||
constraintLevel = 2;
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"Couldn't determine the NIO constraint level from " +
|
||||
"the system properties; using the safest level (2)");
|
||||
}
|
||||
} else if (constraintLevel != 0) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info(
|
||||
"Using the autodetected NIO constraint level: " +
|
||||
constraintLevel +
|
||||
" (Use better NIO provider for better performance)");
|
||||
}
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"Using the autodetected NIO constraint level: " +
|
||||
constraintLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CONSTRAINT_LEVEL = constraintLevel;
|
||||
|
||||
@ -236,7 +244,9 @@ final class SctpProviderMetadata {
|
||||
ch.bind(new InetSocketAddress(0));
|
||||
ch.configureBlocking(false);
|
||||
} catch (Throwable e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to configure a temporary socket.", e);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -244,7 +254,9 @@ final class SctpProviderMetadata {
|
||||
try {
|
||||
loop = new SelectorLoop();
|
||||
} catch (Throwable e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to open a temporary selector.", e);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -252,7 +264,9 @@ final class SctpProviderMetadata {
|
||||
try {
|
||||
ch.register(loop.selector, 0);
|
||||
} catch (Throwable e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to register a temporary selector.", e);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -338,9 +352,11 @@ final class SctpProviderMetadata {
|
||||
try {
|
||||
ch.close();
|
||||
} catch (Throwable e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to close a temporary socket.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (loop != null) {
|
||||
loop.done = true;
|
||||
@ -368,10 +384,12 @@ final class SctpProviderMetadata {
|
||||
try {
|
||||
loop.selector.close();
|
||||
} catch (Throwable e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to close a temporary selector.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return constraintLevel;
|
||||
}
|
||||
@ -406,11 +424,13 @@ final class SctpProviderMetadata {
|
||||
}
|
||||
keys.clear();
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to wait for a temporary selector.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (Entry<Object, Object> e: System.getProperties().entrySet()) {
|
||||
|
@ -71,9 +71,11 @@ class SctpServerChannelImpl extends AbstractServerChannel
|
||||
try {
|
||||
serverChannel.close();
|
||||
} catch (IOException e2) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to close a partially initialized socket.", e2);
|
||||
}
|
||||
}
|
||||
|
||||
throw new ChannelException("Failed to enter non-blocking mode.", e);
|
||||
}
|
||||
|
@ -246,8 +246,10 @@ class SctpServerPipelineSink extends AbstractChannelSink {
|
||||
// Closed as requested.
|
||||
break;
|
||||
} catch (Throwable e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to accept a connection.", e);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e1) {
|
||||
@ -271,25 +273,31 @@ class SctpServerPipelineSink extends AbstractChannelSink {
|
||||
SctpServerPipelineSink.this, acceptedSocket,
|
||||
worker, currentThread), null);
|
||||
} catch (Exception e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to initialize an accepted socket.", e);
|
||||
}
|
||||
try {
|
||||
acceptedSocket.close();
|
||||
} catch (IOException e2) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to close a partially accepted socket.",
|
||||
e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void closeSelector() {
|
||||
channel.selector = null;
|
||||
try {
|
||||
selector.close();
|
||||
} catch (Exception e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to close a selector.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,8 +110,10 @@ class SctpWorker implements Runnable {
|
||||
try {
|
||||
selector.close();
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to close a selector.", t);
|
||||
}
|
||||
}
|
||||
this.selector = selector = null;
|
||||
// The method will return to the caller at this point.
|
||||
}
|
||||
@ -204,8 +206,10 @@ class SctpWorker implements Runnable {
|
||||
try {
|
||||
selector.close();
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to close a selector.", e);
|
||||
}
|
||||
} finally {
|
||||
this.selector = null;
|
||||
}
|
||||
@ -222,9 +226,10 @@ class SctpWorker implements Runnable {
|
||||
shutdown = false;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Unexpected exception in the selector loop.", t);
|
||||
|
||||
}
|
||||
// Prevent possible consecutive immediate failures that lead to
|
||||
// excessive CPU consumption.
|
||||
try {
|
||||
@ -313,7 +318,9 @@ class SctpWorker implements Runnable {
|
||||
if (messageInfo.isComplete()) {
|
||||
failure = false;
|
||||
} else {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("Received incomplete sctp packet, can not continue! Expected SCTP_EXPLICIT_COMPLETE message");
|
||||
}
|
||||
failure = true;
|
||||
}
|
||||
} else {
|
||||
|
@ -32,11 +32,14 @@ final class SelectorUtil {
|
||||
try {
|
||||
selector.select(10); // does small timeout give more throughput + less CPU usage?
|
||||
} catch (CancelledKeyException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
// Harmless exception - log anyway
|
||||
logger.debug(
|
||||
CancelledKeyException.class.getSimpleName() +
|
||||
" raised by a Selector - JDK bug?", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private SelectorUtil() {
|
||||
|
@ -48,11 +48,13 @@ public abstract class CompleteChannelFuture implements ChannelFuture {
|
||||
try {
|
||||
listener.operationComplete(this);
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"An exception was thrown by " +
|
||||
ChannelFutureListener.class.getSimpleName() + ".", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(ChannelFutureListener listener) {
|
||||
|
@ -56,11 +56,13 @@ public class DefaultChannelFuture implements ChannelFuture {
|
||||
public static void setUseDeadLockChecker(boolean useDeadLockChecker) {
|
||||
if (!useDeadLockChecker && !disabledDeadLockCheckerOnce) {
|
||||
disabledDeadLockCheckerOnce = true;
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"The dead lock checker in " +
|
||||
DefaultChannelFuture.class.getSimpleName() +
|
||||
" has been disabled as requested at your own risk.");
|
||||
}
|
||||
}
|
||||
DefaultChannelFuture.useDeadLockChecker = useDeadLockChecker;
|
||||
}
|
||||
|
||||
@ -413,11 +415,13 @@ public class DefaultChannelFuture implements ChannelFuture {
|
||||
try {
|
||||
l.operationComplete(this);
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"An exception was thrown by " +
|
||||
ChannelFutureListener.class.getSimpleName() + ".", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setProgress(long amount, long current, long total) {
|
||||
@ -453,9 +457,11 @@ public class DefaultChannelFuture implements ChannelFuture {
|
||||
try {
|
||||
l.operationProgressed(this, amount, current, total);
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"An exception was thrown by " +
|
||||
ChannelFutureProgressListener.class.getSimpleName() + ".", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -357,8 +357,10 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
remove((DefaultChannelHandlerContext) ctx);
|
||||
removed = true;
|
||||
} catch (Throwable t2) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to remove a handler: " + ctx.getName(), t2);
|
||||
}
|
||||
}
|
||||
|
||||
if (removed) {
|
||||
throw new ChannelHandlerLifeCycleException(
|
||||
@ -564,8 +566,9 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
public void sendUpstream(ChannelEvent e) {
|
||||
DefaultChannelHandlerContext head = getActualUpstreamContext(this.head);
|
||||
if (head == null) {
|
||||
logger.warn(
|
||||
"The pipeline contains no upstream handlers; discarding: " + e);
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("The pipeline contains no upstream handlers; discarding: " + e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -648,9 +651,11 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
|
||||
protected void notifyHandlerException(ChannelEvent e, Throwable t) {
|
||||
if (e instanceof ExceptionEvent) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"An exception was thrown by a user handler " +
|
||||
"while handling an exception event (" + e + ")", t);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -664,9 +669,11 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
try {
|
||||
sink.exceptionCaught(this, e, pe);
|
||||
} catch (Exception e1) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("An exception was thrown by an exception handler.", e1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void init(String name, ChannelHandler handler) {
|
||||
DefaultChannelHandlerContext ctx = new DefaultChannelHandlerContext(null, null, name, handler);
|
||||
@ -815,8 +822,10 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
|
||||
@Override
|
||||
public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Not attached yet; discarding: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelPipeline pipeline,
|
||||
|
@ -81,7 +81,9 @@ public class DefaultFileRegion implements FileRegion {
|
||||
try {
|
||||
file.close();
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to close a file.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -382,9 +382,11 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture {
|
||||
try {
|
||||
l.operationComplete(this);
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"An exception was thrown by " +
|
||||
ChannelFutureListener.class.getSimpleName() + ".", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,8 +116,10 @@ final class LocalClientChannelSink extends AbstractChannelSink {
|
||||
} catch (Exception e) {
|
||||
future.setFailure(e);
|
||||
fireExceptionCaught(channel, e);
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to initialize an accepted socket.", e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -47,11 +47,14 @@ class DefaultNioDatagramChannelConfig extends DefaultDatagramChannelConfig
|
||||
if (getWriteBufferHighWaterMark() < getWriteBufferLowWaterMark()) {
|
||||
// Recover the integrity of the configuration with a sensible value.
|
||||
setWriteBufferLowWaterMark0(getWriteBufferHighWaterMark() >>> 1);
|
||||
if (logger.isWarnEnabled()) {
|
||||
// Notify the user about misconfiguration.
|
||||
logger.warn("writeBufferLowWaterMark cannot be greater than "
|
||||
+ "writeBufferHighWaterMark; setting to the half of the "
|
||||
+ "writeBufferHighWaterMark.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,12 +55,15 @@ class DefaultNioSocketChannelConfig extends DefaultSocketChannelConfig
|
||||
if (getWriteBufferHighWaterMark() < getWriteBufferLowWaterMark()) {
|
||||
// Recover the integrity of the configuration with a sensible value.
|
||||
setWriteBufferLowWaterMark0(getWriteBufferHighWaterMark() >>> 1);
|
||||
if (logger.isWarnEnabled()) {
|
||||
// Notify the user about misconfiguration.
|
||||
logger.warn(
|
||||
"writeBufferLowWaterMark cannot be greater than " +
|
||||
"writeBufferHighWaterMark; setting to the half of the " +
|
||||
"writeBufferHighWaterMark.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,10 +52,13 @@ final class NioClientSocketChannel extends NioSocketChannel {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to close a partially initialized socket.",
|
||||
e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,8 +208,10 @@ class NioClientSocketPipelineSink extends AbstractChannelSink {
|
||||
try {
|
||||
selector.close();
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to close a selector.", t);
|
||||
}
|
||||
}
|
||||
this.selector = selector = null;
|
||||
// The method will return to the caller at this point.
|
||||
}
|
||||
@ -302,8 +304,11 @@ class NioClientSocketPipelineSink extends AbstractChannelSink {
|
||||
try {
|
||||
selector.close();
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to close a selector.", e);
|
||||
}
|
||||
|
||||
} finally {
|
||||
this.selector = null;
|
||||
}
|
||||
@ -320,8 +325,11 @@ class NioClientSocketPipelineSink extends AbstractChannelSink {
|
||||
shutdown = false;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Unexpected exception in the selector loop.", t);
|
||||
}
|
||||
|
||||
|
||||
// Prevent possible consecutive immediate failures.
|
||||
try {
|
||||
|
@ -155,8 +155,10 @@ class NioDatagramWorker implements Runnable {
|
||||
// Release the Selector if the execution fails.
|
||||
selector.close();
|
||||
} catch (final Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to close a selector.", t);
|
||||
}
|
||||
}
|
||||
this.selector = selector = null;
|
||||
// The method will return to the caller at this point.
|
||||
}
|
||||
|
@ -70,19 +70,26 @@ final class NioProviderMetadata {
|
||||
|
||||
if (constraintLevel < 0) {
|
||||
constraintLevel = 2;
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"Couldn't determine the NIO constraint level from " +
|
||||
"the system properties; using the safest level (2)");
|
||||
}
|
||||
} else if (constraintLevel != 0) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info(
|
||||
"Using the autodetected NIO constraint level: " +
|
||||
constraintLevel +
|
||||
" (Use better NIO provider for better performance)");
|
||||
}
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"Using the autodetected NIO constraint level: " +
|
||||
constraintLevel);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
CONSTRAINT_LEVEL = constraintLevel;
|
||||
@ -235,7 +242,9 @@ final class NioProviderMetadata {
|
||||
ch.socket().bind(new InetSocketAddress(0));
|
||||
ch.configureBlocking(false);
|
||||
} catch (Throwable e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to configure a temporary socket.", e);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -243,7 +252,9 @@ final class NioProviderMetadata {
|
||||
try {
|
||||
loop = new SelectorLoop();
|
||||
} catch (Throwable e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to open a temporary selector.", e);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -251,7 +262,9 @@ final class NioProviderMetadata {
|
||||
try {
|
||||
ch.register(loop.selector, 0);
|
||||
} catch (Throwable e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to register a temporary selector.", e);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -337,9 +350,11 @@ final class NioProviderMetadata {
|
||||
try {
|
||||
ch.close();
|
||||
} catch (Throwable e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to close a temporary socket.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (loop != null) {
|
||||
loop.done = true;
|
||||
@ -367,10 +382,12 @@ final class NioProviderMetadata {
|
||||
try {
|
||||
loop.selector.close();
|
||||
} catch (Throwable e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to close a temporary selector.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return constraintLevel;
|
||||
}
|
||||
@ -405,11 +422,13 @@ final class NioProviderMetadata {
|
||||
}
|
||||
keys.clear();
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to wait for a temporary selector.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (Entry<Object, Object> e: System.getProperties().entrySet()) {
|
||||
|
@ -73,10 +73,13 @@ final class NioServerSocketChannel extends AbstractServerChannel
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e2) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to close a partially initialized socket.", e2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
throw new ChannelException("Failed to enter non-blocking mode.", e);
|
||||
}
|
||||
|
||||
|
@ -243,8 +243,10 @@ class NioServerSocketPipelineSink extends AbstractChannelSink {
|
||||
// Closed as requested.
|
||||
break;
|
||||
} catch (Throwable e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to accept a connection.", e);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e1) {
|
||||
@ -266,25 +268,31 @@ class NioServerSocketPipelineSink extends AbstractChannelSink {
|
||||
worker.register(NioAcceptedSocketChannel.create(channel.getFactory(), pipeline, channel,
|
||||
NioServerSocketPipelineSink.this, acceptedSocket, worker, currentThread), null);
|
||||
} catch (Exception e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to initialize an accepted socket.", e);
|
||||
}
|
||||
try {
|
||||
acceptedSocket.close();
|
||||
} catch (IOException e2) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to close a partially accepted socket.",
|
||||
e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void closeSelector() {
|
||||
channel.selector = null;
|
||||
try {
|
||||
selector.close();
|
||||
} catch (Exception e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to close a selector.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -103,8 +103,10 @@ class NioWorker implements Runnable {
|
||||
try {
|
||||
selector.close();
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to close a selector.", t);
|
||||
}
|
||||
}
|
||||
this.selector = selector = null;
|
||||
// The method will return to the caller at this point.
|
||||
}
|
||||
@ -197,8 +199,10 @@ class NioWorker implements Runnable {
|
||||
try {
|
||||
selector.close();
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to close a selector.", e);
|
||||
}
|
||||
} finally {
|
||||
this.selector = null;
|
||||
}
|
||||
@ -215,8 +219,11 @@ class NioWorker implements Runnable {
|
||||
shutdown = false;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Unexpected exception in the selector loop.", t);
|
||||
}
|
||||
|
||||
|
||||
// Prevent possible consecutive immediate failures that lead to
|
||||
// excessive CPU consumption.
|
||||
|
@ -32,11 +32,14 @@ final class SelectorUtil {
|
||||
try {
|
||||
selector.select(500);
|
||||
} catch (CancelledKeyException e) {
|
||||
// Harmless exception - log anyway
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
CancelledKeyException.class.getSimpleName() +
|
||||
" raised by a Selector - JDK bug?", e);
|
||||
}
|
||||
// Harmless exception - log anyway
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private SelectorUtil() {
|
||||
|
@ -72,9 +72,12 @@ final class OioServerSocketChannel extends AbstractServerChannel
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e2) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to close a partially initialized socket.", e2);
|
||||
}
|
||||
|
||||
}
|
||||
throw new ChannelException(
|
||||
"Failed to set the server socket timeout.", e);
|
||||
}
|
||||
|
@ -203,16 +203,20 @@ class OioServerSocketPipelineSink extends AbstractChannelSink {
|
||||
workerExecutor,
|
||||
new OioWorker(acceptedChannel));
|
||||
} catch (Exception e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to initialize an accepted socket.", e);
|
||||
}
|
||||
try {
|
||||
acceptedSocket.close();
|
||||
} catch (IOException e2) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to close a partially accepted socket.",
|
||||
e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SocketTimeoutException e) {
|
||||
// Thrown every second to stop when requested.
|
||||
} catch (Throwable e) {
|
||||
@ -222,8 +226,11 @@ class OioServerSocketPipelineSink extends AbstractChannelSink {
|
||||
break;
|
||||
}
|
||||
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"Failed to accept a connection.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e1) {
|
||||
|
Loading…
Reference in New Issue
Block a user