Class: ComponentHost::Host
- Inherits:
-
Object
- Object
- ComponentHost::Host
- Includes:
- Dependency, Log::Dependency
- Defined in:
- lib/component_host/host.rb
Defined Under Namespace
Classes: Component
Class Method Summary collapse
Instance Method Summary collapse
- #abort ⇒ Object
- #components ⇒ Object
- #log_observer ⇒ Object
- #record_error(&block) ⇒ Object
- #record_errors_observer ⇒ Object
- #register(initiator, name = nil) ⇒ Object
- #registered?(&block) ⇒ Boolean
- #start(&probe) ⇒ Object
- #start_components(&block) ⇒ Object
Class Method Details
permalink .build ⇒ Object
[View source]
9 10 11 12 13 14 |
# File 'lib/component_host/host.rb', line 9 def self.build instance = new Signal.configure instance instance.send = Actor::Messaging::Send instance end |
Instance Method Details
permalink #abort ⇒ Object
115 116 117 |
# File 'lib/component_host/host.rb', line 115 def abort raise StopIteration end |
permalink #components ⇒ Object
[View source]
111 112 113 |
# File 'lib/component_host/host.rb', line 111 def components @components ||= [] end |
permalink #log_observer ⇒ Object
[View source]
107 108 109 |
# File 'lib/component_host/host.rb', line 107 def log_observer @log_observer ||= SupervisorObservers::Log.new end |
permalink #record_error(&block) ⇒ Object
[View source]
28 29 30 |
# File 'lib/component_host/host.rb', line 28 def record_error(&block) record_errors_observer.record_error_proc = block end |
permalink #record_errors_observer ⇒ Object
[View source]
103 104 105 |
# File 'lib/component_host/host.rb', line 103 def record_errors_observer @record_errors_observer ||= SupervisorObservers::RecordErrors.new end |
permalink #register(initiator, name = nil) ⇒ Object
[View source]
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/component_host/host.rb', line 16 def register(initiator, name=nil) logger.trace(tag: :component_host) { "Registering component (Component Initiator: #{initiator}, Name: #{name || '(none)'})" } component = Component.new(initiator, name) components << component logger.debug(tag: :component_host) { "Registered component (Component Initiator: #{initiator}, Name: #{name || '(none)'})" } component end |
permalink #registered?(&block) ⇒ Boolean
119 120 121 122 123 124 125 |
# File 'lib/component_host/host.rb', line 119 def registered?(&block) block ||= proc { true } components.any? do |component| block.(component.initiator, component.name) end end |
permalink #start(&probe) ⇒ Object
[View source]
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/component_host/host.rb', line 32 def start(&probe) started_components = [] Actor::Supervisor.start do |supervisor| supervisor.add_observer record_errors_observer supervisor.add_observer log_observer signal.trap 'TSTP' do = Actor::Messages::Suspend send.(, supervisor.address) logger.info(tags: [:*, :signal]) { "Handled TSTP signal (Message Name: #{.}, SupervisorAddress: #{supervisor.address.id})" } end signal.trap 'CONT' do = Actor::Messages::Resume send.(, supervisor.address) logger.info(tags: [:*, :signal]) { "Handled CONT signal (Message Name: #{.}, SupervisorAddress: #{supervisor.address.id})" } end signal.trap 'INT' do = Actor::Messages::Shutdown send.(, supervisor.address) logger.info(tags: [:*, :signal]) { "Handled INT signal (Message Name: #{.}, SupervisorAddress: #{supervisor.address.id})" } end signal.trap 'TERM' do = Actor::Messages::Shutdown send.(, supervisor.address) logger.info(tags: [:*, :signal]) { "Handled TERM signal (Message Name: #{.}, SupervisorAddress: #{supervisor.address.id})" } end start_components do |component| started_components << component end probe.(supervisor) if probe end started_components end |
permalink #start_components(&block) ⇒ Object
[View source]
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/component_host/host.rb', line 82 def start_components(&block) components.each do |component| if ComponentHost::Defaults.startup_info? STDOUT.puts " Component: #{component.initiator} (Name: #{component.name || '(none)'})" end logger.trace(tags: [:component_host, :start]) { "Starting component: #{component.initiator} (Name: #{component.name || '(none)'})" } component.start logger.info(tags: [:component_host, :start]) { "Started component: #{component.initiator} (Name: #{component.name || '(none)'})" } block.(component) if block end rescue => error record_errors_observer.(error) logger.fatal(tags: [:*, :component_host, :start]) { "#{error.} (Error: #{error.class})" } raise error end |