From 349949d154233c170a89246e64a064599f13e922 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 27 Apr 2013 22:24:57 +1000 Subject: [PATCH] @normanmaurer, @trustin in relation to netty/1317 can we consider this a motion to allow channel.write(Object,null), I think it is a very good idea and cannot see it breaking any existing functionality at all. --- .../net/md_5/bungee/netty/ChannelWrapper.java | 11 +- .../net/md_5/bungee/netty/SillyPromise.java | 181 ++++++++++++++++++ 2 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 proxy/src/main/java/net/md_5/bungee/netty/SillyPromise.java diff --git a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java index 852db26e..e1d22b62 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java @@ -1,17 +1,22 @@ package net.md_5.bungee.netty; import io.netty.channel.Channel; -import lombok.RequiredArgsConstructor; -@RequiredArgsConstructor public class ChannelWrapper { private final Channel ch; + private final SillyPromise promise; + + public ChannelWrapper(Channel ch) + { + this.ch = ch; + this.promise = new SillyPromise( ch ); + } public void write(Object packet) { - ch.write( packet ); + ch.write( packet, promise ); } public Channel getHandle() diff --git a/proxy/src/main/java/net/md_5/bungee/netty/SillyPromise.java b/proxy/src/main/java/net/md_5/bungee/netty/SillyPromise.java new file mode 100644 index 00000000..c66b0f9a --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/netty/SillyPromise.java @@ -0,0 +1,181 @@ +package net.md_5.bungee.netty; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelPromise; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class SillyPromise implements ChannelPromise +{ + + private final Channel ch; + + @Override + public Channel channel() + { + return ch; + } + + @Override + public ChannelPromise setSuccess(Void v) + { + return this; + } + + @Override + public ChannelPromise setSuccess() + { + return this; + } + + @Override + public boolean trySuccess() + { + return true; + } + + @Override + public ChannelPromise setFailure(Throwable thrwbl) + { + return this; + + } + + @Override + public ChannelPromise addListener(GenericFutureListener> gl) + { + return this; + } + + @Override + public ChannelPromise addListeners(GenericFutureListener>... gls) + { + return this; + + } + + @Override + public ChannelPromise removeListener(GenericFutureListener> gl) + { + return this; + } + + @Override + public ChannelPromise removeListeners(GenericFutureListener>... gls) + { + return this; + } + + @Override + public ChannelPromise sync() throws InterruptedException + { + return this; + } + + @Override + public ChannelPromise syncUninterruptibly() + { + return this; + } + + @Override + public ChannelPromise await() throws InterruptedException + { + return this; + } + + @Override + public ChannelPromise awaitUninterruptibly() + { + return this; + } + + @Override + public boolean isSuccess() + { + return true; + } + + @Override + public Throwable cause() + { + return null; + } + + @Override + public boolean await(long l, TimeUnit tu) throws InterruptedException + { + return true; + } + + @Override + public boolean await(long l) throws InterruptedException + { + return true; + } + + @Override + public boolean awaitUninterruptibly(long l, TimeUnit tu) + { + return true; + } + + @Override + public boolean awaitUninterruptibly(long l) + { + return true; + } + + @Override + public Void getNow() + { + return null; + } + + @Override + public boolean cancel(boolean bln) + { + return true; + } + + @Override + public boolean isCancelled() + { + return true; + } + + @Override + public boolean isDone() + { + return false; + } + + @Override + public Void get() throws InterruptedException, ExecutionException + { + return null; + } + + @Override + public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException + { + return null; + } + + @Override + public boolean trySuccess(Void v) + { + return true; + } + + @Override + public boolean tryFailure(Throwable thrwbl) + { + return true; + } +}