Class: FFWD::Core
- Inherits:
-
Object
- Object
- FFWD::Core
- Defined in:
- lib/ffwd/core.rb,
lib/ffwd/core/emitter.rb,
lib/ffwd/core/reporter.rb,
lib/ffwd/core/interface.rb,
lib/ffwd/core/processor.rb
Defined Under Namespace
Classes: Emitter, Interface, Processor, Reporter
Instance Method Summary collapse
-
#initialize(plugins, opts = {}) ⇒ Core
constructor
A new instance of Core.
-
#run ⇒ Object
Main entry point.
Methods included from Logging
Methods included from Lifecycle
#depend_on, #start, #started?, #starting, #starting_hooks, #stop, #stopped?, #stopping, #stopping_hooks
Constructor Details
#initialize(plugins, opts = {}) ⇒ Core
Returns a new instance of Core.
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ffwd/core.rb', line 40 def initialize plugins, opts={} @tunnel_plugins = plugins[:tunnel] || [] @input_plugins = plugins[:input] || [] @output_plugins = plugins[:output] || [] @statistics_opts = opts[:statistics] @debug_opts = opts[:debug] @core_opts = opts[:core] || {} @processors = FFWD::Processor.load_processors(opts[:processor] || {}) @output_channel = FFWD::PluginChannel.build 'core.output' @input_channel = FFWD::PluginChannel.build 'core.input' @system_channel = Channel.new log, "system_channel" memory_config = (@core_opts[:memory] || {}) @memory_limit = (memory_config[:limit] || 1000).to_f.round(3) @memory_limit95 = @memory_limit * 0.95 if @memory_limit < 0 raise "memory limit must be non-negative number" end @emitter = Core::Emitter.build @output_channel, @core_opts @processor = Core::Processor.build @input_channel, @emitter, @processors @debug = nil if @debug_opts @debug = FFWD::Debug.setup @debug_opts @debug.monitor @input_channel, FFWD::Debug::Input @debug.monitor @output_channel, FFWD::Debug::Output @debug.depend_on self end # Configuration for statistics module. @statistics = nil if config = @statistics_opts @statistics = FFWD::Statistics::Collector.build( @emitter, @system_channel, config) @statistics.depend_on self end @interface = Core::Interface.new( @input_channel, @output_channel, @tunnel_plugins, @statistics, @debug, @processors, @core_opts ) @interface.depend_on self @input_instances = @input_plugins.map do |factory| factory.call @interface end @output_instances = @output_plugins.map do |factory| factory.call @interface end unless @statistics.nil? reporters = [@input_channel, @output_channel, @processor] reporters += @input_instances.select{|i| FFWD.is_reporter?(i)} reporters += @output_instances.select{|i| FFWD.is_reporter?(i)} @statistics.register self, "core", Core::Reporter.new(reporters) end # Make the core-related channels depend on core. # They will then be orchestrated with core when it's being # started/stopped. @input_channel.depend_on self @output_channel.depend_on self end |
Instance Method Details
#run ⇒ Object
Main entry point.
Since all components are governed by the lifecycle of core, it should mostly be a matter of calling ‘start’.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/ffwd/core.rb', line 117 def run # What to do when we receive a shutdown signal? shutdown_handler = proc do # Hack to get out of trap context and into EM land. EM.add_timer(0) do log.info "Shutting down" stop EM.stop end end EM.run do Signal.trap("INT", &shutdown_handler) Signal.trap("TERM", &shutdown_handler) start setup_memory_monitor end stopping do end end |