Class InMemoryEventStore
java.lang.Object
cloud.opencode.base.event.store.InMemoryEventStore
- All Implemented Interfaces:
EventStore
In-Memory Event Store
内存事件存储
Thread-safe in-memory implementation of EventStore.
EventStore的线程安全内存实现。
Features | 主要功能:
- Thread-safe storage - 线程安全存储
- Automatic capacity management - 自动容量管理
- Event replay support - 事件重放支持
- Time-based queries - 基于时间的查询
Usage Examples | 使用示例:
InMemoryEventStore store = new InMemoryEventStore(10000);
store.save(event);
// Query events
List<EventRecord> records = store.findByType(OrderCreatedEvent.class);
// Replay events
store.replay(OrderEvent.class, e -> processEvent(e));
- Since:
- JDK 25, opencode-base-event V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate in-memory event store with default capacity (10000) 使用默认容量(10000)创建内存事件存储InMemoryEventStore(int maxCapacity) Create in-memory event store with specified capacity 使用指定容量创建内存事件存储 -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all stored events 清除所有存储的事件longcount()Get the total count of stored events 获取存储事件的总数findAll()Get all event records 获取所有事件记录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 根据事件类型查找所有事件记录longGet the current sequence number 获取当前序列号intGet the maximum capacity 获取最大容量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 将事件保存到存储
-
Constructor Details
-
InMemoryEventStore
public InMemoryEventStore()Create in-memory event store with default capacity (10000) 使用默认容量(10000)创建内存事件存储 -
InMemoryEventStore
public InMemoryEventStore(int maxCapacity) Create in-memory event store with specified capacity 使用指定容量创建内存事件存储- Parameters:
maxCapacity- the maximum number of events to store | 存储的最大事件数
-
-
Method Details
-
save
Description copied from interface:EventStoreSave an event to the store 将事件保存到存储- Specified by:
savein interfaceEventStore- Parameters:
event- the event to save | 要保存的事件- Returns:
- the saved event record | 保存的事件记录
-
findById
Description copied from interface:EventStoreFind event record by event ID 根据事件ID查找事件记录- Specified by:
findByIdin interfaceEventStore- Parameters:
eventId- the event ID | 事件ID- Returns:
- optional containing the event record if found | 如果找到则包含事件记录的Optional
-
findByType
Description copied from interface:EventStoreFind all event records by event type 根据事件类型查找所有事件记录- Specified by:
findByTypein interfaceEventStore- Parameters:
eventType- the event type class | 事件类型类- Returns:
- list of event records | 事件记录列表
-
findByTimeRange
Description copied from interface:EventStoreFind event records within a time range 在时间范围内查找事件记录- Specified by:
findByTimeRangein interfaceEventStore- Parameters:
from- start time (inclusive) | 开始时间(包含)to- end time (exclusive) | 结束时间(不包含)- Returns:
- list of event records | 事件记录列表
-
findBySource
Description copied from interface:EventStoreFind event records by source 根据来源查找事件记录- Specified by:
findBySourcein interfaceEventStore- Parameters:
source- the event source | 事件来源- Returns:
- list of event records | 事件记录列表
-
replay
Description copied from interface:EventStoreReplay events of a specific type 重放特定类型的事件- Specified by:
replayin interfaceEventStore- Parameters:
eventType- the event type to replay | 要重放的事件类型handler- the handler to process each event | 处理每个事件的处理器
-
replayByTimeRange
Description copied from interface:EventStoreReplay events within a time range 在时间范围内重放事件- Specified by:
replayByTimeRangein interfaceEventStore- Parameters:
from- start time (inclusive) | 开始时间(包含)to- end time (exclusive) | 结束时间(不包含)handler- the handler to process each event | 处理每个事件的处理器
-
count
public long count()Description copied from interface:EventStoreGet the total count of stored events 获取存储事件的总数- Specified by:
countin interfaceEventStore- Returns:
- total event count | 事件总数
-
clear
public void clear()Description copied from interface:EventStoreClear all stored events 清除所有存储的事件- Specified by:
clearin interfaceEventStore
-
getMaxCapacity
public int getMaxCapacity()Get the maximum capacity 获取最大容量- Returns:
- the maximum capacity | 最大容量
-
findAll
Get all event records 获取所有事件记录- Returns:
- list of all event records | 所有事件记录列表
-
getCurrentSequence
public long getCurrentSequence()Get the current sequence number 获取当前序列号- Returns:
- current sequence number | 当前序列号
-