Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4302d83

Browse files
committed
completed 运行 LogEventBroadcaster 和 LogEventMonitor
1 parent 2503df6 commit 4302d83

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
运行 LogEventBroadcaster 和 LogEventMonitor
2+
====
3+
4+
如上所述,我们将使用 Maven 来运行应用程序。这一次你需要打开两个控制台窗口给每个项目。用 Ctrl-C 可以停止它。
5+
6+
首先我们将启动 LogEventBroadcaster 如清单13.4所示,除了已经构建项目以下命令即可(使用默认值):
7+
8+
$ mvn exec:exec -Pchapter13-LogEventBroadcaster
9+
10+
和之前一样,这将通过 UDP 广播日志消息。
11+
12+
现在,在一个新窗口,构建和启动 LogEventMonitor 接收和显示广播消息。
13+
14+
Listing 13.9 Compile and start the LogEventBroadcaster
15+
16+
$ mvn clean package exec:exec -Pchapter13-LogEventMonitor
17+
[INFO] Scanning for projects...
18+
[INFO]
19+
[INFO] --------------------------------------------------------------------
20+
[INFO] Building netty-in-action 0.1-SNAPSHOT
21+
[INFO] --------------------------------------------------------------------
22+
...
23+
[INFO]
24+
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ netty-in-action ---
25+
[INFO] Building jar: /Users/norman/Documents/workspace-intellij/netty-in-actionprivate/
26+
target/netty-in-action-0.1-SNAPSHOT.jar
27+
[INFO]
28+
[INFO] --- exec-maven-plugin:1.2.1:exec (default-cli) @ netty-in-action ---
29+
LogEventMonitor running
30+
31+
当看到 "LogEventMonitor running" 说明程序运行成功了。
32+
33+
控制台将显示任何事件被添加到日志文件中,如下所示。消息的格式是由LogEventHandler 创建。
34+
35+
Listing 13.10 LogEventMonitor output
36+
37+
1364217299382 [/192.168.0.38:63182] [/var/log/messages] : Mar 25 13:55:08 dev-linux
38+
dhclient: DHCPREQUEST of 192.168.0.50 on eth2 to 192.168.0.254 port 67
39+
1364217299382 [/192.168.0.38:63182] [/var/log/messages] : Mar 25 13:55:08 dev-linux
40+
dhclient: DHCPACK of 192.168.0.50 from 192.168.0.254
41+
1364217299382 [/192.168.0.38:63182] [/var/log/messages] : Mar 25 13:55:08 dev-linux
42+
dhclient: bound to 192.168.0.50 -- renewal in 270 seconds.
43+
1364217299382 [/192.168.0.38:63182] [[/var/log/messages] : Mar 25 13:59:38 dev-linux
44+
dhclient: DHCPREQUEST of 192.168.0.50 on eth2 to 192.168.0.254 port 67
45+
1364217299382 [/192.168.0.38:63182] [/[/var/log/messages] : Mar 25 13:59:38 dev-linux
46+
dhclient: DHCPACK of 192.168.0.50 from 192.168.0.254
47+
1364217299382 [/192.168.0.38:63182] [/var/log/messages] : Mar 25 13:59:38 dev-linux
48+
dhclient: bound to 192.168.0.50 -- renewal in 259 seconds.
49+
1364217299383 [/192.168.0.38:63182] [/var/log/messages] : Mar 25 14:03:57 dev-linux
50+
dhclient: DHCPREQUEST of 192.168.0.50 on eth2 to 192.168.0.254 port 67
51+
1364217299383 [/192.168.0.38:63182] [/var/log/messages] : Mar 25 14:03:57 dev-linux
52+
dhclient: DHCPACK of 192.168.0.50 from 192.168.0.254
53+
1364217299383 [/192.168.0.38:63182] [/var/log/messages] : Mar 25 14:03:57 dev-linux
54+
dhclient: bound to 192.168.0.50 -- renewal in 285 seconds.
55+
56+
若你没有访问 UNIX syslog 的权限,可以创建 自定义的文件,手动填入内容。下面是 UNIX 命令用 touch 创建一个空文件
57+
58+
$ touch ~/mylog.log
59+
60+
再次启动 LogEventBroadcaster,设置系统属性
61+
62+
$ mvn exec:exec -Pchapter13-LogEventBroadcaster -Dlogfile=~/mylog.log
63+
64+
当 LogEventBroadcaster 运行时,你可以手动的添加消息到文件来查看广播到 LogEventMonitor 控制台的内容。使用 echo 和输出的文件
65+
66+
$ echo ’Test log entry’ >> ~/mylog.log
67+
68+
你可以启动任意个监视器实例,他们都会收到相同的消息。

‎SUMMARY.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ This is the summary of my book.
8888
* [EventLog 的 POJO](NETTY BY EXAMPLE/EventLog POJOs.md)
8989
* [写广播器](NETTY BY EXAMPLE/Writing the broadcaster.md)
9090
* [写监视器](NETTY BY EXAMPLE/Writing the monitor.md)
91+
* [运行 LogEventBroadcaster 和 LogEventMonitor](NETTY BY EXAMPLE/Running the LogEventBroadcaster and LogEventMonitor.md)
9192
* 高级主题
9293
* [实现自定义编解码器](ADVANCED TOPICS/Implement a custom codec.md)
9394
* [EventLoop 和线程模型](ADVANCED TOPICS/EventLoop and thread model.md)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /