Class: VectorMCP::Transport::HttpStream::SessionManager Private

Inherits:
BaseSessionManager show all
Defined in:
lib/vector_mcp/transport/http_stream/session_manager.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 HTTP stream sessions with automatic cleanup and thread safety. Extends BaseSessionManager with HTTP streaming-specific functionality.

Handles:

  • Session creation and lifecycle management
  • Thread-safe session storage using concurrent-ruby
  • Automatic session cleanup based on timeout
  • Session context integration with VectorMCP::Session
  • HTTP streaming connection management

Defined Under Namespace

Modules: SessionStreaming

Instance Attribute Summary

Attributes inherited from BaseSessionManager

#logger, #session_timeout, #transport

Instance Method Summary collapse

Methods inherited from BaseSessionManager

#active_session_ids, #cleanup_all_sessions, #find_sessions, #get_session, #get_session_metadata, #initialize, #session_count, #session_metadata_updated?, #session_terminated?, #sessions?

Constructor Details

This class inherits a constructor from VectorMCP::Transport::BaseSessionManager

Instance Method Details

#create_session(session_id = nil, rack_env = nil) ⇒ VectorMCP::Session

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.

Creates a new session. RequestContext.from_rack_env handles nil rack_env by falling back to a minimal context, so we don't need to branch here.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/vector_mcp/transport/http_stream/session_manager.rb', line 62

def create_session(session_id = nil, rack_env = nil)
  session_id ||= generate_session_id

  request_context = VectorMCP::RequestContext.from_rack_env(rack_env, "http_stream")
  session = VectorMCP::Session.new(
    @transport.server, @transport, id: session_id, request_context: request_context
  )
  session.extend(SessionStreaming)
  session..merge!()

  @sessions[session_id] = session

  logger.info { "Session created: #{session_id}" }
  session
end

#get_or_create_session(session_id = nil, rack_env = nil) ⇒ Object

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.

Override to add rack_env support. Returns nil when a session_id is provided but not found (expired or unknown) — callers are responsible for returning 404 in that case. Request-scoped data is never written onto an existing session; each request carries its own context via the Invocation built at dispatch.



83
84
85
86
87
88
89
# File 'lib/vector_mcp/transport/http_stream/session_manager.rb', line 83

def get_or_create_session(session_id = nil, rack_env = nil)
  if session_id
    get_session(session_id)
  else
    create_session(nil, rack_env)
  end
end

#remove_streaming_connection(session, connection = nil) ⇒ 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.

Removes streaming connection from a session.



122
123
124
125
126
# File 'lib/vector_mcp/transport/http_stream/session_manager.rb', line 122

def remove_streaming_connection(session, connection = nil)
  session.remove_streaming_connection(connection)
  session.touch!
  logger.debug { "Streaming connection removed: #{session.id}" }
end

#set_streaming_connection(session, connection) ⇒ 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.

Associates a streaming connection with a session.



111
112
113
114
115
# File 'lib/vector_mcp/transport/http_stream/session_manager.rb', line 111

def set_streaming_connection(session, connection)
  session.add_streaming_connection(connection)
  session.touch!
  logger.debug { "Streaming connection associated: #{session.id} (stream #{connection.stream_id})" }
end

#terminate_session(session_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.

Terminates a session by ID.

rubocop:disable Naming/PredicateMethod



96
97
98
99
100
101
102
103
# File 'lib/vector_mcp/transport/http_stream/session_manager.rb', line 96

def terminate_session(session_id)
  session = @sessions.delete(session_id)
  return false unless session

  on_session_terminated(session)
  logger.info { "Session terminated: #{session_id}" }
  true
end