Class: VectorMCP::Transport::HttpStream::EventStore Private
- Inherits:
-
Object
- Object
- VectorMCP::Transport::HttpStream::EventStore
- Defined in:
- lib/vector_mcp/transport/http_stream/event_store.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Manages Server-Sent Events storage for resumable connections.
Handles:
-
Event storage with unique IDs
-
Event replay from a specific Last-Event-ID
-
Circular buffer for memory efficiency
-
Thread-safe operations
Defined Under Namespace
Classes: Event
Instance Attribute Summary collapse
- #logger ⇒ Object readonly private
- #max_events ⇒ Object readonly private
Instance Method Summary collapse
-
#clear ⇒ void
private
Clears all stored events.
-
#event_count ⇒ Integer
private
Gets the total number of stored events.
-
#event_exists?(event_id) ⇒ Boolean
private
Checks if an event ID exists in the store.
-
#get_events_after(last_event_id, session_id: nil) ⇒ Array<Event>
private
Retrieves events starting from a specific event ID, optionally filtered by session.
-
#initialize(max_events) ⇒ EventStore
constructor
private
Initializes a new event store.
-
#newest_event_id ⇒ String?
private
Gets the newest event ID (for debugging/monitoring).
-
#oldest_event_id ⇒ String?
private
Gets the oldest event ID (for debugging/monitoring).
-
#stats ⇒ Hash
private
Gets statistics about the event store.
-
#store_event(data, type = nil, session_id: nil) ⇒ String
private
Stores a new event and returns its ID.
Constructor Details
#initialize(max_events) ⇒ EventStore
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes a new event store.
36 37 38 39 40 41 |
# File 'lib/vector_mcp/transport/http_stream/event_store.rb', line 36 def initialize(max_events) @max_events = max_events @events = Concurrent::Array.new @event_index = Concurrent::Hash.new # event_id -> index for fast lookup @current_sequence = Concurrent::AtomicFixnum.new(0) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 |
# File 'lib/vector_mcp/transport/http_stream/event_store.rb', line 31 def logger @logger end |
#max_events ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 |
# File 'lib/vector_mcp/transport/http_stream/event_store.rb', line 31 def max_events @max_events end |
Instance Method Details
#clear ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Clears all stored events.
127 128 129 130 |
# File 'lib/vector_mcp/transport/http_stream/event_store.rb', line 127 def clear @events.clear @event_index.clear end |
#event_count ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Gets the total number of stored events.
98 99 100 |
# File 'lib/vector_mcp/transport/http_stream/event_store.rb', line 98 def event_count @events.length end |
#event_exists?(event_id) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if an event ID exists in the store.
120 121 122 |
# File 'lib/vector_mcp/transport/http_stream/event_store.rb', line 120 def event_exists?(event_id) @event_index.key?(event_id) end |
#get_events_after(last_event_id, session_id: nil) ⇒ Array<Event>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Retrieves events starting from a specific event ID, optionally filtered by session.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/vector_mcp/transport/http_stream/event_store.rb', line 78 def get_events_after(last_event_id, session_id: nil) events = if last_event_id.nil? @events.to_a else last_index = @event_index[last_event_id] return [] if last_index.nil? start_index = last_index + 1 return [] if start_index >= @events.length @events[start_index..] end events = events.select { |e| e.session_id == session_id } if session_id events end |
#newest_event_id ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Gets the newest event ID (for debugging/monitoring).
112 113 114 |
# File 'lib/vector_mcp/transport/http_stream/event_store.rb', line 112 def newest_event_id @events.last&.id end |
#oldest_event_id ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Gets the oldest event ID (for debugging/monitoring).
105 106 107 |
# File 'lib/vector_mcp/transport/http_stream/event_store.rb', line 105 def oldest_event_id @events.first&.id end |
#stats ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Gets statistics about the event store.
135 136 137 138 139 140 141 142 143 |
# File 'lib/vector_mcp/transport/http_stream/event_store.rb', line 135 def stats { total_events: event_count, max_events: @max_events, oldest_event_id: oldest_event_id, newest_event_id: newest_event_id, memory_usage_ratio: event_count.to_f / @max_events } end |
#store_event(data, type = nil, session_id: nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Stores a new event and returns its ID.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vector_mcp/transport/http_stream/event_store.rb', line 49 def store_event(data, type = nil, session_id: nil) event_id = generate_event_id = Time.now event = Event.new(event_id, data, type, , session_id) # Add to events array @events.push(event) # Update index @event_index[event_id] = @events.length - 1 # Maintain circular buffer if @events.length > @max_events removed_event = @events.shift @event_index.delete(removed_event.id) # Update all indices after removal @event_index.transform_values! { |index| index - 1 } end event_id end |