Make sure IPs are only sent once when sending to ArrayPort on a subgraph #41

Closed
wants to merge 2 commits into
from
@@ -54,9 +54,14 @@ class Graph extends noflo.Component
replicatePort: (port) ->
return new noflo.ArrayPort() if port instanceof noflo.ArrayPort
- return new noflo.Port() unless port instanceof noflo.ArrayPort
+ return new noflo.Port() unless port instanceof noflo.ArrayPort
+
replicateInPort: (port, portName) ->
newPort = @replicatePort port
+
+ # Designate the originating port (inside the graph) as a link to avoid sending multiple IPs
+ port.isLink = true
+
newPort.on "attach", (socket) ->
newSocket = noflo.internalSocket.createSocket()
port.attach newSocket
@@ -75,6 +80,10 @@ class Graph extends noflo.Component
replicateOutPort: (port, portName) ->
newPort = @replicatePort port
+
+ # Designate the originating port (inside the graph) as a link to avoid sending multiple IPs
+ newPort.isLink = true
+
newPort.on "attach", (socket) ->
newSocket = noflo.internalSocket.createSocket()
port.attach newSocket
View
@@ -9,6 +9,10 @@ class ArrayPort extends port.Port
@attachSocket socket
connect: (socketId = null) ->
+ # Send only once when this is a linking port between a graph and a subgraph
+ if @isLink
+ socketId = 0
+
if socketId is null
@sockets.forEach (socket) ->
socket.disconnect()
@@ -20,6 +24,10 @@ class ArrayPort extends port.Port
@sockets[socketId].disconnect()
beginGroup: (group, socketId = null) ->
+ # Send only once when this is a linking port between a graph and a subgraph
+ if @isLink
+ socketId = 0
+
if socketId is null
@sockets.forEach (socket, index) =>
@beginGroup group, index
@@ -35,6 +43,10 @@ class ArrayPort extends port.Port
@sockets[socketId].connect()
send: (data, socketId = null) ->
+ # Send only once when this is a linking port between a graph and a subgraph
+ if @isLink
+ socketId = 0
+
if socketId is null
@sockets.forEach (socket, index) =>
@send data, index
@@ -50,6 +62,10 @@ class ArrayPort extends port.Port
@sockets[socketId].connect()
endGroup: (socketId = null) ->
+ # Send only once when this is a linking port between a graph and a subgraph
+ if @isLink
+ socketId = 0
+
if socketId is null
@sockets.forEach (socket, index) =>
@endGroup index
@@ -61,6 +77,10 @@ class ArrayPort extends port.Port
do @sockets[socketId].endGroup
disconnect: (socketId = null) ->
+ # Send only once when this is a linking port between a graph and a subgraph
+ if @isLink
+ socketId = 0
+
if socketId is null
@sockets.forEach (socket) ->
socket.disconnect()