13.3 日志事件POJO

    我们的应用程序通常需要某种“消息POJO”用于保存消息,我们把这个消息POJO看成是一个“事件消息”在本例子中我们也创建一个POJO叫做LogEvent,LogEvent用来存储事件数据,然后将数据输出到日志文件。看下面代码:

[java] view plaincopy

  1. package netty.in.action.udp;
  2. import java.net.InetSocketAddress;
  3. public class LogEvent {
  4. public static final byte SEPARATOR = (byte) '|';
  5. private final InetSocketAddress source;
  6. private final String logfile;
  7. private final String msg;
  8. private final long received;
  9. public LogEvent(String logfile, String msg) {
  10. this(null, -1, logfile, msg);
  11. }
  12. public LogEvent(InetSocketAddress source, long received, String logfile, String msg) {
  13. this.source = source;
  14. this.logfile = logfile;
  15. this.msg = msg;
  16. this.received = received;
  17. }
  18. public InetSocketAddress getSource() {
  19. return source;
  20. }
  21. public String getLogfile() {
  22. return logfile;
  23. }
  24. public String getMsg() {
  25. return msg;
  26. }
  27. public long getReceived() {
  28. return received;
  29. }
  30. }

接下来的章节,我们将用这个POJO类来实现具体的逻辑。

results matching ""

    No results matching ""