Class: Langis::Engine::EventMachineEngine
- Inherits:
-
Object
- Object
- Langis::Engine::EventMachineEngine
- Defined in:
- lib/langis/engine.rb
Overview
And EventMachine based implementation of a Langis Engine. Its sole job is to take a pumped message into an intake and broadcast the same message to all of the intake’s registered sinks. In essense these engines need to execute the sinks handler methods for each message.
This class leverages EventMachine’s features to easily do efficient publishing to the subscribers, and uses the EventMachineRunner to do the actual code execution.
Instance Method Summary collapse
-
#initialize(intakes, options = {}) ⇒ EventMachineEngine
constructor
A new instance of EventMachineEngine.
-
#pump(message, *intakes) ⇒ Object
Publishes a message into the Langis publish-subscribe bus.
Constructor Details
#initialize(intakes, options = {}) ⇒ EventMachineEngine
Returns a new instance of EventMachineEngine.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/langis/engine.rb', line 110 def initialize(intakes, ={}) evm_channel_class = [:evm_channel] || EventMachine::Channel @intake_channels = {} intakes.each do |intake_name, apps| = { :success_channel => [:success_channel], :error_channel => [:error_channel], :evm => [:evm], :intake_name => intake_name } @intake_channels[intake_name] = channel = evm_channel_class.new apps.each do |app| channel.subscribe EventMachineRunner.new(app, ) end end end |
Instance Method Details
#pump(message) ⇒ Object #pump(message, ...) ⇒ Object
Publishes a message into the Langis publish-subscribe bus.
137 138 139 140 141 142 143 |
# File 'lib/langis/engine.rb', line 137 def pump(, *intakes) intakes.unshift :default if intakes.empty? intakes.each do |name| channel = @intake_channels[name.to_s] channel.push() if channel end end |