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, &block) ⇒ Object
- #registered?(&block) ⇒ Boolean
- #start(&probe) ⇒ Object
- #start_components(&block) ⇒ Object
Class Method Details
Instance Method Details
#abort ⇒ Object
117 118 119 |
# File 'lib/component_host/host.rb', line 117 def abort raise StopIteration end |
#components ⇒ Object
113 114 115 |
# File 'lib/component_host/host.rb', line 113 def components @components ||= [] end |
#log_observer ⇒ Object
109 110 111 |
# File 'lib/component_host/host.rb', line 109 def log_observer @log_observer ||= SupervisorObservers::Log.new end |
#record_error(&block) ⇒ Object
30 31 32 |
# File 'lib/component_host/host.rb', line 30 def record_error(&block) record_errors_observer.record_error_proc = block end |
#record_errors_observer ⇒ Object
105 106 107 |
# File 'lib/component_host/host.rb', line 105 def record_errors_observer @record_errors_observer ||= SupervisorObservers::RecordErrors.new end |
#register(initiator, name = nil, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/component_host/host.rb', line 16 def register(initiator, name=nil, &block) initiator ||= proc { yield } 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 |
#registered?(&block) ⇒ Boolean
121 122 123 124 125 126 127 |
# File 'lib/component_host/host.rb', line 121 def registered?(&block) block ||= proc { true } components.any? do |component| block.(component.initiator, component.name) end end |
#start(&probe) ⇒ Object
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 81 82 |
# File 'lib/component_host/host.rb', line 34 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 |
#start_components(&block) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/component_host/host.rb', line 84 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 |