方法
|
说明
|
EventLoop eventLoop()
|
获得EventLoop实例,每一个Channel实例都会被注册到一个EventLoop中,这个EventLoop实例就是Channel注册的实例。
|
Channel parent()
|
获得父Channel实例。如: channelB = channelA.accept(), 那么channelA就是channelB的parent。
|
ChannelConfig config()
|
获得Channel实例的配置信息。
|
boolean isOpen()
|
channel是否处于open状态。netty为每一个channel定义了四种状态open->registered->active->closed。一个新建立的channel处于open状态,随后他被注册到一个eventloop中它处于open+registered状态,当这个channel上的链接创建成功后它处于open+registered+active状态,被关闭后处于closed状态。
|
boolean isRegistered()
|
channel是否处于registered状态。
|
boolean isActive()
|
channel是否处于active状态。
|
SocketAddress localAddress()
|
channel的本地bind的地址。
|
SocketAddress remoteAddress()
|
channel链接的远程channel的地址。
|
boolean isWritable()
|
channel的I/O线程是否能够当即执操做。
|
Unsafe unsafe()
|
获得channel内部的Unsafe实例。
|
ChannelPipeline pipeline()
|
获得channel内部的ChannelPipeline实例。
|
ByteBufAllocator alloc()
|
channel持有的buffer分配器。
|
方法
|
说明
|
ChannelFuture bind(SocketAddress localAddress)
ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise)
|
让channel绑定的指定的本地地址(localAddress)上。这个方法会触发ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)方法的调用。
|
ChannelFuture connect(SocketAddress remoteAddress)
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress)
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise)
|
链接到远程地址(remoteAddress), 这个方法会触发ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)方法的调用。
|
ChannelFuture disconnect()
ChannelFuture disconnect(ChannelPromise promise);
|
断开链接, 这个方法会触发ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)的调用。
|
ChannelFuture close()
ChannelFuture close(ChannelPromise promise)
|
关闭channel. 这个方法会触发ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)的调用。
|
ChannelFuture deregister()
ChannelFuture deregister(ChannelPromise promise)
|
从eventloop中注销这个channel,这个方法会触发ChannelOutboundHandler#deregister(ChannelHandlerContext, ChannelPromise)的调用。
|
ChannelFuture write(Object msg)
ChannelFuture write(Object msg, ChannelPromise promise)
|
向channel写入数据,这个操做不会致使真正写操做,只会把数据追加到输出缓冲区中。它会触发ChannelOutboundHandler#write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)调用。
|
Channel flush()
|
对输出缓冲区中的数据执行真正的写操做,调用这个方法后链接的另外一端才能收到write的数据,它会触发ChannelOutboundHandler#flush(ChannelHandlerContext ctx)调用。
|
ChannelFuture writeAndFlush(Object msg, ChannelPromise promise)
ChannelFuture writeAndFlush(Object msg)
|
效果和先调用write而后调用flush同样。
|
方法
|
说明
|
Channel read()
|
从channel中读取数据,把数据放到输入缓冲区中,而后触发ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)和ChannelInboundHandler#channelReadComplete(ChannelHandlerContext)调用,若是以前已经有一个read操做正在执行或等待执行,这个方法不会有任何影响。
|
方法
|
说明
|
SocketAddress localAddress()
|
同Channel
|
SocketAddress remoteAddress()
|
同Channel
|
void register(EventLoop eventLoop, ChannelPromise promise)
|
同Channel,
|
void bind(SocketAddress localAddress, ChannelPromise promise)
|
同Channel, 必须在I/O线程中执行
|
void connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise)
|
同Channel, 必须在I/O线程中执行
|
void disconnect(ChannelPromise promise)
|
同Channel, 必须在I/O线程中执行
|
void close(ChannelPromise promise)
|
同Channel, 必须在I/O线程中执行
|
void closeForcibly()
|
当即关闭channel,而且不触发任何事件。
|
void deregister(ChannelPromise promise)
|
同Channel, 必须在I/O线程中执行
|
void beginRead()
|
为channel触发read事件作准备。如:把read事件注册到NIO 的selector上。 必须在I/O线程中执行 必须在I/O线程中执行
|
void write(Object msg, ChannelPromise promise)
|
同Channel, 必须在I/O线程中执行
|
void flush()
|
同Channel, 必须在I/O线程中执行
|
ChannelOutboundBuffer outboundBuffer()
|
获得channel的输出缓冲区,write的数据就是追加到这个缓冲区中。 必须在I/O线程中执行
|