Record Class EventRecord

java.lang.Object
java.lang.Record
cloud.opencode.base.event.store.EventRecord
Record Components:
id - the unique event ID | 唯一事件ID
event - the event object | 事件对象
eventType - the event type class name | 事件类型类名
timestamp - the event timestamp | 事件时间戳
source - the event source | 事件来源
storedAt - the storage timestamp | 存储时间戳
sequenceNumber - the sequence number | 序列号

public record EventRecord(String id, Event event, String eventType, Instant timestamp, String source, Instant storedAt, long sequenceNumber) extends Record
Event Record 事件记录

Immutable record representing a stored event with metadata.

表示带有元数据的已存储事件的不可变记录。

Fields | 字段:

  • id - Event unique identifier | 事件唯一标识符
  • event - The actual event object | 实际事件对象
  • eventType - Event class name | 事件类名
  • timestamp - Event timestamp | 事件时间戳
  • source - Event source | 事件来源
  • storedAt - Storage timestamp | 存储时间戳
  • sequenceNumber - Sequence number for ordering | 用于排序的序列号

Usage Examples | 使用示例:

EventRecord record = new EventRecord(
    event.getId(),
    event,
    event.getClass().getName(),
    event.getTimestamp(),
    event.getSource(),
    Instant.now(),
    sequenceGenerator.next()
);

Features | 主要功能:

  • Core functionality - 核心功能

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
Since:
JDK 25, opencode-base-event V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • EventRecord

      public EventRecord(String id, Event event, String eventType, Instant timestamp, String source, Instant storedAt, long sequenceNumber)
      Creates an instance of a EventRecord record class.
      Parameters:
      id - the value for the id record component
      event - the value for the event record component
      eventType - the value for the eventType record component
      timestamp - the value for the timestamp record component
      source - the value for the source record component
      storedAt - the value for the storedAt record component
      sequenceNumber - the value for the sequenceNumber record component
  • Method Details

    • of

      public static EventRecord of(Event event, long sequenceNumber)
      Create event record from an event 从事件创建事件记录
      Parameters:
      event - the event | 事件
      sequenceNumber - the sequence number | 序列号
      Returns:
      new event record | 新的事件记录
    • isType

      public boolean isType(Class<? extends Event> type)
      Check if the event is of a specific type 检查事件是否为特定类型
      Parameters:
      type - the event type class | 事件类型类
      Returns:
      true if matches | 如果匹配返回true
    • isWithinTimeRange

      public boolean isWithinTimeRange(Instant from, Instant to)
      Check if the event is within a time range 检查事件是否在时间范围内
      Parameters:
      from - start time (inclusive) | 开始时间(包含)
      to - end time (exclusive) | 结束时间(不包含)
      Returns:
      true if within range | 如果在范围内返回true
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • id

      public String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • event

      public Event event()
      Returns the value of the event record component.
      Returns:
      the value of the event record component
    • eventType

      public String eventType()
      Returns the value of the eventType record component.
      Returns:
      the value of the eventType record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component
    • source

      public String source()
      Returns the value of the source record component.
      Returns:
      the value of the source record component
    • storedAt

      public Instant storedAt()
      Returns the value of the storedAt record component.
      Returns:
      the value of the storedAt record component
    • sequenceNumber

      public long sequenceNumber()
      Returns the value of the sequenceNumber record component.
      Returns:
      the value of the sequenceNumber record component