- EventLog 的 POJO
EventLog 的 POJO
在消息应用里面,数据一般以 POJO 形式呈现。这可能保存配置或处理信息除了实际的消息数据。在这个应用程序里,消息的单元是一个“事件”。由于数据来自一个日志文件,我们将称之为 LogEvent。
清单13.1显示了这个简单的POJO的细节。
Listing 13.1 LogEvent message
public final 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) { //1this(null, -1, logfile, msg);}public LogEvent(InetSocketAddress source, long received, String logfile, String msg) { //2this.source = source;this.logfile = logfile;this.msg = msg;this.received = received;}public InetSocketAddress getSource() { //3return source;}public String getLogfile() { //4return logfile;}public String getMsg() { //5return msg;}public long getReceivedTimestamp() { //6return received;}}
- 构造器用于出站消息
- 构造器用于入站消息
- 返回发送 LogEvent 的 InetSocketAddress 的资源
- 返回用于发送 LogEvent 的日志文件的名称
- 返回消息的内容
- 返回 LogEvent 接收到的时间
