Class: RFlow::Component::InputPort

Inherits:
HashPort show all
Defined in:
lib/rflow/component/port.rb

Overview

An actual RFlow::Component input port.

Instance Attribute Summary

Attributes inherited from HashPort

#name, #uuid

Attributes inherited from Port

#component, #connected

Instance Method Summary collapse

Methods inherited from HashPort

#[], #all_connections, #collect_messages, #connections_for, #direct_connect, #each, #initialize, #keys, #remove_connection, #send_message

Methods inherited from Port

#connected?, #initialize

Constructor Details

This class inherits a constructor from RFlow::Component::HashPort

Instance Method Details

#add_connection(key, connection) ⇒ void

This method returns an undefined value.

Add and start up a new RFlow::Connection.

Parameters:

  • key (String)

    the key to subscript with

  • connection (Connection)

    the connection to add



253
254
255
256
# File 'lib/rflow/component/port.rb', line 253

def add_connection(key, connection)
  super
  connection.connect_input! if connected?
end

#connect!void

This method returns an undefined value.

Connect all the input connections, once everything’s been set up.



244
245
246
247
# File 'lib/rflow/component/port.rb', line 244

def connect!
  @connections_for.each {|key, conns| conns.each {|c| c.connect_input! } }
  @connected = true
end

#recv_callback=(callback) ⇒ void

This method returns an undefined value.

Once things have been set up, registering the receive callback will set it on all connections, so that when messages are received, they are delivered on all connections with appropriate key and connection information from the context of the connection.

Parameters:

  • callback (Proc)

    the receive callback



264
265
266
267
268
269
270
271
272
# File 'lib/rflow/component/port.rb', line 264

def recv_callback=(callback)
  @connections_for.each do |key, connections|
    connections.each do |connection|
      connection.recv_callback = Proc.new do |message|
        callback.call self, key, connection, message
      end
    end
  end
end