Class: Legion::Gaia::Router::AgentBridge
- Inherits:
-
Object
- Object
- Legion::Gaia::Router::AgentBridge
- Defined in:
- lib/legion/gaia/router/agent_bridge.rb
Instance Attribute Summary collapse
-
#started ⇒ Object
readonly
Returns the value of attribute started.
-
#worker_id ⇒ Object
readonly
Returns the value of attribute worker_id.
Instance Method Summary collapse
- #ingest_from_payload(payload) ⇒ Object
-
#initialize(worker_id:) ⇒ AgentBridge
constructor
A new instance of AgentBridge.
- #publish_output(output_frame) ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(worker_id:) ⇒ AgentBridge
Returns a new instance of AgentBridge.
9 10 11 12 |
# File 'lib/legion/gaia/router/agent_bridge.rb', line 9 def initialize(worker_id:) @worker_id = worker_id @started = false end |
Instance Attribute Details
#started ⇒ Object (readonly)
Returns the value of attribute started.
7 8 9 |
# File 'lib/legion/gaia/router/agent_bridge.rb', line 7 def started @started end |
#worker_id ⇒ Object (readonly)
Returns the value of attribute worker_id.
7 8 9 |
# File 'lib/legion/gaia/router/agent_bridge.rb', line 7 def worker_id @worker_id end |
Instance Method Details
#ingest_from_payload(payload) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/legion/gaia/router/agent_bridge.rb', line 39 def ingest_from_payload(payload) frame = reconstruct_input_frame(payload) return { ingested: false, reason: :invalid_frame } unless frame if Legion::Gaia.respond_to?(:ingest) && Legion::Gaia.started? Legion::Gaia.ingest(frame) else { ingested: false, reason: :gaia_not_started } end end |
#publish_output(output_frame) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/legion/gaia/router/agent_bridge.rb', line 28 def publish_output(output_frame) return { published: false, reason: :not_started } unless started? if transport_available? Transport::Messages::OutputFrameMessage.new(frame: output_frame).publish { published: true, frame_id: output_frame.id } else { published: false, reason: :no_transport, frame_id: output_frame.id } end end |
#start ⇒ Object
14 15 16 17 |
# File 'lib/legion/gaia/router/agent_bridge.rb', line 14 def start @started = true subscribe_inbound if transport_available? end |
#started? ⇒ Boolean
24 25 26 |
# File 'lib/legion/gaia/router/agent_bridge.rb', line 24 def started? @started == true end |
#stop ⇒ Object
19 20 21 22 |
# File 'lib/legion/gaia/router/agent_bridge.rb', line 19 def stop @consumer&.cancel if @consumer.respond_to?(:cancel) @started = false end |