13.3 日志事件POJO
我们的应用程序通常需要某种“消息POJO”用于保存消息,我们把这个消息POJO看成是一个“事件消息”在本例子中我们也创建一个POJO叫做LogEvent,LogEvent用来存储事件数据,然后将数据输出到日志文件。看下面代码:
[java] view plaincopy
- package netty.in.action.udp;
- import java.net.InetSocketAddress;
- public class LogEvent {
- public static final byte SEPARATOR = (byte) '|';
- private final InetSocketAddress source;
- private final String logfile;
- private final String msg;
- private final long received;
- public LogEvent(String logfile, String msg) {
- this(null, -1, logfile, msg);
- }
- public LogEvent(InetSocketAddress source, long received, String logfile, String msg) {
- this.source = source;
- this.logfile = logfile;
- this.msg = msg;
- this.received = received;
- }
- public InetSocketAddress getSource() {
- return source;
- }
- public String getLogfile() {
- return logfile;
- }
- public String getMsg() {
- return msg;
- }
- public long getReceived() {
- return received;
- }
- }
接下来的章节,我们将用这个POJO类来实现具体的逻辑。