Tweak our channel promise to be a bit more hellpful on errors

This commit is contained in:
md_5 2013-06-13 20:51:22 +10:00
parent 78e67283cc
commit 12cba14657
3 changed files with 13 additions and 9 deletions

View File

@ -1,6 +1,7 @@
package net.md_5.bungee.netty; package net.md_5.bungee.netty;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.Getter; import lombok.Getter;
public class ChannelWrapper public class ChannelWrapper
@ -11,10 +12,10 @@ public class ChannelWrapper
private volatile boolean closed; private volatile boolean closed;
private final ReusableChannelPromise promise; private final ReusableChannelPromise promise;
public ChannelWrapper(Channel ch) public ChannelWrapper(ChannelHandlerContext ctx)
{ {
this.ch = ch; this.ch = ctx.channel();
this.promise = new ReusableChannelPromise( ch ); this.promise = new ReusableChannelPromise( ctx );
} }
public synchronized void write(Object packet) public synchronized void write(Object packet)

View File

@ -6,13 +6,10 @@ import io.netty.channel.ChannelInboundMessageHandlerAdapter;
import io.netty.handler.timeout.ReadTimeoutException; import io.netty.handler.timeout.ReadTimeoutException;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import net.md_5.bungee.ServerConnector;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.connection.CancelSendSignal; import net.md_5.bungee.connection.CancelSendSignal;
import net.md_5.bungee.connection.DownstreamBridge;
import net.md_5.bungee.connection.InitialHandler; import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.connection.PingHandler; import net.md_5.bungee.connection.PingHandler;
import net.md_5.bungee.connection.UpstreamBridge;
/** /**
* This class is a primitive wrapper for {@link PacketHandler} instances tied to * This class is a primitive wrapper for {@link PacketHandler} instances tied to
@ -36,7 +33,7 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<Object>
{ {
if ( handler != null ) if ( handler != null )
{ {
channel = new ChannelWrapper( ctx.channel() ); channel = new ChannelWrapper( ctx );
handler.connected( channel ); handler.connected( channel );
if ( !( handler instanceof InitialHandler || handler instanceof PingHandler ) ) if ( !( handler instanceof InitialHandler || handler instanceof PingHandler ) )

View File

@ -1,9 +1,11 @@
package net.md_5.bungee.netty; package net.md_5.bungee.netty;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.GenericFutureListener;
import java.nio.channels.ClosedChannelException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -15,12 +17,12 @@ import net.md_5.bungee.api.ProxyServer;
public class ReusableChannelPromise implements ChannelPromise public class ReusableChannelPromise implements ChannelPromise
{ {
private final Channel ch; private final ChannelHandlerContext ctx;
@Override @Override
public Channel channel() public Channel channel()
{ {
return ch; return ctx.channel();
} }
@Override @Override
@ -44,6 +46,10 @@ public class ReusableChannelPromise implements ChannelPromise
@Override @Override
public ChannelPromise setFailure(Throwable cause) public ChannelPromise setFailure(Throwable cause)
{ {
if ( !( cause instanceof ClosedChannelException ) )
{
ctx.fireExceptionCaught( cause );
}
return this; return this;
} }