Skip to content

Commit

Permalink
Move ChannelBufferType to netty-buffers and rename it to ChannelBufType
Browse files Browse the repository at this point in the history
- Also add ChannelBuf.type()
  • Loading branch information
trustin committed Jun 12, 2012
1 parent ecd0ae5 commit 3b562c9
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 28 deletions.
5 changes: 5 additions & 0 deletions buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public boolean isPooled() {
return false;
}

@Override
public ChannelBufType type() {
return ChannelBufType.BYTE;
}

@Override
public int readerIndex() {
return readerIndex;
Expand Down
1 change: 1 addition & 0 deletions buffer/src/main/java/io/netty/buffer/ChannelBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
package io.netty.buffer;

public interface ChannelBuf {
ChannelBufType type();
boolean isPooled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions buffer/src/main/java/io/netty/buffer/DefaultMessageBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public boolean isPooled() {
return false;
}

@Override
public ChannelBufType type() {
return ChannelBufType.MESSAGE;
}

@Override
public int drainTo(Collection<? super T> c) {
int cnt = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public boolean isPooled() {
return false;
}

@Override
public ChannelBufType type() {
return ChannelBufType.MESSAGE;
}

@Override
public boolean add(T e) {
return queue.add(e);
Expand Down
5 changes: 5 additions & 0 deletions buffer/src/main/java/io/netty/buffer/SwappedByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public boolean isPooled() {
return buf.isPooled();
}

@Override
public ChannelBufType type() {
return ChannelBufType.MESSAGE;
}

@Override
public ByteBufFactory factory() {
return buf.factory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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;
Expand Down Expand Up @@ -63,6 +64,11 @@ public int capacity() {
}
}

@Override
public ChannelBufType type() {
return ChannelBufType.BYTE;
}

@Override
public boolean isPooled() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,8 +52,8 @@ public MessageBuf<Object> outboundMessageBuffer() {
}

@Override
public ChannelBufferType bufferType() {
return ChannelBufferType.MESSAGE;
public ChannelBufType bufferType() {
return ChannelBufType.MESSAGE;
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion transport/src/main/java/io/netty/channel/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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;
Expand Down Expand Up @@ -886,7 +887,7 @@ public String toString() {

@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.");
}
Expand All @@ -895,7 +896,7 @@ public MessageBuf<Object> inboundMessageBuffer() {

@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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,8 +27,8 @@ public EmbeddedByteChannel(ChannelHandler... handlers) {
}

@Override
public ChannelBufferType bufferType() {
return ChannelBufferType.BYTE;
public ChannelBufType bufferType() {
return ChannelBufType.BYTE;
}

public ByteBuf inboundBuffer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,8 +28,8 @@ public EmbeddedMessageChannel(ChannelHandler... handlers) {
}

@Override
public ChannelBufferType bufferType() {
return ChannelBufferType.MESSAGE;
public ChannelBufType bufferType() {
return ChannelBufType.MESSAGE;
}

public MessageBuf<Object> inboundBuffer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,8 +68,8 @@ public LocalChannel(Integer id) {
}

@Override
public ChannelBufferType bufferType() {
return ChannelBufferType.MESSAGE;
public ChannelBufType bufferType() {
return ChannelBufType.MESSAGE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,8 +32,8 @@ protected AbstractNioByteChannel(
}

@Override
public ChannelBufferType bufferType() {
return ChannelBufferType.BYTE;
public ChannelBufType bufferType() {
return ChannelBufType.BYTE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,8 +31,8 @@ protected AbstractNioMessageChannel(
}

@Override
public ChannelBufferType bufferType() {
return ChannelBufferType.MESSAGE;
public ChannelBufType bufferType() {
return ChannelBufType.MESSAGE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,8 +29,8 @@ protected AbstractOioByteChannel(Channel parent, Integer id) {
}

@Override
public ChannelBufferType bufferType() {
return ChannelBufferType.BYTE;
public ChannelBufType bufferType() {
return ChannelBufType.BYTE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,8 +29,8 @@ protected AbstractOioMessageChannel(Channel parent, Integer id) {
}

@Override
public ChannelBufferType bufferType() {
return ChannelBufferType.MESSAGE;
public ChannelBufType bufferType() {
return ChannelBufType.MESSAGE;
}

@Override
Expand Down

0 comments on commit 3b562c9

Please sign in to comment.