Class: RFlow::Components::HTTP::Server
- Inherits:
-
RFlow::Component
- Object
- RFlow::Component
- RFlow::Components::HTTP::Server
- Defined in:
- lib/rflow/components/http/server.rb
Defined Under Namespace
Classes: Connection
Instance Attribute Summary collapse
-
#connections ⇒ Object
Returns the value of attribute connections.
-
#listen ⇒ Object
Returns the value of attribute listen.
-
#port ⇒ Object
Returns the value of attribute port.
-
#server_signature ⇒ Object
Returns the value of attribute server_signature.
Instance Method Summary collapse
- #configure!(config) ⇒ Object
-
#process_message(input_port, input_port_key, connection, message) ⇒ Object
Getting all messages to response_port, which we need to filter for those that pertain to this component and have active connections.
- #run! ⇒ Object
Instance Attribute Details
#connections ⇒ Object
Returns the value of attribute connections.
14 15 16 |
# File 'lib/rflow/components/http/server.rb', line 14 def connections @connections end |
#listen ⇒ Object
Returns the value of attribute listen.
14 15 16 |
# File 'lib/rflow/components/http/server.rb', line 14 def listen @listen end |
#port ⇒ Object
Returns the value of attribute port.
14 15 16 |
# File 'lib/rflow/components/http/server.rb', line 14 def port @port end |
#server_signature ⇒ Object
Returns the value of attribute server_signature.
14 15 16 |
# File 'lib/rflow/components/http/server.rb', line 14 def server_signature @server_signature end |
Instance Method Details
#configure!(config) ⇒ Object
16 17 18 19 20 |
# File 'lib/rflow/components/http/server.rb', line 16 def configure!(config) @listen = config['listen'] ? config['listen'] : '127.0.0.1' @port = config['port'] ? config['port'].to_i : 8000 @connections = Hash.new end |
#process_message(input_port, input_port_key, connection, message) ⇒ Object
Getting all messages to response_port, which we need to filter for those that pertain to this component and have active connections. This is done by inspecting the provenance, specifically the context attribute that we stored originally
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rflow/components/http/server.rb', line 33 def (input_port, input_port_key, connection, ) RFlow.logger.debug "Received a message" return unless .data_type_name == 'RFlow::Message::Data::HTTP::Response' RFlow.logger.debug "Received a HTTP::Response message, determining if its mine" my_events = .provenance.find_all {|processing_event| processing_event.component_instance_uuid == instance_uuid} RFlow.logger.debug "Found #{my_events.size} processing events from me" # Attempt to send the data to each context match my_events.each do |processing_event| RFlow.logger.debug "Inspecting #{processing_event.context}" connection_signature = processing_event.context if connections[connection_signature] RFlow.logger.debug "Found connection for #{processing_event.context}" connections[connection_signature].send_http_response end end end |
#run! ⇒ Object
22 23 24 25 26 27 |
# File 'lib/rflow/components/http/server.rb', line 22 def run! @server_signature = EM.start_server(@listen, @port, Connection) do |conn| conn.server = self self.connections[conn.signature.to_s] = conn end end |