diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 00000000..9d922a1c
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,24 @@
+version: 2
+updates:
+- package-ecosystem: maven
+ directory: "/"
+ schedule:
+ interval: daily
+ open-pull-requests-limit: 10
+ ignore:
+ - dependency-name: com.google.protobuf:protobuf-java
+ versions:
+ - 3.14.0
+ - 3.15.0
+ - 3.15.1
+ - 3.15.2
+ - 3.15.3
+ - 3.15.4
+ - 3.15.5
+ - 3.15.6
+ - 3.15.7
+ - dependency-name: io.netty:netty-all
+ versions:
+ - 4.1.59.Final
+ - 4.1.60.Final
+ - 4.1.62.Final
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 00000000..94249a90
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,19 @@
+language: java
+
+sudo: false
+
+jdk:
+ - oraclejdk8
+
+before_cache:
+ - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
+ - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
+
+cache:
+ directories:
+ - $HOME/.gradle/caches/
+ - $HOME/.gradle/wrapper/
+
+script:
+ # need to override as the default is to test
+ - mvn test -B
\ No newline at end of file
diff --git a/README.md b/README.md
index 6cf98462..2a7eee0b 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,66 @@
-This Repository contains the source-code for all chapters of the book [Netty in Action](http://manning.com/maurer)
-by Norman Maurer and Marvin Allen Wolfthal.
+# 《Netty 实战》 Netty In Action 中文版
-Latest version: https://github.com/normanmaurer/netty-in-action/tree/2.0-SNAPSHOT
+>代码清单已经更新到 Netty 4.1.25.final
-Enjoy! Feedback and PR's welcome!
+[如何评价这本书-知乎](https://www.zhihu.com/question/58838575)
+[关于本书-豆瓣](https://book.douban.com/subject/27038538/)
+
+[京东链接(现货发售):《Netty实战》([美]诺曼·毛瑞尔(Norman Maurer),马文·艾伦·沃尔夫泰尔(Marvin Allen Wolfthal)) ](https://union-click.jd.com/jdc?d=oN4CCW&come=appmessage)
+
+[不负好时光《Netty IN ACTION》中文版《Netty实战》翻译手记](http://www.epubit.com.cn/article/1171)
+
+[不负好时光《Netty IN ACTION》中文版《Netty实战》翻译手记(ATA内网)](https://www.atatech.org/articles/79051?flag_data_from=recommend)
+
+![image](https://cloud.githubusercontent.com/assets/501740/25295296/94d2ef06-2715-11e7-9a2a-916d77014cfc.png)
+
+
+## 内容提要
+
+本书是为想要或者正在使用 Java 从事高性能网络编程的人而写的,循序渐进地介绍了 Netty
+各个方面的内容。
+
+本书共分为 4 个部分:第一部分详细地介绍 Netty 的相关概念以及核心组件,第二部分介绍
+自定义协议经常用到的编解码器,第三部分介绍 Netty 对于应用层高级协议的支持,会覆盖常见
+的协议及其在实践中的应用,第四部分是几个案例研究。此外,附录部分还会简单地介绍 Maven,
+以及如何通过使用 Maven 编译和运行本书中的示例。
+
+阅读本书不需要读者精通 Java 网络和并发编程。如果想要更加深入地理解本书背后的理念
+以及 Netty 源码本身,可以系统地学习一下 Java 网络编程、 NIO、并发和异步编程以及相关的
+设计模式。
+
+## 说明
+
+这个仓库包含了[Netty In Action](http://www.manning.com/maurer/) 这本书的中文版 [Netty实战](http://www.epubit.com.cn) 的代码清单.
+为了更好地服务于读者,进行了如下方面的改进.
-Prerequisites
- JDK 1.7.0u71 or better
+相对于英文版本([2.0-SNAPSHOT](https://github.com/ReactivePlatform/netty-in-action-cn/tree/2.0-SNAPSHOT)分支):
+
+1. 更新了行文中的注释
+2. 按照中文版本的排版进行了调整
+3. 所有的代码清单以及跳转都使用了中文版书籍中的翻译
+
+
+## 反馈
+
+上游版本的更新,请直接将PR的目标调整为本仓库的`master`分支
+
+中文版本的更新,请将PR的目标调整为本仓库的`ChineseVersion`分支
+
+## 使用
+
+请直接克隆本项目即可,建议对照原文查看代码.
+
+## 勘误
+[前言: 2001 => 2011](https://github.com/ReactivePlatform/netty-in-action-cn/issues/2)
+
+-----
+
+Prerequisites
- Maven 3.2.3 or better
+ maven 3.3.9
+ JDK 8
If you want to build everything at once, from the top directory run
diff --git a/chapter1/src/main/java/nia/chapter1/BlockingIoExample.java b/chapter1/src/main/java/nia/chapter1/BlockingIoExample.java
index 1be636a5..bd2d002f 100644
--- a/chapter1/src/main/java/nia/chapter1/BlockingIoExample.java
+++ b/chapter1/src/main/java/nia/chapter1/BlockingIoExample.java
@@ -10,24 +10,35 @@
/**
* Created by kerr.
*
- * Listing 1.1 Blocking I/O example
+ * 代码清单 1-1 阻塞 I/O 示例
*/
public class BlockingIoExample {
+
+ /**
+ * 代码清单 1-1 阻塞 I/O 示例
+ * */
public void serve(int portNumber) throws IOException {
+ //创建一个新的 ServerSocket,用以监听指定端口上的连接请求
ServerSocket serverSocket = new ServerSocket(portNumber);
+ //对accept()方法的调用将被阻塞,直到一个连接建立
Socket clientSocket = serverSocket.accept();
+ //这些流对象都派生于该套接字的流对象
BufferedReader in = new BufferedReader(
new InputStreamReader(clientSocket.getInputStream()));
PrintWriter out =
new PrintWriter(clientSocket.getOutputStream(), true);
String request, response;
+ //处理循环开始
while ((request = in.readLine()) != null) {
if ("Done".equals(request)) {
break;
}
+ //请求被传递给服务器的处理方法
+ response = processRequest(request);
+ //服务器的响应被发送给了客户端
+ out.println(response);
+ //继续执行处理循环
}
- response = processRequest(request);
- out.println(response);
}
private String processRequest(String request){
diff --git a/chapter1/src/main/java/nia/chapter1/ConnectExample.java b/chapter1/src/main/java/nia/chapter1/ConnectExample.java
index 8f41b7cc..9108c7c3 100644
--- a/chapter1/src/main/java/nia/chapter1/ConnectExample.java
+++ b/chapter1/src/main/java/nia/chapter1/ConnectExample.java
@@ -5,6 +5,7 @@
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.socket.nio.NioSocketChannel;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
@@ -12,30 +13,43 @@
/**
* Created by kerr.
*
- * Listing 1.3 Asynchronous connect
- * Listing 1.4 Callback in action
+ * 代码清单 1-3 异步地建立连接
+ *
+ * 代码清单 1-4 回调实战
*/
public class ConnectExample {
+ private static final Channel CHANNEL_FROM_SOMEWHERE = new NioSocketChannel();
- public static void connect(Channel channel) {
+ /**
+ * 代码清单 1-3 异步地建立连接
+ *
+ * 代码清单 1-4 回调实战
+ * */
+ public static void connect() {
+ Channel channel = CHANNEL_FROM_SOMEWHERE; //reference form somewhere
// Does not block
+ //异步地连接到远程节点
ChannelFuture future = channel.connect(
new InetSocketAddress("192.168.0.1", 25));
+ //注册一个 ChannelFutureListener,以便在操作完成时获得通知
future.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
+ //检查操作的状态
if (future.isSuccess()) {
+ //如果操作是成功的,则创建一个 ByteBuf 以持有数据
ByteBuf buffer = Unpooled.copiedBuffer(
"Hello", Charset.defaultCharset());
+ //将数据异步地发送到远程节点。返回一个 ChannelFuture
ChannelFuture wf = future.channel()
.writeAndFlush(buffer);
// ...
} else {
+ //如果发生错误,则访问描述原因的 Throwable
Throwable cause = future.cause();
cause.printStackTrace();
}
}
});
-
}
}
\ No newline at end of file
diff --git a/chapter1/src/main/java/nia/chapter1/ConnectHandler.java b/chapter1/src/main/java/nia/chapter1/ConnectHandler.java
index 01313d78..2e04d547 100644
--- a/chapter1/src/main/java/nia/chapter1/ConnectHandler.java
+++ b/chapter1/src/main/java/nia/chapter1/ConnectHandler.java
@@ -6,10 +6,11 @@
/**
* Created by kerr.
*
- * Listing 1.2 ChannelHandler triggered by a callback
+ * 代码清单 1-2 被回调触发的 ChannelHandler
*/
public class ConnectHandler extends ChannelInboundHandlerAdapter {
@Override
+ //当一个新的连接已经被建立时,channelActive(ChannelHandlerContext)将会被调用
public void channelActive(ChannelHandlerContext ctx)
throws Exception {
System.out.println(
diff --git a/chapter1/src/main/java/nia/chapter1/package-info.java b/chapter1/src/main/java/nia/chapter1/package-info.java
index d16877da..66a62fd1 100644
--- a/chapter1/src/main/java/nia/chapter1/package-info.java
+++ b/chapter1/src/main/java/nia/chapter1/package-info.java
@@ -1,12 +1,12 @@
/**
* kerr.
*
- * Listing 1.1 Blocking I/O example {@link nia.chapter1.BlockingIoExample#serve(int)}
+ * 代码清单 1-1 阻塞 I/O 示例 {@link nia.chapter1.BlockingIoExample#serve(int)}
*
- * Listing 1.2 ChannelHandler triggered by a callback {@link nia.chapter1.ConnectHandler}
+ * 代码清单 1-2 被回调触发的 ChannelHandler {@link nia.chapter1.ConnectHandler}
*
- * Listing 1.3 Asynchronous connect {@link nia.chapter1.ConnectExample#connect(io.netty.channel.Channel)}
+ * 代码清单 1-3 异步地建立连接 {@link nia.chapter1.ConnectExample#connect()}
*
- * Listing 1.4 Callback in action {@link nia.chapter1.ConnectExample#connect(io.netty.channel.Channel)}
+ * 代码清单 1-4 回调实战 {@link nia.chapter1.ConnectExample#connect()}
*/
package nia.chapter1;
\ No newline at end of file
diff --git a/chapter10/src/main/java/nia/chapter10/ByteToCharDecoder.java b/chapter10/src/main/java/nia/chapter10/ByteToCharDecoder.java
index 6a9793f9..2f4618e4 100644
--- a/chapter10/src/main/java/nia/chapter10/ByteToCharDecoder.java
+++ b/chapter10/src/main/java/nia/chapter10/ByteToCharDecoder.java
@@ -7,15 +7,17 @@
import java.util.List;
/**
- * Listing 10.8 Class ByteToCharDecoder
+ * 代码清单 10-8 ByteToCharDecoder 类
*
* @author Norman Maurer
*/
+//扩展了ByteToMessageDecoder
public class ByteToCharDecoder extends ByteToMessageDecoder {
@Override
public void decode(ChannelHandlerContext ctx, ByteBuf in,
List