Make ReusableChannelPromise less hacky

This commit is contained in:
md_5 2013-04-28 08:53:14 +10:00
parent cbb08ec58b
commit ce7c095243
3 changed files with 181 additions and 183 deletions

View File

@ -6,12 +6,12 @@ public class ChannelWrapper
{
private final Channel ch;
private final SillyPromise promise;
private final ReusableChannelPromise promise;
public ChannelWrapper(Channel ch)
{
this.ch = ch;
this.promise = new SillyPromise( ch );
this.promise = new ReusableChannelPromise( ch );
}
public void write(Object packet)

View File

@ -0,0 +1,179 @@
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 ReusableChannelPromise implements ChannelPromise
{
private final Channel ch;
@Override
public Channel channel()
{
return ch;
}
@Override
public ChannelPromise setSuccess(Void result)
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public ChannelPromise setSuccess()
{
return this;
}
@Override
public boolean trySuccess()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public ChannelPromise setFailure(Throwable cause)
{
return this;
}
@Override
public ChannelPromise addListener(GenericFutureListener<? extends Future<Void>> listener)
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public ChannelPromise addListeners(GenericFutureListener<? extends Future<Void>>... listeners)
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public ChannelPromise removeListener(GenericFutureListener<? extends Future<Void>> listener)
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public ChannelPromise removeListeners(GenericFutureListener<? extends Future<Void>>... listeners)
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public ChannelPromise sync() throws InterruptedException
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public ChannelPromise syncUninterruptibly()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public ChannelPromise await() throws InterruptedException
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public ChannelPromise awaitUninterruptibly()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public boolean isSuccess()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public Throwable cause()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public boolean await(long timeout, TimeUnit unit) throws InterruptedException
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public boolean await(long timeoutMillis) throws InterruptedException
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public boolean awaitUninterruptibly(long timeout, TimeUnit unit)
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public boolean awaitUninterruptibly(long timeoutMillis)
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public Void getNow()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public boolean cancel(boolean mayInterruptIfRunning)
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public boolean isCancelled()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public boolean isDone()
{
return false;
}
@Override
public Void get() throws InterruptedException, ExecutionException
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public boolean trySuccess(Void result)
{
throw new UnsupportedOperationException( "Not supported yet." );
}
@Override
public boolean tryFailure(Throwable cause)
{
throw new UnsupportedOperationException( "Not supported yet." );
}
}

View File

@ -1,181 +0,0 @@
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<? extends Future<Void>> gl)
{
return this;
}
@Override
public ChannelPromise addListeners(GenericFutureListener<? extends Future<Void>>... gls)
{
return this;
}
@Override
public ChannelPromise removeListener(GenericFutureListener<? extends Future<Void>> gl)
{
return this;
}
@Override
public ChannelPromise removeListeners(GenericFutureListener<? extends Future<Void>>... 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;
}
}