Move ChannelBufferType to netty-buffers and rename it to ChannelBufType

- Also add ChannelBuf.type()
This commit is contained in:
Trustin Lee 2012-06-12 17:05:28 +09:00
parent ecd0ae5406
commit 3b562c917d
17 changed files with 58 additions and 28 deletions

View File

@ -51,6 +51,11 @@ public abstract class AbstractByteBuf implements ByteBuf {
return false; return false;
} }
@Override
public ChannelBufType type() {
return ChannelBufType.BYTE;
}
@Override @Override
public int readerIndex() { public int readerIndex() {
return readerIndex; return readerIndex;

View File

@ -16,5 +16,6 @@
package io.netty.buffer; package io.netty.buffer;
public interface ChannelBuf { public interface ChannelBuf {
ChannelBufType type();
boolean isPooled(); boolean isPooled();
} }

View File

@ -13,9 +13,9 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.channel; package io.netty.buffer;
public enum ChannelBufferType { public enum ChannelBufType {
BYTE, BYTE,
MESSAGE MESSAGE
} }

View File

@ -37,6 +37,11 @@ public class DefaultMessageBuf<T> extends ArrayDeque<T> implements MessageBuf<T>
return false; return false;
} }
@Override
public ChannelBufType type() {
return ChannelBufType.MESSAGE;
}
@Override @Override
public int drainTo(Collection<? super T> c) { public int drainTo(Collection<? super T> c) {
int cnt = 0; int cnt = 0;

View File

@ -35,6 +35,11 @@ public class QueueBackedMessageBuf<T> implements MessageBuf<T> {
return false; return false;
} }
@Override
public ChannelBufType type() {
return ChannelBufType.MESSAGE;
}
@Override @Override
public boolean add(T e) { public boolean add(T e) {
return queue.add(e); return queue.add(e);

View File

@ -67,6 +67,11 @@ public class SwappedByteBuf implements WrappedByteBuf {
return buf.isPooled(); return buf.isPooled();
} }
@Override
public ChannelBufType type() {
return ChannelBufType.MESSAGE;
}
@Override @Override
public ByteBufFactory factory() { public ByteBufFactory factory() {
return buf.factory(); return buf.factory();

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufFactory; import io.netty.buffer.ByteBufFactory;
import io.netty.buffer.ByteBufIndexFinder; import io.netty.buffer.ByteBufIndexFinder;
import io.netty.buffer.ChannelBufType;
import io.netty.buffer.SwappedByteBuf; import io.netty.buffer.SwappedByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.util.Signal; import io.netty.util.Signal;
@ -63,6 +64,11 @@ class ReplayingDecoderBuffer implements ByteBuf {
} }
} }
@Override
public ChannelBufType type() {
return ChannelBufType.BYTE;
}
@Override @Override
public boolean isPooled() { public boolean isPooled() {
return false; return false;

View File

@ -16,6 +16,7 @@
package io.netty.channel; package io.netty.channel;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ChannelBufType;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import java.net.SocketAddress; import java.net.SocketAddress;
@ -51,8 +52,8 @@ public abstract class AbstractServerChannel extends AbstractChannel implements S
} }
@Override @Override
public ChannelBufferType bufferType() { public ChannelBufType bufferType() {
return ChannelBufferType.MESSAGE; return ChannelBufType.MESSAGE;
} }
@Override @Override

View File

@ -16,6 +16,7 @@
package io.netty.channel; package io.netty.channel;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ChannelBufType;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.ServerSocketChannel; import io.netty.channel.socket.ServerSocketChannel;
@ -138,7 +139,7 @@ public interface Channel extends AttributeMap, ChannelOutboundInvoker, ChannelFu
boolean isRegistered(); boolean isRegistered();
boolean isActive(); boolean isActive();
ChannelBufferType bufferType(); ChannelBufType bufferType();
ByteBuf outboundByteBuffer(); ByteBuf outboundByteBuffer();
<T> MessageBuf<T> outboundMessageBuffer(); <T> MessageBuf<T> outboundMessageBuffer();

View File

@ -18,6 +18,7 @@ package io.netty.channel;
import static io.netty.channel.DefaultChannelHandlerContext.*; import static io.netty.channel.DefaultChannelHandlerContext.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ChannelBuf; import io.netty.buffer.ChannelBuf;
import io.netty.buffer.ChannelBufType;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.DefaultChannelHandlerContext.ByteBridge; import io.netty.channel.DefaultChannelHandlerContext.ByteBridge;
@ -886,7 +887,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
@Override @Override
public MessageBuf<Object> inboundMessageBuffer() { public MessageBuf<Object> inboundMessageBuffer() {
if (channel.bufferType() != ChannelBufferType.MESSAGE) { if (channel.bufferType() != ChannelBufType.MESSAGE) {
throw new NoSuchBufferException( throw new NoSuchBufferException(
"The first inbound buffer of this channel must be a message buffer."); "The first inbound buffer of this channel must be a message buffer.");
} }
@ -895,7 +896,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
@Override @Override
public ByteBuf inboundByteBuffer() { public ByteBuf inboundByteBuffer() {
if (channel.bufferType() != ChannelBufferType.BYTE) { if (channel.bufferType() != ChannelBufType.BYTE) {
throw new NoSuchBufferException( throw new NoSuchBufferException(
"The first inbound buffer of this channel must be a byte buffer."); "The first inbound buffer of this channel must be a byte buffer.");
} }

View File

@ -16,8 +16,8 @@
package io.netty.channel.embedded; package io.netty.channel.embedded;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ChannelBufType;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelBufferType;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
public class EmbeddedByteChannel extends AbstractEmbeddedChannel { public class EmbeddedByteChannel extends AbstractEmbeddedChannel {
@ -27,8 +27,8 @@ public class EmbeddedByteChannel extends AbstractEmbeddedChannel {
} }
@Override @Override
public ChannelBufferType bufferType() { public ChannelBufType bufferType() {
return ChannelBufferType.BYTE; return ChannelBufType.BYTE;
} }
public ByteBuf inboundBuffer() { public ByteBuf inboundBuffer() {

View File

@ -15,8 +15,8 @@
*/ */
package io.netty.channel.embedded; package io.netty.channel.embedded;
import io.netty.buffer.ChannelBufType;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.channel.ChannelBufferType;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import java.util.ArrayDeque; import java.util.ArrayDeque;
@ -28,8 +28,8 @@ public class EmbeddedMessageChannel extends AbstractEmbeddedChannel {
} }
@Override @Override
public ChannelBufferType bufferType() { public ChannelBufType bufferType() {
return ChannelBufferType.MESSAGE; return ChannelBufType.MESSAGE;
} }
public MessageBuf<Object> inboundBuffer() { public MessageBuf<Object> inboundBuffer() {

View File

@ -15,10 +15,10 @@
*/ */
package io.netty.channel.local; package io.netty.channel.local;
import io.netty.buffer.ChannelBufType;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.channel.AbstractChannel; import io.netty.channel.AbstractChannel;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelBufferType;
import io.netty.channel.ChannelConfig; import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
@ -68,8 +68,8 @@ public class LocalChannel extends AbstractChannel {
} }
@Override @Override
public ChannelBufferType bufferType() { public ChannelBufType bufferType() {
return ChannelBufferType.MESSAGE; return ChannelBufType.MESSAGE;
} }
@Override @Override

View File

@ -16,8 +16,8 @@
package io.netty.channel.socket.nio; package io.netty.channel.socket.nio;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ChannelBufType;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelBufferType;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import java.io.IOException; import java.io.IOException;
@ -32,8 +32,8 @@ abstract class AbstractNioByteChannel extends AbstractNioChannel {
} }
@Override @Override
public ChannelBufferType bufferType() { public ChannelBufType bufferType() {
return ChannelBufferType.BYTE; return ChannelBufType.BYTE;
} }
@Override @Override

View File

@ -15,9 +15,9 @@
*/ */
package io.netty.channel.socket.nio; package io.netty.channel.socket.nio;
import io.netty.buffer.ChannelBufType;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelBufferType;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import java.io.IOException; import java.io.IOException;
@ -31,8 +31,8 @@ abstract class AbstractNioMessageChannel extends AbstractNioChannel {
} }
@Override @Override
public ChannelBufferType bufferType() { public ChannelBufType bufferType() {
return ChannelBufferType.MESSAGE; return ChannelBufType.MESSAGE;
} }
@Override @Override

View File

@ -16,8 +16,8 @@
package io.netty.channel.socket.oio; package io.netty.channel.socket.oio;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ChannelBufType;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelBufferType;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import java.io.IOException; import java.io.IOException;
@ -29,8 +29,8 @@ abstract class AbstractOioByteChannel extends AbstractOioChannel {
} }
@Override @Override
public ChannelBufferType bufferType() { public ChannelBufType bufferType() {
return ChannelBufferType.BYTE; return ChannelBufType.BYTE;
} }
@Override @Override

View File

@ -15,9 +15,9 @@
*/ */
package io.netty.channel.socket.oio; package io.netty.channel.socket.oio;
import io.netty.buffer.ChannelBufType;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelBufferType;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import java.io.IOException; import java.io.IOException;
@ -29,8 +29,8 @@ abstract class AbstractOioMessageChannel extends AbstractOioChannel {
} }
@Override @Override
public ChannelBufferType bufferType() { public ChannelBufType bufferType() {
return ChannelBufferType.MESSAGE; return ChannelBufType.MESSAGE;
} }
@Override @Override