* Code clean up

* Codec embedded now supports multiple handler combinations
This commit is contained in:
Trustin Lee 2008-12-03 08:28:50 +00:00
parent 2bf7467726
commit e659482215
3 changed files with 21 additions and 11 deletions

View File

@ -47,22 +47,32 @@ import org.jboss.netty.channel.MessageEvent;
*/
abstract class AbstractCodecEmbedder<T> implements CodecEmbedder<T> {
private static final String NAME = "__embedded__";
private final Channel channel;
private final ChannelPipeline pipeline;
private final EmbeddedChannelSink sink = new EmbeddedChannelSink();
final Queue<Object> productQueue = new LinkedList<Object>();
AbstractCodecEmbedder(ChannelHandler handler) {
if (handler == null) {
throw new NullPointerException("handler");
AbstractCodecEmbedder(ChannelHandler... handlers) {
if (handlers == null) {
throw new NullPointerException("handlers");
}
if (handlers.length == 0) {
throw new IllegalArgumentException(
"handlers should contain at least one " +
ChannelHandler.class.getSimpleName() + '.');
}
pipeline = Channels.pipeline();
pipeline.addLast(NAME, handler);
pipeline.addLast("LAST", sink);
for (int i = 0; i < handlers.length; i ++) {
ChannelHandler h = handlers[i];
if (h == null) {
throw new NullPointerException("handlers[" + i + "]");
}
pipeline.addLast(String.valueOf(i), handlers[i]);
}
pipeline.addLast("SINK", sink);
channel = new EmbeddedChannel(pipeline, sink);
// Fire the typical initial events.

View File

@ -33,8 +33,8 @@ import org.jboss.netty.channel.ChannelUpstreamHandler;
*/
public class DecoderEmbedder<T> extends AbstractCodecEmbedder<T> {
public DecoderEmbedder(ChannelUpstreamHandler handler) {
super(handler);
public DecoderEmbedder(ChannelUpstreamHandler... handlers) {
super(handlers);
}
public boolean offer(Object input) {

View File

@ -33,8 +33,8 @@ import org.jboss.netty.channel.ChannelDownstreamHandler;
*/
public class EncoderEmbedder<T> extends AbstractCodecEmbedder<T> {
public EncoderEmbedder(ChannelDownstreamHandler handler) {
super(handler);
public EncoderEmbedder(ChannelDownstreamHandler... handlers) {
super(handlers);
}
public boolean offer(Object input) {