Undeprecate deregister() and chanelUnregistered()

Motivation:

As discussed in #2250, it will become much less complicated to implement
deregistration and reregistration of a channel once #2250 is resolved.
Therefore, there's no need to deprecate deregister() and
channelUnregistered().

Modification:

- Undeprecate deregister() and channelUnregistered()
- Remove SuppressWarnings annotations where applicable

Result:

We (including @jakobbuchgraber) are now ready to play with #2250 at
master
This commit is contained in:
Trustin Lee 2014-04-25 16:40:42 +09:00
parent 75e1b3e799
commit bdab831ba5
11 changed files with 138 additions and 28 deletions

View File

@ -370,7 +370,6 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
} }
@Override @Override
@Deprecated
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
ctx.deregister(promise); ctx.deregister(promise);
} }

View File

@ -287,7 +287,6 @@ public interface Channel extends AttributeMap, Comparable<Channel> {
* {@link Channel}. * {@link Channel}.
* *
*/ */
@Deprecated
ChannelFuture deregister(); ChannelFuture deregister();
/** /**
@ -375,7 +374,6 @@ public interface Channel extends AttributeMap, Comparable<Channel> {
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
@Deprecated
ChannelFuture deregister(ChannelPromise promise); ChannelFuture deregister(ChannelPromise promise);
/** /**
@ -489,7 +487,6 @@ public interface Channel extends AttributeMap, Comparable<Channel> {
* Deregister the {@link Channel} of the {@link ChannelPromise} from {@link EventLoop} and notify the * Deregister the {@link Channel} of the {@link ChannelPromise} from {@link EventLoop} and notify the
* {@link ChannelPromise} once the operation was complete. * {@link ChannelPromise} once the operation was complete.
*/ */
@Deprecated
void deregister(ChannelPromise promise); void deregister(ChannelPromise promise);
/** /**

View File

@ -189,12 +189,7 @@ public interface ChannelHandler {
/** /**
* Gets called if a {@link Throwable} was thrown. * Gets called if a {@link Throwable} was thrown.
*
* @deprecated Will be removed in the future and only {@link ChannelInboundHandler} will receive
* exceptionCaught events. For {@link ChannelOutboundHandler} the {@link ChannelPromise}
* must be failed.
*/ */
@Deprecated
void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception; void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception;
/** /**

View File

@ -81,10 +81,8 @@ public abstract class ChannelHandlerAdapter implements ChannelHandler {
* *
* Sub-classes may override this method to change behavior. * Sub-classes may override this method to change behavior.
*/ */
@Deprecated
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
throws Exception {
ctx.fireExceptionCaught(cause); ctx.fireExceptionCaught(cause);
} }
} }

View File

@ -177,7 +177,6 @@ public interface ChannelHandlerContext
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the * called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
@Deprecated
ChannelHandlerContext fireChannelUnregistered(); ChannelHandlerContext fireChannelUnregistered();
/** /**
@ -311,7 +310,6 @@ public interface ChannelHandlerContext
* {@link Channel}. * {@link Channel}.
* *
*/ */
@Deprecated
ChannelFuture deregister(); ChannelFuture deregister();
/** /**
@ -399,7 +397,6 @@ public interface ChannelHandlerContext
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
@Deprecated
ChannelFuture deregister(ChannelPromise promise); ChannelFuture deregister(ChannelPromise promise);
/** /**

View File

@ -28,10 +28,7 @@ public interface ChannelInboundHandler extends ChannelHandler {
/** /**
* The {@link Channel} of the {@link ChannelHandlerContext} was unregistered from its {@link EventLoop} * The {@link Channel} of the {@link ChannelHandlerContext} was unregistered from its {@link EventLoop}
*
* @deprecated use {@link #channelInactive(ChannelHandlerContext)}
*/ */
@Deprecated
void channelUnregistered(ChannelHandlerContext ctx) throws Exception; void channelUnregistered(ChannelHandlerContext ctx) throws Exception;
/** /**

View File

@ -69,7 +69,6 @@ public interface ChannelOutboundHandler extends ChannelHandler {
* @param promise the {@link ChannelPromise} to notify once the operation completes * @param promise the {@link ChannelPromise} to notify once the operation completes
* @throws Exception thrown if an error accour * @throws Exception thrown if an error accour
*/ */
@Deprecated
void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception; void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception;
/** /**

View File

@ -612,7 +612,6 @@ public interface ChannelPipeline
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the * called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
@Deprecated
ChannelPipeline fireChannelUnregistered(); ChannelPipeline fireChannelUnregistered();
/** /**
@ -746,7 +745,6 @@ public interface ChannelPipeline
* {@link Channel}. * {@link Channel}.
* *
*/ */
@Deprecated
ChannelFuture deregister(); ChannelFuture deregister();
/** /**
@ -834,7 +832,6 @@ public interface ChannelPipeline
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
@Deprecated
ChannelFuture deregister(ChannelPromise promise); ChannelFuture deregister(ChannelPromise promise);
/** /**

View File

@ -220,7 +220,6 @@ public interface ChannelGroup extends Set<Channel>, Comparable<ChannelGroup> {
* @return the {@link ChannelGroupFuture} instance that notifies when * @return the {@link ChannelGroupFuture} instance that notifies when
* the operation is done for all channels * the operation is done for all channels
*/ */
@Deprecated
ChannelGroupFuture deregister(); ChannelGroupFuture deregister();
/** /**
@ -232,6 +231,5 @@ public interface ChannelGroup extends Set<Channel>, Comparable<ChannelGroup> {
* @return the {@link ChannelGroupFuture} instance that notifies when * @return the {@link ChannelGroupFuture} instance that notifies when
* the operation is done for all channels * the operation is done for all channels
*/ */
@Deprecated
ChannelGroupFuture deregister(ChannelMatcher matcher); ChannelGroupFuture deregister(ChannelMatcher matcher);
} }

View File

@ -173,7 +173,6 @@ public class DefaultChannelGroup extends AbstractSet<Channel> implements Channel
} }
@Override @Override
@Deprecated
public ChannelGroupFuture deregister() { public ChannelGroupFuture deregister() {
return deregister(ChannelMatchers.all()); return deregister(ChannelMatchers.all());
} }
@ -277,7 +276,6 @@ public class DefaultChannelGroup extends AbstractSet<Channel> implements Channel
} }
@Override @Override
@Deprecated
public ChannelGroupFuture deregister(ChannelMatcher matcher) { public ChannelGroupFuture deregister(ChannelMatcher matcher) {
if (matcher == null) { if (matcher == null) {
throw new NullPointerException("matcher"); throw new NullPointerException("matcher");

View File

@ -15,14 +15,18 @@
*/ */
package io.netty.channel; package io.netty.channel;
import static org.junit.Assert.assertTrue;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.LoggingHandler.Event; import io.netty.channel.LoggingHandler.Event;
import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalAddress;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import org.junit.Test; import org.junit.Test;
import java.nio.channels.ClosedChannelException;
import static org.junit.Assert.*;
public class ReentrantChannelTest extends BaseChannelTest { public class ReentrantChannelTest extends BaseChannelTest {
@Test @Test
@ -96,4 +100,135 @@ public class ReentrantChannelTest extends BaseChannelTest {
"WRITABILITY: writable=true\n"); "WRITABILITY: writable=true\n");
} }
@Test
public void testWriteFlushPingPong() throws Exception {
LocalAddress addr = new LocalAddress("testWriteFlushPingPong");
ServerBootstrap sb = getLocalServerBootstrap();
sb.bind(addr).sync().channel();
Bootstrap cb = getLocalClientBootstrap();
setInterest(Event.WRITE, Event.FLUSH, Event.CLOSE, Event.EXCEPTION);
Channel clientChannel = cb.connect(addr).sync().channel();
clientChannel.pipeline().addLast(new ChannelOutboundHandlerAdapter() {
int writeCount;
int flushCount;
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (writeCount < 5) {
writeCount++;
ctx.channel().flush();
}
super.write(ctx, msg, promise);
}
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
if (flushCount < 5) {
flushCount++;
ctx.channel().write(createTestBuf(2000));
}
super.flush(ctx);
}
});
clientChannel.writeAndFlush(createTestBuf(2000));
clientChannel.close().sync();
assertLog(
"WRITE\n" +
"FLUSH\n" +
"WRITE\n" +
"FLUSH\n" +
"WRITE\n" +
"FLUSH\n" +
"WRITE\n" +
"FLUSH\n" +
"WRITE\n" +
"FLUSH\n" +
"WRITE\n" +
"FLUSH\n" +
"CLOSE\n");
}
@Test
public void testCloseInFlush() throws Exception {
LocalAddress addr = new LocalAddress("testCloseInFlush");
ServerBootstrap sb = getLocalServerBootstrap();
sb.bind(addr).sync().channel();
Bootstrap cb = getLocalClientBootstrap();
setInterest(Event.WRITE, Event.FLUSH, Event.CLOSE, Event.EXCEPTION);
Channel clientChannel = cb.connect(addr).sync().channel();
clientChannel.pipeline().addLast(new ChannelOutboundHandlerAdapter() {
@Override
public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
promise.addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
ctx.channel().close();
}
});
super.write(ctx, msg, promise);
ctx.channel().flush();
}
});
clientChannel.write(createTestBuf(2000)).sync();
clientChannel.closeFuture().sync();
assertLog("WRITE\nFLUSH\nCLOSE\n");
}
@Test
public void testFlushFailure() throws Exception {
LocalAddress addr = new LocalAddress("testFlushFailure");
ServerBootstrap sb = getLocalServerBootstrap();
sb.bind(addr).sync().channel();
Bootstrap cb = getLocalClientBootstrap();
setInterest(Event.WRITE, Event.FLUSH, Event.CLOSE, Event.EXCEPTION);
Channel clientChannel = cb.connect(addr).sync().channel();
clientChannel.pipeline().addLast(new ChannelOutboundHandlerAdapter() {
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
throw new Exception("intentional failure");
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
ctx.close();
}
});
try {
clientChannel.writeAndFlush(createTestBuf(2000)).sync();
fail();
} catch (Throwable cce) {
// FIXME: shouldn't this contain the "intentional failure" exception?
assertEquals(ClosedChannelException.class, cce.getClass());
}
clientChannel.closeFuture().sync();
assertLog("WRITE\nCLOSE\n");
}
} }