Class: RFlow::Components::HTTP::Server

Inherits:
RFlow::Component
  • Object
show all
Defined in:
lib/rflow/components/http/server.rb

Defined Under Namespace

Classes: Connection

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectionsObject

Returns the value of attribute connections.



12
13
14
# File 'lib/rflow/components/http/server.rb', line 12

def connections
  @connections
end

#listenObject

Returns the value of attribute listen.



12
13
14
# File 'lib/rflow/components/http/server.rb', line 12

def listen
  @listen
end

#portObject

Returns the value of attribute port.



12
13
14
# File 'lib/rflow/components/http/server.rb', line 12

def port
  @port
end

#server_signatureObject

Returns the value of attribute server_signature.



12
13
14
# File 'lib/rflow/components/http/server.rb', line 12

def server_signature
  @server_signature
end

Instance Method Details

#configure!(config) ⇒ Object



14
15
16
17
18
# File 'lib/rflow/components/http/server.rb', line 14

def configure!(config)
  @listen = config['listen'] ? config['listen'] : '127.0.0.1'
  @port = config['port'] ? config['port'].to_i : 8000
  @connections = {}
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



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rflow/components/http/server.rb', line 32

def process_message(input_port, input_port_key, connection, message)
  return unless message.data_type_name == 'RFlow::Message::Data::HTTP::Response'
  my_events = message.provenance.find_all {|processing_event| processing_event.component_instance_uuid == uuid}

  my_events.each do |processing_event|
    connection_signature_string = processing_event.context.to_s
    if connections[connection_signature_string]
      connections[connection_signature_string].send_http_response message
    end
  end
end

#run!Object



20
21
22
23
24
25
26
# File 'lib/rflow/components/http/server.rb', line 20

def run!
  @server_signature = EM.start_server(@listen, @port, Connection) do |conn|
    conn.server = self
    self.connections[conn.signature.to_s] = conn
    RFlow.logger.debug { "#{name}: Connection from #{conn.client_ip}:#{conn.client_port} to #{conn.server_ip}:#{conn.server_port}" }
  end
end