Skip to content

Commit 2e656c3

Browse files
committed
completed EventLog 的 POJO
1 parent 747c1a2 commit 2e656c3

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

NETTY BY EXAMPLE/EventLog POJOs.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
EventLog 的 POJO
2+
====
3+
4+
在消息应用里面,数据一般以 POJO 形式呈现。这可能保存配置或处理信息除了实际的消息数据。在这个应用程序里,消息的单元是一个“事件”。由于数据来自一个日志文件,我们将称之为 LogEvent。
5+
6+
清单13.1显示了这个简单的POJO的细节。
7+
8+
Listing 13.1 LogEvent message
9+
10+
public final class LogEvent {
11+
public static final byte SEPARATOR = (byte) ':';
12+
13+
private final InetSocketAddress source;
14+
private final String logfile;
15+
private final String msg;
16+
private final long received;
17+
18+
public LogEvent(String logfile, String msg) { //1
19+
this(null, -1, logfile, msg);
20+
}
21+
22+
public LogEvent(InetSocketAddress source, long received, String logfile, String msg) { //2
23+
this.source = source;
24+
this.logfile = logfile;
25+
this.msg = msg;
26+
this.received = received;
27+
}
28+
29+
public InetSocketAddress getSource() { //3
30+
return source;
31+
}
32+
33+
public String getLogfile() { //4
34+
return logfile;
35+
}
36+
37+
public String getMsg() { //5
38+
return msg;
39+
}
40+
41+
public long getReceivedTimestamp() { //6
42+
return received;
43+
}
44+
}
45+
46+
1. 构造器用于出站消息
47+
2. 构造器用于入站消息
48+
3. 返回发送 LogEvent 的 InetSocketAddress 的资源
49+
4. 返回用于发送 LogEvent 的日志文件的名称
50+
5. 返回消息的内容
51+
6. 返回 LogEvent 接收到的时间
52+

SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ This is the summary of my book.
8585
* [UDP 基础](NETTY BY EXAMPLE/UDP Basics.md)
8686
* [UDP 广播](NETTY BY EXAMPLE/UDP Broadcast.md)
8787
* [UDP 示例](NETTY BY EXAMPLE/The UDP Sample Application.md)
88+
* [EventLog 的 POJO](NETTY BY EXAMPLE/EventLog POJOs.md)
8889
* 高级主题
8990
* [实现自定义编解码器](ADVANCED TOPICS/Implement a custom codec.md)
9091
* [EventLoop 和线程模型](ADVANCED TOPICS/EventLoop and thread model.md)

0 commit comments

Comments
 (0)