Class: VectorMCP::Transport::SseSessionManager
- Inherits:
-
BaseSessionManager
- Object
- BaseSessionManager
- VectorMCP::Transport::SseSessionManager
- Defined in:
- lib/vector_mcp/transport/sse_session_manager.rb
Overview
Session manager for SSE transport with single shared session and client connection management. Extends BaseSessionManager with SSE-specific functionality.
The SSE transport uses a single shared session for all client connections, but manages multiple client connections separately.
Instance Attribute Summary collapse
-
#clients ⇒ Object
readonly
Returns the value of attribute clients.
Attributes inherited from BaseSessionManager
#logger, #session_timeout, #transport
Instance Method Summary collapse
-
#all_clients ⇒ Hash
Gets all client connections.
-
#cleanup_all_sessions ⇒ void
Cleans up all clients and the shared session.
-
#client_count ⇒ Integer
Gets the number of connected clients.
-
#client_unregistered?(client_id) ⇒ Boolean
Unregisters a client connection from the session manager.
-
#initialize(transport, session_timeout = 300) ⇒ SseSessionManager
constructor
Initializes a new SSE session manager.
-
#register_client(client_id, client_connection) ⇒ void
Registers a client connection with the session manager.
-
#shared_session ⇒ Session
Gets the shared session for SSE transport.
Methods inherited from BaseSessionManager
#active_session_ids, #create_session, #find_sessions, #get_or_create_session, #get_session, #get_session_metadata, #session_count, #session_metadata_updated?, #session_terminated?, #sessions?
Constructor Details
#initialize(transport, session_timeout = 300) ⇒ SseSessionManager
Initializes a new SSE session manager.
19 20 21 22 23 24 25 |
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 19 def initialize(transport, session_timeout = 300) @clients = Concurrent::Hash.new super # Create the single shared session for SSE transport @shared_session = create_shared_session end |
Instance Attribute Details
#clients ⇒ Object (readonly)
Returns the value of attribute clients.
13 14 15 |
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 13 def clients @clients end |
Instance Method Details
#all_clients ⇒ Hash
Gets all client connections.
63 64 65 |
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 63 def all_clients @clients.dup end |
#cleanup_all_sessions ⇒ void
This method returns an undefined value.
Cleans up all clients and the shared session.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 77 def cleanup_all_sessions logger.info { "Cleaning up #{@clients.size} client connection(s)" } @clients.each_value do |client_conn| close_client_connection(client_conn) end @clients.clear super end |
#client_count ⇒ Integer
Gets the number of connected clients.
70 71 72 |
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 70 def client_count @clients.size end |
#client_unregistered?(client_id) ⇒ Boolean
Unregisters a client connection from the session manager.
51 52 53 54 55 56 57 58 |
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 51 def client_unregistered?(client_id) client = @clients.delete(client_id) return false unless client (@shared_session.id, clients_count: @clients.size) logger.debug { "Client unregistered: #{client_id}" } true end |
#register_client(client_id, client_connection) ⇒ void
This method returns an undefined value.
Registers a client connection with the session manager.
41 42 43 44 45 |
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 41 def register_client(client_id, client_connection) @clients[client_id] = client_connection (@shared_session.id, clients_count: @clients.size) logger.debug { "Client registered: #{client_id}" } end |
#shared_session ⇒ Session
Gets the shared session for SSE transport. SSE uses a single session shared across all client connections.
31 32 33 34 |
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 31 def shared_session @shared_session.touch! @shared_session end |