Class: Arcp::Runtime::SessionActor

Inherits:
Object
  • Object
show all
Defined in:
lib/arcp/runtime/session_actor.rb

Overview

Per-connection runtime actor. Owns one transport, drives the hello/welcome handshake, dispatches inbound envelopes, and serves as the outbox queue subscriptions fan out into.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime:, transport:) ⇒ SessionActor

Returns a new instance of SessionActor.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/arcp/runtime/session_actor.rb', line 15

def initialize(runtime:, transport:)
  @runtime = runtime
  @transport = transport
  @session_id = nil
  @principal = nil
  @outbox = Async::Queue.new
  @last_processed_seq = 0
  @capabilities = nil
  @resume_token = nil
  @heartbeat_task = nil
  @writer_task = nil
  @closed = false
end

Instance Attribute Details

#outboxObject (readonly)

Returns the value of attribute outbox.



13
14
15
# File 'lib/arcp/runtime/session_actor.rb', line 13

def outbox
  @outbox
end

#principalObject (readonly)

Returns the value of attribute principal.



13
14
15
# File 'lib/arcp/runtime/session_actor.rb', line 13

def principal
  @principal
end

#session_idObject (readonly)

Returns the value of attribute session_id.



13
14
15
# File 'lib/arcp/runtime/session_actor.rb', line 13

def session_id
  @session_id
end

Instance Method Details

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/arcp/runtime/session_actor.rb', line 29

def run
  Async do |task|
    envelope = @transport.receive
    return if envelope.nil?

    handshake(envelope)
    spawn_writer(task)
    spawn_heartbeat(task)
    loop_inbound(task)
  ensure
    close_session
  end
end

#send_envelope(envelope) ⇒ Object



43
44
45
# File 'lib/arcp/runtime/session_actor.rb', line 43

def send_envelope(envelope)
  @outbox.enqueue(envelope)
end