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;
}
@Override
public ChannelBufType type() {
return ChannelBufType.BYTE;
}
@Override
public int readerIndex() {
return readerIndex;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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