Skip to content

Commit

Permalink
Make sure IPs are only sent once when sending to ArrayPort on a subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
kenhkan committed Aug 19, 2012
1 parent 3604097 commit ff09619
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/Graph.coffee
Expand Up @@ -53,8 +53,12 @@ class Graph extends noflo.Component
return true

replicatePort: (port) ->
# Designate the destination port as a link to avoid sending multiple IPs
port.isLink = true

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
newPort.on "attach", (socket) ->
Expand Down
20 changes: 20 additions & 0 deletions src/lib/ArrayPort.coffee
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit ff09619

Please sign in to comment.