broker/AutoFlushHandler: code formatter used

This commit is contained in:
Andreas Mager
2017-02-01 17:13:37 +01:00
parent 4483e554e9
commit 2adee4054c
@@ -13,23 +13,21 @@
* *
* You may elect to redistribute this code under either of these licenses. * You may elect to redistribute this code under either of these licenses.
*/ */
package io.moquette.server.netty; package io.moquette.server.netty;
import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.EventExecutor;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* Auto-flush data on channel after a read timeout. * Auto-flush data on channel after a read timeout. It's inspired by IdleStateHandler but it's
* It's inspired by IdleStateHandler but it's specialized version, just flushing data after * specialized version, just flushing data after no read is done on the channel after a period. It's
* no read is done on the channel after a period. It's used to avoid aggressively flushing from * used to avoid aggressively flushing from the ProtocolProcessor.
* the ProtocolProcessor.
*/ */
public class AutoFlushHandler extends ChannelDuplexHandler { public class AutoFlushHandler extends ChannelDuplexHandler {
@@ -126,9 +124,7 @@ public class AutoFlushHandler extends ChannelDuplexHandler {
EventExecutor loop = ctx.executor(); EventExecutor loop = ctx.executor();
lastWriteTime = System.nanoTime(); lastWriteTime = System.nanoTime();
writerIdleTimeout = loop.schedule( writerIdleTimeout = loop.schedule(new WriterIdleTimeoutTask(ctx), writerIdleTimeNanos, TimeUnit.NANOSECONDS);
new WriterIdleTimeoutTask(ctx),
writerIdleTimeNanos, TimeUnit.NANOSECONDS);
} }
private void destroy() { private void destroy() {
@@ -143,8 +139,10 @@ public class AutoFlushHandler extends ChannelDuplexHandler {
/** /**
* Is called when the write timeout expire. * Is called when the write timeout expire.
* *
* @param ctx the channel context. * @param ctx
* @throws Exception in case of any IO error. * the channel context.
* @throws Exception
* in case of any IO error.
*/ */
protected void channelIdle(ChannelHandlerContext ctx/* , IdleStateEvent evt */) throws Exception { protected void channelIdle(ChannelHandlerContext ctx/* , IdleStateEvent evt */) throws Exception {
// ctx.fireUserEventTriggered(evt); // ctx.fireUserEventTriggered(evt);
@@ -173,16 +171,13 @@ public class AutoFlushHandler extends ChannelDuplexHandler {
long nextDelay = writerIdleTimeNanos - (System.nanoTime() - lastWriteTime); long nextDelay = writerIdleTimeNanos - (System.nanoTime() - lastWriteTime);
if (nextDelay <= 0) { if (nextDelay <= 0) {
// Writer is idle - set a new timeout and notify the callback. // Writer is idle - set a new timeout and notify the callback.
writerIdleTimeout = ctx.executor().schedule( writerIdleTimeout = ctx.executor().schedule(this, writerIdleTimeNanos, TimeUnit.NANOSECONDS);
this, writerIdleTimeNanos, TimeUnit.NANOSECONDS);
try { try {
/*IdleStateEvent event; /*
if (firstWriterIdleEvent) { * IdleStateEvent event; if (firstWriterIdleEvent) { firstWriterIdleEvent =
firstWriterIdleEvent = false; * false; event = IdleStateEvent.FIRST_WRITER_IDLE_STATE_EVENT; } else { event =
event = IdleStateEvent.FIRST_WRITER_IDLE_STATE_EVENT; * IdleStateEvent.WRITER_IDLE_STATE_EVENT; }
} else { */
event = IdleStateEvent.WRITER_IDLE_STATE_EVENT;
}*/
channelIdle(ctx/* , event */); channelIdle(ctx/* , event */);
} catch (Throwable t) { } catch (Throwable t) {
ctx.fireExceptionCaught(t); ctx.fireExceptionCaught(t);