lib/rflow/component/port.rb in rflow-1.0.0a5 vs lib/rflow/component/port.rb in rflow-1.0.0a6
- old
+ new
@@ -79,16 +79,18 @@
# Adds a connection for a given key
def add_connection(key, connection)
RFlow.logger.debug "Attaching #{connection.class.name} connection '#{connection.name}' (#{connection.uuid}) to port '#{name}' (#{uuid}), key '#{connection.input_port_key}'"
connections_for[key] << connection
+ @all_connections = nil
end
# Removes a connection from a given key
def remove_connection(key, connection)
RFlow.logger.debug "Removing #{connection.class.name} connection '#{connection.name}' (#{connection.uuid}) from port '#{name}' (#{uuid}), key '#{connection.input_port_key}'"
connections_for[key].delete(connection)
+ @all_connections = nil
end
def collect_messages(key, receiver)
begin
connection = RFlow::MessageCollectingConnection.new.tap do |c|
@@ -128,26 +130,26 @@
# Should be overridden. Called when it is time to actually
# establish the connection
def connect!; raise NotImplementedError, "Raw ports do not know which direction to connect"; end
- private
def all_connections
@all_connections ||= connections_for.values.flatten.uniq.extend(ConnectionCollection)
end
end
class InputPort < HashPort
def connect!
- connections_for.each do |key, connections|
- connections.each do |connection|
- connection.connect_input!
- @connected = true
- end
- end
+ connections_for.each {|key, conns| conns.each {|c| c.connect_input! } }
+ @connected = true
end
+ def add_connection(key, connection)
+ super
+ connection.connect_input! if connected?
+ end
+
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
@@ -157,15 +159,16 @@
end
end
class OutputPort < HashPort
def connect!
- connections_for.each do |key, connections|
- connections.each do |connection|
- connection.connect_output!
- @connected = true
- end
- end
+ connections_for.each {|key, conns| conns.each {|c| c.connect_output! } }
+ @connected = true
+ end
+
+ def add_connection(key, connection)
+ super
+ connection.connect_output! if connected?
end
# Send a message to all connections on all keys for this port,
# but only once per connection.
def send_message(message)