Interface EventStore
- All Known Implementing Classes:
InMemoryEventStore
public interface EventStore
Event Store Interface
事件存储接口
Interface for persisting and retrieving events.
用于持久化和检索事件的接口。
Features | 主要功能:
- Event persistence - 事件持久化
- Event retrieval - 事件检索
- Event replay - 事件重放
- Event sourcing support - 事件溯源支持
Usage Examples | 使用示例:
EventStore store = new InMemoryEventStore(1000);
store.save(event);
List<EventRecord> records = store.findByType(OrderCreatedEvent.class);
store.replay(OrderEvent.class, event -> processEvent(event));
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是(无状态)
- Since:
- JDK 25, opencode-base-event V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all stored events 清除所有存储的事件longcount()Get the total count of stored events 获取存储事件的总数Find event record by event ID 根据事件ID查找事件记录findBySource(String source) Find event records by source 根据来源查找事件记录findByTimeRange(Instant from, Instant to) Find event records within a time range 在时间范围内查找事件记录findByType(Class<? extends Event> eventType) Find all event records by event type 根据事件类型查找所有事件记录voidReplay events of a specific type 重放特定类型的事件voidreplayByTimeRange(Instant from, Instant to, Consumer<Event> handler) Replay events within a time range 在时间范围内重放事件Save an event to the store 将事件保存到存储
-
Method Details
-
save
Save an event to the store 将事件保存到存储- Parameters:
event- the event to save | 要保存的事件- Returns:
- the saved event record | 保存的事件记录
-
findById
Find event record by event ID 根据事件ID查找事件记录- Parameters:
eventId- the event ID | 事件ID- Returns:
- optional containing the event record if found | 如果找到则包含事件记录的Optional
-
findByType
Find all event records by event type 根据事件类型查找所有事件记录- Parameters:
eventType- the event type class | 事件类型类- Returns:
- list of event records | 事件记录列表
-
findByTimeRange
Find event records within a time range 在时间范围内查找事件记录- Parameters:
from- start time (inclusive) | 开始时间(包含)to- end time (exclusive) | 结束时间(不包含)- Returns:
- list of event records | 事件记录列表
-
findBySource
Find event records by source 根据来源查找事件记录- Parameters:
source- the event source | 事件来源- Returns:
- list of event records | 事件记录列表
-
replay
-
replayByTimeRange
-
count
long count()Get the total count of stored events 获取存储事件的总数- Returns:
- total event count | 事件总数
-
clear
void clear()Clear all stored events 清除所有存储的事件
-