Add back Channel(Inbound|Outbound)(Message|Stream)HandlerAdapter
- they are useful when creating an anonymous class - Also added back CombinedChannelHandler with extra constraints
This commit is contained in:
parent
aab71ccd8a
commit
8701e24b9a
@ -18,6 +18,7 @@ package io.netty.handler.codec.http;
|
|||||||
import io.netty.buffer.ChannelBuffer;
|
import io.netty.buffer.ChannelBuffer;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.channel.CombinedChannelHandler;
|
||||||
import io.netty.handler.codec.PrematureChannelClosureException;
|
import io.netty.handler.codec.PrematureChannelClosureException;
|
||||||
import io.netty.util.internal.QueueFactory;
|
import io.netty.util.internal.QueueFactory;
|
||||||
|
|
||||||
|
@ -15,6 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
|
import io.netty.channel.CombinedChannelHandler;
|
||||||
|
|
||||||
|
import io.netty.channel.CombinedChannelHandler;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A combination of {@link HttpRequestDecoder} and {@link HttpResponseEncoder}
|
* A combination of {@link HttpRequestDecoder} and {@link HttpResponseEncoder}
|
||||||
|
@ -15,6 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.spdy;
|
package io.netty.handler.codec.spdy;
|
||||||
|
|
||||||
|
import io.netty.channel.CombinedChannelHandler;
|
||||||
|
|
||||||
|
import io.netty.channel.CombinedChannelHandler;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A combination of {@link SpdyFrameDecoder} and {@link SpdyFrameEncoder}.
|
* A combination of {@link SpdyFrameDecoder} and {@link SpdyFrameEncoder}.
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.spdy;
|
package io.netty.handler.codec.spdy;
|
||||||
|
|
||||||
|
import io.netty.channel.CombinedChannelHandler;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A combination of {@link SpdyHttpDecoder} and {@link SpdyHttpEncoder}
|
* A combination of {@link SpdyHttpDecoder} and {@link SpdyHttpEncoder}
|
||||||
|
@ -15,21 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec;
|
package io.netty.handler.codec;
|
||||||
|
|
||||||
import io.netty.channel.ChannelBufferHolder;
|
|
||||||
import io.netty.channel.ChannelBufferHolders;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundHandler;
|
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||||
import io.netty.channel.ChannelStateHandlerAdapter;
|
|
||||||
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
public abstract class MessageToMessageDecoder<I, O> extends ChannelStateHandlerAdapter implements ChannelInboundHandler<I> {
|
public abstract class MessageToMessageDecoder<I, O> extends ChannelInboundMessageHandlerAdapter<I> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChannelBufferHolder<I> newInboundBuffer(
|
|
||||||
ChannelHandlerContext ctx) throws Exception {
|
|
||||||
return ChannelBufferHolders.messageBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inboundBufferUpdated(ChannelHandlerContext ctx)
|
public void inboundBufferUpdated(ChannelHandlerContext ctx)
|
||||||
|
@ -15,23 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec;
|
package io.netty.handler.codec;
|
||||||
|
|
||||||
import io.netty.channel.ChannelBufferHolder;
|
|
||||||
import io.netty.channel.ChannelBufferHolders;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelOperationHandlerAdapter;
|
import io.netty.channel.ChannelOutboundMessageHandlerAdapter;
|
||||||
import io.netty.channel.ChannelOutboundHandler;
|
|
||||||
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
public abstract class MessageToMessageEncoder<I, O>
|
public abstract class MessageToMessageEncoder<I, O> extends ChannelOutboundMessageHandlerAdapter<I> {
|
||||||
extends ChannelOperationHandlerAdapter implements ChannelOutboundHandler<I> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChannelBufferHolder<I> newOutboundBuffer(
|
|
||||||
ChannelHandlerContext ctx) throws Exception {
|
|
||||||
return ChannelBufferHolders.messageBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void flush(ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
public void flush(ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
||||||
|
@ -16,23 +16,13 @@
|
|||||||
package io.netty.handler.codec;
|
package io.netty.handler.codec;
|
||||||
|
|
||||||
import io.netty.buffer.ChannelBuffer;
|
import io.netty.buffer.ChannelBuffer;
|
||||||
import io.netty.channel.ChannelBufferHolder;
|
|
||||||
import io.netty.channel.ChannelBufferHolders;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelOperationHandlerAdapter;
|
import io.netty.channel.ChannelOutboundMessageHandlerAdapter;
|
||||||
import io.netty.channel.ChannelOutboundHandler;
|
|
||||||
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
public abstract class MessageToStreamEncoder<I>
|
public abstract class MessageToStreamEncoder<I> extends ChannelOutboundMessageHandlerAdapter<I> {
|
||||||
extends ChannelOperationHandlerAdapter implements ChannelOutboundHandler<I> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChannelBufferHolder<I> newOutboundBuffer(
|
|
||||||
ChannelHandlerContext ctx) throws Exception {
|
|
||||||
return ChannelBufferHolders.messageBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void flush(ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
public void flush(ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
||||||
|
@ -16,23 +16,19 @@
|
|||||||
package io.netty.handler.codec;
|
package io.netty.handler.codec;
|
||||||
|
|
||||||
import io.netty.buffer.ChannelBuffer;
|
import io.netty.buffer.ChannelBuffer;
|
||||||
import io.netty.channel.ChannelBufferHolder;
|
|
||||||
import io.netty.channel.ChannelBufferHolders;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundHandler;
|
import io.netty.channel.ChannelInboundHandler;
|
||||||
|
import io.netty.channel.ChannelInboundStreamHandlerAdapter;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.channel.ChannelStateHandlerAdapter;
|
|
||||||
|
|
||||||
public abstract class StreamToMessageDecoder<O>
|
public abstract class StreamToMessageDecoder<O> extends ChannelInboundStreamHandlerAdapter {
|
||||||
extends ChannelStateHandlerAdapter implements ChannelInboundHandler<Byte> {
|
|
||||||
|
|
||||||
private ChannelHandlerContext ctx;
|
private ChannelHandlerContext ctx;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelBufferHolder<Byte> newInboundBuffer(
|
public void beforeAdd(ChannelHandlerContext ctx) throws Exception {
|
||||||
ChannelHandlerContext ctx) throws Exception {
|
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
return ChannelBufferHolders.byteBuffer();
|
super.beforeAdd(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,20 +16,10 @@
|
|||||||
package io.netty.handler.codec;
|
package io.netty.handler.codec;
|
||||||
|
|
||||||
import io.netty.buffer.ChannelBuffer;
|
import io.netty.buffer.ChannelBuffer;
|
||||||
import io.netty.channel.ChannelBufferHolder;
|
|
||||||
import io.netty.channel.ChannelBufferHolders;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundHandler;
|
import io.netty.channel.ChannelInboundStreamHandlerAdapter;
|
||||||
import io.netty.channel.ChannelStateHandlerAdapter;
|
|
||||||
|
|
||||||
public abstract class StreamToStreamDecoder
|
public abstract class StreamToStreamDecoder extends ChannelInboundStreamHandlerAdapter {
|
||||||
extends ChannelStateHandlerAdapter implements ChannelInboundHandler<Byte> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChannelBufferHolder<Byte> newInboundBuffer(
|
|
||||||
ChannelHandlerContext ctx) throws Exception {
|
|
||||||
return ChannelBufferHolders.byteBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception {
|
public void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
@ -16,21 +16,11 @@
|
|||||||
package io.netty.handler.codec;
|
package io.netty.handler.codec;
|
||||||
|
|
||||||
import io.netty.buffer.ChannelBuffer;
|
import io.netty.buffer.ChannelBuffer;
|
||||||
import io.netty.channel.ChannelBufferHolder;
|
|
||||||
import io.netty.channel.ChannelBufferHolders;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelOperationHandlerAdapter;
|
import io.netty.channel.ChannelOutboundStreamHandlerAdapter;
|
||||||
import io.netty.channel.ChannelOutboundHandler;
|
|
||||||
|
|
||||||
public abstract class StreamToStreamEncoder
|
public abstract class StreamToStreamEncoder extends ChannelOutboundStreamHandlerAdapter {
|
||||||
extends ChannelOperationHandlerAdapter implements ChannelOutboundHandler<Byte> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChannelBufferHolder<Byte> newOutboundBuffer(
|
|
||||||
ChannelHandlerContext ctx) throws Exception {
|
|
||||||
return ChannelBufferHolders.byteBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void flush(ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
public void flush(ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
||||||
|
@ -21,9 +21,8 @@ import io.netty.channel.Channel;
|
|||||||
import io.netty.channel.ChannelBufferHolder;
|
import io.netty.channel.ChannelBufferHolder;
|
||||||
import io.netty.channel.ChannelBufferHolders;
|
import io.netty.channel.ChannelBufferHolders;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundHandler;
|
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.channel.ChannelStateHandlerAdapter;
|
|
||||||
import io.netty.util.internal.QueueFactory;
|
import io.netty.util.internal.QueueFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -70,8 +69,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*
|
*
|
||||||
* @param <E> the type of the received messages
|
* @param <E> the type of the received messages
|
||||||
*/
|
*/
|
||||||
public class BlockingReadHandler<E>
|
public class BlockingReadHandler<E> extends ChannelInboundMessageHandlerAdapter<Object> {
|
||||||
extends ChannelStateHandlerAdapter implements ChannelInboundHandler<Object> {
|
|
||||||
|
|
||||||
private static final Object INACTIVE = new Object();
|
private static final Object INACTIVE = new Object();
|
||||||
|
|
||||||
|
@ -16,18 +16,15 @@
|
|||||||
package io.netty.bootstrap;
|
package io.netty.bootstrap;
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelBufferHolder;
|
|
||||||
import io.netty.channel.ChannelBufferHolders;
|
|
||||||
import io.netty.channel.ChannelException;
|
import io.netty.channel.ChannelException;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundHandler;
|
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.channel.ChannelStateHandlerAdapter;
|
|
||||||
import io.netty.channel.EventLoop;
|
import io.netty.channel.EventLoop;
|
||||||
import io.netty.channel.ServerChannel;
|
import io.netty.channel.ServerChannel;
|
||||||
import io.netty.logging.InternalLogger;
|
import io.netty.logging.InternalLogger;
|
||||||
@ -231,13 +228,7 @@ public class ServerBootstrap {
|
|||||||
validate();
|
validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Acceptor extends ChannelStateHandlerAdapter implements ChannelInboundHandler<Channel> {
|
private class Acceptor extends ChannelInboundMessageHandlerAdapter<Channel> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChannelBufferHolder<Channel> newInboundBuffer(
|
|
||||||
ChannelHandlerContext ctx) throws Exception {
|
|
||||||
return ChannelBufferHolders.messageBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inboundBufferUpdated(ChannelHandlerContext ctx) {
|
public void inboundBufferUpdated(ChannelHandlerContext ctx) {
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class ChannelInboundHandlerAdapter<I> extends ChannelStateHandlerAdapter
|
||||||
|
implements ChannelInboundHandler<I> {
|
||||||
|
// Useful when you have to create an anonymous class
|
||||||
|
}
|
@ -17,8 +17,7 @@ package io.netty.channel;
|
|||||||
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
public class ChannelInboundMessageHandlerAdapter<I>
|
public class ChannelInboundMessageHandlerAdapter<I> extends ChannelInboundHandlerAdapter<I> {
|
||||||
extends ChannelStateHandlerAdapter implements ChannelInboundHandler<I> {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelBufferHolder<I> newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
|
public ChannelBufferHolder<I> newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
@ -18,8 +18,7 @@ package io.netty.channel;
|
|||||||
import io.netty.buffer.ChannelBuffer;
|
import io.netty.buffer.ChannelBuffer;
|
||||||
|
|
||||||
|
|
||||||
public class ChannelInboundStreamHandlerAdapter
|
public class ChannelInboundStreamHandlerAdapter extends ChannelInboundHandlerAdapter<Byte> {
|
||||||
extends ChannelStateHandlerAdapter implements ChannelInboundHandler<Byte> {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelBufferHolder<Byte> newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
|
public ChannelBufferHolder<Byte> newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class ChannelOutboundHandlerAdapter<O>
|
||||||
|
extends ChannelOperationHandlerAdapter implements ChannelOutboundHandler<O> {
|
||||||
|
// Useful when you have to create an anonymous class
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
|
||||||
|
public class ChannelOutboundMessageHandlerAdapter<I> extends ChannelOutboundHandlerAdapter<I> {
|
||||||
|
@Override
|
||||||
|
public ChannelBufferHolder<I> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
return ChannelBufferHolders.messageBuffer();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
public class ChannelOutboundStreamHandlerAdapter extends ChannelOutboundHandlerAdapter<Byte> {
|
||||||
|
@Override
|
||||||
|
public ChannelBufferHolder<Byte> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
return ChannelBufferHolders.byteBuffer();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,191 @@
|
|||||||
|
/*
|
||||||
|
* 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 java.net.SocketAddress;
|
||||||
|
|
||||||
|
public class CombinedChannelHandler
|
||||||
|
extends ChannelHandlerAdapter
|
||||||
|
implements ChannelInboundHandler<Object>, ChannelOutboundHandler<Object> {
|
||||||
|
|
||||||
|
private ChannelOutboundHandler<Object> out;
|
||||||
|
private ChannelInboundHandler<Object> in;
|
||||||
|
|
||||||
|
protected CombinedChannelHandler() {
|
||||||
|
// User will call init in the subclass constructor.
|
||||||
|
}
|
||||||
|
|
||||||
|
public CombinedChannelHandler(
|
||||||
|
ChannelInboundHandler<?> inboundHandler, ChannelOutboundHandler<?> outboundHandler) {
|
||||||
|
init(inboundHandler, outboundHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected void init(ChannelInboundHandler<?> inboundHandler,
|
||||||
|
ChannelOutboundHandler<?> outboundHandler) {
|
||||||
|
if (inboundHandler == null) {
|
||||||
|
throw new NullPointerException("inboundHandler");
|
||||||
|
}
|
||||||
|
if (outboundHandler == null) {
|
||||||
|
throw new NullPointerException("outboundHandler");
|
||||||
|
}
|
||||||
|
if (inboundHandler instanceof ChannelOperationHandler) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"inboundHandler must not implement " +
|
||||||
|
ChannelOperationHandler.class.getSimpleName() + " to get combined.");
|
||||||
|
}
|
||||||
|
if (outboundHandler instanceof ChannelStateHandler) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"outboundHandler must not implement " +
|
||||||
|
ChannelStateHandler.class.getSimpleName() + " to get combined.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (in != null) {
|
||||||
|
throw new IllegalStateException("init() cannot be called more than once.");
|
||||||
|
}
|
||||||
|
|
||||||
|
in = (ChannelInboundHandler<Object>) inboundHandler;
|
||||||
|
out = (ChannelOutboundHandler<Object>) outboundHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelBufferHolder<Object> newInboundBuffer(
|
||||||
|
ChannelHandlerContext ctx) throws Exception {
|
||||||
|
return in.newInboundBuffer(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelBufferHolder<Object> newOutboundBuffer(
|
||||||
|
ChannelHandlerContext ctx) throws Exception {
|
||||||
|
return out.newOutboundBuffer(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeAdd(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
if (in == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"not initialized yet - call init() in the constructor of the subclass");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
in.beforeAdd(ctx);
|
||||||
|
} finally {
|
||||||
|
out.beforeAdd(ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterAdd(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
try {
|
||||||
|
in.afterAdd(ctx);
|
||||||
|
} finally {
|
||||||
|
out.afterAdd(ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeRemove(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
try {
|
||||||
|
in.beforeRemove(ctx);
|
||||||
|
} finally {
|
||||||
|
out.beforeRemove(ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterRemove(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
try {
|
||||||
|
in.afterRemove(ctx);
|
||||||
|
} finally {
|
||||||
|
out.afterRemove(ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
in.channelRegistered(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
in.channelUnregistered(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
in.channelActive(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
in.channelInactive(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
|
in.exceptionCaught(ctx, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||||
|
in.userEventTriggered(ctx, evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
in.inboundBufferUpdated(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bind(
|
||||||
|
ChannelHandlerContext ctx,
|
||||||
|
SocketAddress localAddress, ChannelFuture future) throws Exception {
|
||||||
|
out.bind(ctx, localAddress, future);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connect(
|
||||||
|
ChannelHandlerContext ctx,
|
||||||
|
SocketAddress remoteAddress, SocketAddress localAddress,
|
||||||
|
ChannelFuture future) throws Exception {
|
||||||
|
out.connect(ctx, remoteAddress, localAddress, future);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnect(
|
||||||
|
ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
||||||
|
out.disconnect(ctx, future);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close(
|
||||||
|
ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
||||||
|
out.close(ctx, future);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deregister(
|
||||||
|
ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
||||||
|
out.deregister(ctx, future);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush(
|
||||||
|
ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
||||||
|
out.flush(ctx, future);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user