Remove Channel(Inbound|Outbound)HandlerAdapter which does nothing
- Thanks to the recent refactoring, Channel(Inbound|Outbound)Handler- Adapter ended up having empty body. No need to keep.
This commit is contained in:
parent
09570db091
commit
aab71ccd8a
@ -18,11 +18,12 @@ package io.netty.handler.codec;
|
||||
import io.netty.channel.ChannelBufferHolder;
|
||||
import io.netty.channel.ChannelBufferHolders;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelInboundHandler;
|
||||
import io.netty.channel.ChannelStateHandlerAdapter;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
public abstract class MessageToMessageDecoder<I, O> extends ChannelInboundHandlerAdapter<I> {
|
||||
public abstract class MessageToMessageDecoder<I, O> extends ChannelStateHandlerAdapter implements ChannelInboundHandler<I> {
|
||||
|
||||
@Override
|
||||
public ChannelBufferHolder<I> newInboundBuffer(
|
||||
|
@ -19,11 +19,13 @@ import io.netty.channel.ChannelBufferHolder;
|
||||
import io.netty.channel.ChannelBufferHolders;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOutboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelOperationHandlerAdapter;
|
||||
import io.netty.channel.ChannelOutboundHandler;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
public abstract class MessageToMessageEncoder<I, O> extends ChannelOutboundHandlerAdapter<I> {
|
||||
public abstract class MessageToMessageEncoder<I, O>
|
||||
extends ChannelOperationHandlerAdapter implements ChannelOutboundHandler<I> {
|
||||
|
||||
@Override
|
||||
public ChannelBufferHolder<I> newOutboundBuffer(
|
||||
|
@ -20,11 +20,13 @@ import io.netty.channel.ChannelBufferHolder;
|
||||
import io.netty.channel.ChannelBufferHolders;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOutboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelOperationHandlerAdapter;
|
||||
import io.netty.channel.ChannelOutboundHandler;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
public abstract class MessageToStreamEncoder<I> extends ChannelOutboundHandlerAdapter<I> {
|
||||
public abstract class MessageToStreamEncoder<I>
|
||||
extends ChannelOperationHandlerAdapter implements ChannelOutboundHandler<I> {
|
||||
|
||||
@Override
|
||||
public ChannelBufferHolder<I> newOutboundBuffer(
|
||||
|
@ -20,10 +20,11 @@ import io.netty.channel.ChannelBufferHolder;
|
||||
import io.netty.channel.ChannelBufferHolders;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandler;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.ChannelStateHandlerAdapter;
|
||||
|
||||
public abstract class StreamToMessageDecoder<O> extends ChannelInboundHandlerAdapter<Byte> {
|
||||
public abstract class StreamToMessageDecoder<O>
|
||||
extends ChannelStateHandlerAdapter implements ChannelInboundHandler<Byte> {
|
||||
|
||||
private ChannelHandlerContext ctx;
|
||||
|
||||
|
@ -19,9 +19,11 @@ import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.channel.ChannelBufferHolder;
|
||||
import io.netty.channel.ChannelBufferHolders;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelInboundHandler;
|
||||
import io.netty.channel.ChannelStateHandlerAdapter;
|
||||
|
||||
public abstract class StreamToStreamDecoder extends ChannelInboundHandlerAdapter<Byte> {
|
||||
public abstract class StreamToStreamDecoder
|
||||
extends ChannelStateHandlerAdapter implements ChannelInboundHandler<Byte> {
|
||||
|
||||
@Override
|
||||
public ChannelBufferHolder<Byte> newInboundBuffer(
|
||||
|
@ -20,9 +20,11 @@ import io.netty.channel.ChannelBufferHolder;
|
||||
import io.netty.channel.ChannelBufferHolders;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOutboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelOperationHandlerAdapter;
|
||||
import io.netty.channel.ChannelOutboundHandler;
|
||||
|
||||
public abstract class StreamToStreamEncoder extends ChannelOutboundHandlerAdapter<Byte> {
|
||||
public abstract class StreamToStreamEncoder
|
||||
extends ChannelOperationHandlerAdapter implements ChannelOutboundHandler<Byte> {
|
||||
|
||||
@Override
|
||||
public ChannelBufferHolder<Byte> newOutboundBuffer(
|
||||
|
@ -232,4 +232,16 @@ public class LoggingHandler extends ChannelHandlerAdapter {
|
||||
}
|
||||
super.deregister(ctx, future);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush(ChannelHandlerContext ctx, ChannelFuture future)
|
||||
throws Exception {
|
||||
ctx.flush(future);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inboundBufferUpdated(ChannelHandlerContext ctx)
|
||||
throws Exception {
|
||||
ctx.fireInboundBufferUpdated();
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,9 @@ import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelBufferHolder;
|
||||
import io.netty.channel.ChannelBufferHolders;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelInboundHandler;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.ChannelStateHandlerAdapter;
|
||||
import io.netty.util.internal.QueueFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -69,7 +70,8 @@ import java.util.concurrent.TimeUnit;
|
||||
*
|
||||
* @param <E> the type of the received messages
|
||||
*/
|
||||
public class BlockingReadHandler<E> extends ChannelInboundHandlerAdapter<Object> {
|
||||
public class BlockingReadHandler<E>
|
||||
extends ChannelStateHandlerAdapter implements ChannelInboundHandler<Object> {
|
||||
|
||||
private static final Object INACTIVE = new Object();
|
||||
|
||||
|
@ -23,8 +23,9 @@ import io.netty.channel.ChannelException;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerAdapter;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOutboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelOutboundHandler;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
@ -67,7 +68,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
* @apiviz.landmark
|
||||
* @apiviz.has io.netty.handler.stream.ChunkedInput oneway - - reads from
|
||||
*/
|
||||
public class ChunkedWriteHandler extends ChannelOutboundHandlerAdapter<Object> {
|
||||
public class ChunkedWriteHandler
|
||||
extends ChannelHandlerAdapter implements ChannelOutboundHandler<Object> {
|
||||
|
||||
private static final InternalLogger logger =
|
||||
InternalLoggerFactory.getInstance(ChunkedWriteHandler.class);
|
||||
|
@ -23,10 +23,11 @@ import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelInboundHandler;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.ChannelStateHandlerAdapter;
|
||||
import io.netty.channel.EventLoop;
|
||||
import io.netty.channel.ServerChannel;
|
||||
import io.netty.logging.InternalLogger;
|
||||
@ -230,9 +231,11 @@ public class ServerBootstrap {
|
||||
validate();
|
||||
}
|
||||
|
||||
private class Acceptor extends ChannelInboundHandlerAdapter<Channel> {
|
||||
private class Acceptor extends ChannelStateHandlerAdapter implements ChannelInboundHandler<Channel> {
|
||||
|
||||
@Override
|
||||
public ChannelBufferHolder<Channel> newInboundBuffer(ChannelHandlerContext ctx) {
|
||||
public ChannelBufferHolder<Channel> newInboundBuffer(
|
||||
ChannelHandlerContext ctx) throws Exception {
|
||||
return ChannelBufferHolders.messageBuffer();
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,10 @@
|
||||
*/
|
||||
package io.netty.channel;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Queue;
|
||||
|
||||
public class ChannelHandlerAdapter extends ChannelStateHandlerAdapter implements ChannelOperationHandler {
|
||||
|
||||
@ -46,10 +49,27 @@ public class ChannelHandlerAdapter extends ChannelStateHandlerAdapter implements
|
||||
|
||||
@Override
|
||||
public void flush(ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
||||
if (ctx.type().contains(ChannelHandlerType.OUTBOUND)) {
|
||||
ChannelOutboundHandlerAdapter.flush0(ctx, future);
|
||||
} else {
|
||||
flush0(ctx, future);
|
||||
}
|
||||
|
||||
static <O> void flush0(ChannelHandlerContext ctx, ChannelFuture future) {
|
||||
if (ctx.hasOutboundMessageBuffer()) {
|
||||
Queue<O> out = ctx.outboundMessageBuffer();
|
||||
Queue<Object> nextOut = ctx.nextOutboundMessageBuffer();
|
||||
for (;;) {
|
||||
O msg = out.poll();
|
||||
if (msg == null) {
|
||||
break;
|
||||
}
|
||||
nextOut.add(msg);
|
||||
}
|
||||
} else if (ctx.hasOutboundByteBuffer()) {
|
||||
ChannelBuffer out = ctx.outboundByteBuffer();
|
||||
ChannelBuffer nextOut = ctx.nextOutboundByteBuffer();
|
||||
nextOut.writeBytes(out);
|
||||
out.discardReadBytes();
|
||||
}
|
||||
|
||||
ctx.flush(future);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.channel;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
public abstract class ChannelInboundHandlerAdapter<I> extends ChannelStateHandlerAdapter
|
||||
implements ChannelInboundHandler<I> {
|
||||
|
||||
@Override
|
||||
public void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception {
|
||||
inboundBufferUpdated0(ctx);
|
||||
}
|
||||
|
||||
static <I> void inboundBufferUpdated0(ChannelHandlerContext ctx) {
|
||||
if (ctx.hasInboundMessageBuffer()) {
|
||||
Queue<I> in = ctx.inboundMessageBuffer();
|
||||
Queue<Object> nextIn = ctx.nextInboundMessageBuffer();
|
||||
for (;;) {
|
||||
I msg = in.poll();
|
||||
if (msg == null) {
|
||||
break;
|
||||
}
|
||||
nextIn.add(msg);
|
||||
}
|
||||
} else {
|
||||
ChannelBuffer in = ctx.inboundByteBuffer();
|
||||
ChannelBuffer nextIn = ctx.nextInboundByteBuffer();
|
||||
nextIn.writeBytes(in);
|
||||
in.discardReadBytes();
|
||||
}
|
||||
ctx.fireInboundBufferUpdated();
|
||||
}
|
||||
}
|
@ -17,8 +17,8 @@ package io.netty.channel;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
public class ChannelInboundMessageHandlerAdapter<I> extends
|
||||
ChannelInboundHandlerAdapter<I> {
|
||||
public class ChannelInboundMessageHandlerAdapter<I>
|
||||
extends ChannelStateHandlerAdapter implements ChannelInboundHandler<I> {
|
||||
|
||||
@Override
|
||||
public ChannelBufferHolder<I> newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
|
||||
|
@ -18,7 +18,9 @@ package io.netty.channel;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
|
||||
|
||||
public class ChannelInboundStreamHandlerAdapter extends ChannelInboundHandlerAdapter<Byte> {
|
||||
public class ChannelInboundStreamHandlerAdapter
|
||||
extends ChannelStateHandlerAdapter implements ChannelInboundHandler<Byte> {
|
||||
|
||||
@Override
|
||||
public ChannelBufferHolder<Byte> newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
|
||||
return ChannelBufferHolders.byteBuffer();
|
||||
|
@ -69,6 +69,6 @@ public class ChannelOperationHandlerAdapter implements ChannelOperationHandler {
|
||||
@Override
|
||||
public void flush(ChannelHandlerContext ctx, ChannelFuture future)
|
||||
throws Exception {
|
||||
ctx.flush(future);
|
||||
ChannelHandlerAdapter.flush0(ctx, future);
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.channel;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
public abstract class ChannelOutboundHandlerAdapter<O> extends ChannelHandlerAdapter
|
||||
implements ChannelOutboundHandler<O> {
|
||||
|
||||
@Override
|
||||
public void flush(ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
||||
flush0(ctx, future);
|
||||
}
|
||||
|
||||
static <O> void flush0(ChannelHandlerContext ctx, ChannelFuture future) {
|
||||
if (ctx.hasOutboundMessageBuffer()) {
|
||||
Queue<O> out = ctx.outboundMessageBuffer();
|
||||
Queue<Object> nextOut = ctx.nextOutboundMessageBuffer();
|
||||
for (;;) {
|
||||
O msg = out.poll();
|
||||
if (msg == null) {
|
||||
break;
|
||||
}
|
||||
nextOut.add(msg);
|
||||
}
|
||||
} else {
|
||||
ChannelBuffer out = ctx.outboundByteBuffer();
|
||||
ChannelBuffer nextOut = ctx.nextOutboundByteBuffer();
|
||||
nextOut.writeBytes(out);
|
||||
out.discardReadBytes();
|
||||
}
|
||||
ctx.flush(future);
|
||||
}
|
||||
}
|
@ -15,6 +15,10 @@
|
||||
*/
|
||||
package io.netty.channel;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
public class ChannelStateHandlerAdapter implements ChannelStateHandler {
|
||||
|
||||
// Not using volatile because it's used only for a sanity check.
|
||||
@ -78,10 +82,28 @@ public class ChannelStateHandlerAdapter implements ChannelStateHandler {
|
||||
|
||||
@Override
|
||||
public void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception {
|
||||
if (ctx.type().contains(ChannelHandlerType.INBOUND)) {
|
||||
ChannelInboundHandlerAdapter.inboundBufferUpdated0(ctx);
|
||||
} else {
|
||||
inboundBufferUpdated0(ctx);
|
||||
}
|
||||
|
||||
static <I> void inboundBufferUpdated0(ChannelHandlerContext ctx) {
|
||||
if (ctx.hasInboundMessageBuffer()) {
|
||||
Queue<I> in = ctx.inboundMessageBuffer();
|
||||
Queue<Object> nextIn = ctx.nextInboundMessageBuffer();
|
||||
for (;;) {
|
||||
I msg = in.poll();
|
||||
if (msg == null) {
|
||||
break;
|
||||
}
|
||||
nextIn.add(msg);
|
||||
}
|
||||
} else if (ctx.hasInboundByteBuffer()){
|
||||
ChannelBuffer in = ctx.inboundByteBuffer();
|
||||
ChannelBuffer nextIn = ctx.nextInboundByteBuffer();
|
||||
nextIn.writeBytes(in);
|
||||
in.discardReadBytes();
|
||||
}
|
||||
|
||||
ctx.fireInboundBufferUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user