标签:tee 定义 tty 指南 creat ret 状态 outbound triggers
A nexus to a network socket or a component which is capable of I/O operations such as read, write, connect, and bind.
【连接到网络socket或组件的连接,它能够进行I/O操作,如读、写、连接和绑定。】
A channel provides a user: 【一个channel 能提供:】
All I/O operations in Netty are asynchronous. 【所有的 I/O 操作在netty中都是异步的】
It means any I/O calls will return immediately with no guarantee that the requested I/O operation has been completed at the end of the call. 【这意味着任何I/O调用都会立即返回,不能保证请求的I/O操作在调用结束时完成】
Instead, you will be returned with a ChannelFuture instance which will notify you when the requested I/O operation has succeeded, failed, or canceled.【相反,会返回一个ChannelFuture 对象,它会在I/O操作成功、失败、取消时通知你】
A Channel can have a parent depending on how it was created.【谁创建了它,谁就是它的父channel】
For instance, a SocketChannel, that was accepted by ServerSocketChannel, will return the ServerSocketChannel as its parent on parent().【例如,ServerSocketChannel通过accept()方法接受一个SocketChannel后,调用SocketChannel的 parent()会返回 ServerSocketChannel对象】
The semantics of the hierarchical structure depends on the transport implementation where the Channel belongs to. 【层次结构的语义取决于通道所属的Channel实现】
For example, you could write a new Channel implementation that creates the sub-channels that share one socket connection, as BEEP and SSH do.【例如,你可以编写一个新的Channel实现,它创建一个子Channel,它与父Channel共享一个socket的内存,例如BEEP和 SSH do】
Some transports exposes additional operations that is specific to the transport. 【某些子类传输会提供一些特定的操作】
Down-cast the Channel to sub-type to invoke such operations.【向下转型成子类传输以获得这些操作】
For example, with the old I/O datagram transport, multicast join / leave operations are provided by DatagramChannel.【例如,UDP传输有特定的 jion() 和 leave() 操作,可以向下转型成 DatagramChannel获得这些操作】
It is important to call close() or close(ChannelPromise) to release all resources once you are done with the Channel. 【一旦你使用完Channel,必须调用 close() 或 close(ChannelPromise)方法释放一些重要的资源】
This ensures all resources are released in a proper way, i.e. filehandles.【确保这些资源以一个适当的方式释放,比如文件句柄】
1 public interface Channel extends AttributeMap, ChannelOutboundInvoker, Comparable<Channel>
public interface ChannelOutboundInvoker { //绑定本地地址 ChannelFuture bind(SocketAddress localAddress); ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise); //连接远程地址 ChannelFuture connect(SocketAddress remoteAddress); ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise); ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress); ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise); //解除连接 ChannelFuture disconnect(); ChannelFuture disconnect(ChannelPromise promise); //关闭Channel ChannelFuture close(); ChannelFuture close(ChannelPromise promise); //与EventLoop解除注册 ChannelFuture deregister(); ChannelFuture deregister(ChannelPromise promise); /** * Request to Read data from the {@link Channel} into the first inbound buffer, * triggers an {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)} event if data was read, * and triggers a {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext) channelReadComplete} event so the * handler can decide to continue reading. If there‘s a pending read operation already, this method does nothing. * This will result in having the * {@link ChannelOutboundHandler#read(ChannelHandlerContext)} * method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * {@link Channel}. */ /** * 从channel中读取数据到第一个 InboundBuffer, * 1、触发 ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)事件,在有数据的情况下 * 2、触发ChannelInboundHandler#channelReadComplete(ChannelHandlerContext)事件,handler继续读取 * 如果有read操作已经挂起,则不执行任何操作 * 实际调用:Channel——>ChannelPipeline——>ChannelOutboundHandler——>ChannelOutboundHandler#read(ChannelHandlerContext)——>read() * ChannelHandlerContext继承了ChannelOutboundInvoker,它的子类实现read()方法,最后ctx.read()。 * */ ChannelOutboundInvoker read(); //写 ChannelFuture write(Object msg); ChannelFuture write(Object msg, ChannelPromise promise); //将数据冲刷到Channel ChannelOutboundInvoker flush(); //write + flush ChannelFuture writeAndFlush(Object msg); ChannelFuture writeAndFlush(Object msg, ChannelPromise promise); ChannelPromise newPromise(); ChannelProgressivePromise newProgressivePromise(); ChannelFuture newSucceededFuture(); ChannelFuture newFailedFuture(Throwable cause); ChannelPromise voidPromise(); }
public interface Channel extends AttributeMap, ChannelOutboundInvoker, Comparable<Channel> { //get属性 ChannelId id(); //获得一个唯一的channelId EventLoop eventLoop();//获得关联的EventLoop Channel parent();//父Channel ChannelConfig config();//获得配置参数 ChannelMetadata metadata();//获得元数据 SocketAddress localAddress();//获得本地地址 SocketAddress remoteAddress();//获得远端地址 ChannelFuture closeFuture();//获得Channel关闭时的异步结果 ChannelPipeline pipeline();//获得事件管道,用于处理IO事件 ByteBufAllocator alloc();//获得字节缓存分配器 Unsafe unsafe();//获得Unsafe对象 //状态查询 boolean isOpen();//是否开放 boolean isRegistered();// 是否注册到一个EventLoop boolean isActive();// 是否激活 boolean isWritable();// 是否可写 long bytesBeforeUnwritable(); long bytesBeforeWritable(); @Override Channel read(); @Override Channel flush(); }
public interface Channel extends AttributeMap, ChannelOutboundInvoker, Comparable<Channel> { .... interface Unsafe { RecvByteBufAllocator.Handle recvBufAllocHandle();//当接受数据时返回它,用于分配ByteBuf SocketAddress localAddress(); SocketAddress remoteAddress(); void register(EventLoop eventLoop, ChannelPromise promise); void deregister(ChannelPromise promise); void bind(SocketAddress localAddress, ChannelPromise promise); void connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise); void disconnect(ChannelPromise promise); void close(ChannelPromise promise); void closeForcibly();//当注册失败时强制关闭连接 void beginRead(); void write(Object msg, ChannelPromise promise); void flush(); ChannelPromise voidPromise();//返回一个特殊的可重用的ChannelPromise,它仅作为一个容器不用于操作成功或失败的通知器 ChannelOutboundBuffer outboundBuffer();//返回消息发送缓冲区 } }
标签:tee 定义 tty 指南 creat ret 状态 outbound triggers
原文地址:http://www.cnblogs.com/chenzl1024/p/7256847.html