Class: Arcp::Runtime::Runtime
- Inherits:
-
Object
- Object
- Arcp::Runtime::Runtime
- Defined in:
- lib/arcp/runtime/runtime.rb
Overview
ARCP runtime. Owns the agent registry, job manager, lease manager, subscription manager, and event log. Sessions attach via ‘#accept(transport)` which returns an `Async::Task` running the `SessionActor` for that connection.
Instance Attribute Summary collapse
-
#auth_verifier ⇒ Object
readonly
Returns the value of attribute auth_verifier.
-
#clock ⇒ Object
readonly
Returns the value of attribute clock.
-
#credential_registry ⇒ Object
readonly
Returns the value of attribute credential_registry.
-
#enforce_model_use ⇒ Object
readonly
Returns the value of attribute enforce_model_use.
-
#event_log ⇒ Object
readonly
Returns the value of attribute event_log.
-
#heartbeat_interval_sec ⇒ Object
readonly
Returns the value of attribute heartbeat_interval_sec.
-
#job_manager ⇒ Object
readonly
Returns the value of attribute job_manager.
-
#lease_manager ⇒ Object
readonly
Returns the value of attribute lease_manager.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#resume_window_sec ⇒ Object
readonly
Returns the value of attribute resume_window_sec.
-
#subscription_manager ⇒ Object
readonly
Returns the value of attribute subscription_manager.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #accept(transport) ⇒ Object
- #deregister_session(session_id) ⇒ Object
-
#initialize(auth_verifier:, name: 'arcp-runtime', version: Arcp::VERSION, heartbeat_interval_sec: 30, resume_window_sec: 300, clock: Arcp::SystemClock.new, credential_provisioner: nil, credential_store: nil, require_durable_store: false, enforce_model_use: false) ⇒ Runtime
constructor
A new instance of Runtime.
- #local_capabilities(agents_inventory: false) ⇒ Object
- #register_agent(name:, versions:, default:, handler:) ⇒ Object
- #register_session(session_id, actor) ⇒ Object
- #session(session_id) ⇒ Object
- #shutdown(reason: nil) ⇒ Object
Constructor Details
#initialize(auth_verifier:, name: 'arcp-runtime', version: Arcp::VERSION, heartbeat_interval_sec: 30, resume_window_sec: 300, clock: Arcp::SystemClock.new, credential_provisioner: nil, credential_store: nil, require_durable_store: false, enforce_model_use: false) ⇒ Runtime
Returns a new instance of Runtime.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/arcp/runtime/runtime.rb', line 27 def initialize(auth_verifier:, name: 'arcp-runtime', version: Arcp::VERSION, heartbeat_interval_sec: 30, resume_window_sec: 300, clock: Arcp::SystemClock.new, credential_provisioner: nil, credential_store: nil, require_durable_store: false, enforce_model_use: false) if require_durable_store && credential_provisioner && credential_store.nil? raise Arcp::Errors::InvalidRequest, 'provisioned_credentials requires a CredentialStore' end @auth_verifier = auth_verifier @name = name @version = version @heartbeat_interval_sec = heartbeat_interval_sec @resume_window_sec = resume_window_sec @clock = clock @enforce_model_use = enforce_model_use @credential_registry = build_credential_registry( credential_provisioner: credential_provisioner, credential_store: credential_store, clock: clock ) @event_log = EventLog.new(window_sec: resume_window_sec, clock: clock) @lease_manager = LeaseManager.new(clock: clock, enforce_model_use: enforce_model_use) @subscription_manager = SubscriptionManager.new @job_manager = JobManager.new( runtime: self, lease_manager: @lease_manager, subscription_manager: @subscription_manager, event_log: @event_log, clock: clock ) @sessions = {} @mutex = Mutex.new end |
Instance Attribute Details
#auth_verifier ⇒ Object (readonly)
Returns the value of attribute auth_verifier.
22 23 24 |
# File 'lib/arcp/runtime/runtime.rb', line 22 def auth_verifier @auth_verifier end |
#clock ⇒ Object (readonly)
Returns the value of attribute clock.
22 23 24 |
# File 'lib/arcp/runtime/runtime.rb', line 22 def clock @clock end |
#credential_registry ⇒ Object (readonly)
Returns the value of attribute credential_registry.
22 23 24 |
# File 'lib/arcp/runtime/runtime.rb', line 22 def credential_registry @credential_registry end |
#enforce_model_use ⇒ Object (readonly)
Returns the value of attribute enforce_model_use.
22 23 24 |
# File 'lib/arcp/runtime/runtime.rb', line 22 def enforce_model_use @enforce_model_use end |
#event_log ⇒ Object (readonly)
Returns the value of attribute event_log.
22 23 24 |
# File 'lib/arcp/runtime/runtime.rb', line 22 def event_log @event_log end |
#heartbeat_interval_sec ⇒ Object (readonly)
Returns the value of attribute heartbeat_interval_sec.
22 23 24 |
# File 'lib/arcp/runtime/runtime.rb', line 22 def heartbeat_interval_sec @heartbeat_interval_sec end |
#job_manager ⇒ Object (readonly)
Returns the value of attribute job_manager.
22 23 24 |
# File 'lib/arcp/runtime/runtime.rb', line 22 def job_manager @job_manager end |
#lease_manager ⇒ Object (readonly)
Returns the value of attribute lease_manager.
22 23 24 |
# File 'lib/arcp/runtime/runtime.rb', line 22 def lease_manager @lease_manager end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/arcp/runtime/runtime.rb', line 22 def name @name end |
#resume_window_sec ⇒ Object (readonly)
Returns the value of attribute resume_window_sec.
22 23 24 |
# File 'lib/arcp/runtime/runtime.rb', line 22 def resume_window_sec @resume_window_sec end |
#subscription_manager ⇒ Object (readonly)
Returns the value of attribute subscription_manager.
22 23 24 |
# File 'lib/arcp/runtime/runtime.rb', line 22 def subscription_manager @subscription_manager end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
22 23 24 |
# File 'lib/arcp/runtime/runtime.rb', line 22 def version @version end |
Instance Method Details
#accept(transport) ⇒ Object
83 84 85 86 |
# File 'lib/arcp/runtime/runtime.rb', line 83 def accept(transport) actor = SessionActor.new(runtime: self, transport: transport) actor.run end |
#deregister_session(session_id) ⇒ Object
92 93 94 |
# File 'lib/arcp/runtime/runtime.rb', line 92 def deregister_session(session_id) @mutex.synchronize { @sessions.delete(session_id) } end |
#local_capabilities(agents_inventory: false) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/arcp/runtime/runtime.rb', line 68 def local_capabilities(agents_inventory: false) features = Arcp::Session::Feature::ALL.dup unless @credential_registry features -= [ Arcp::Session::Feature::MODEL_USE, Arcp::Session::Feature::PROVISIONED_CREDENTIALS ] end Arcp::Session::CapabilitySet.local( features: features, agents: agents_inventory ? @job_manager.agent_inventory : nil ) end |
#register_agent(name:, versions:, default:, handler:) ⇒ Object
64 65 66 |
# File 'lib/arcp/runtime/runtime.rb', line 64 def register_agent(name:, versions:, default:, handler:) @job_manager.register_agent(name: name, versions: versions, default: default, handler: handler) end |
#register_session(session_id, actor) ⇒ Object
88 89 90 |
# File 'lib/arcp/runtime/runtime.rb', line 88 def register_session(session_id, actor) @mutex.synchronize { @sessions[session_id] = actor } end |
#session(session_id) ⇒ Object
96 |
# File 'lib/arcp/runtime/runtime.rb', line 96 def session(session_id) = @mutex.synchronize { @sessions[session_id] } |
#shutdown(reason: nil) ⇒ Object
98 99 100 101 |
# File 'lib/arcp/runtime/runtime.rb', line 98 def shutdown(reason: nil) actors = @mutex.synchronize { @sessions.values.dup } actors.each { |a| a.send_envelope(bye_envelope(a.session_id, reason)) } end |