Example #1
0
def sched(ch, graph):
    """Sits in an infinite loop waiting on the channel to receive data.

    The procedure prolog takes care of sorting the
    input graph into a dependency list and initializing
    the filter tasklets used to construct the graph.

    @param graph: The graph representing the work flow
    @type graph: Python dict organized as a graph struct
    @param ch: The stackless channel to listen on
    @type ch: stackless.channel
    @return: nothing
    """
    # Added so that incoming data is fed to every input adapter
    # should check if in exists and create it if it doesn't
    # because a user could remove the input port by accident
    nodes = connect_graph_components(graph)
    tasks = schedule_recursively(nodes)
    inputEdges = []
    # Connect all the adapters to the input
    for node in nodes:
        if node.get_type() == 'ADAPTER':
            ie = Pype()
            node.connect_input('in', ie)
            inputEdges.append(ie)

    while True:
        data = ch.receive()
        for ie in inputEdges:
            ie.send(data)
        try:
            tasks[0].run()
        except:
            traceback.print_exc()
Example #2
0
def sched(ch, graph):
    """Sits in an infinite loop waiting on the channel to receive data.

    The procedure prolog takes care of sorting the
    input graph into a dependency list and initializing
    the filter tasklets used to construct the graph.

    @param graph: The graph representing the work flow
    @type graph: Python dict organized as a graph struct
    @param ch: The stackless channel to listen on
    @type ch: stackless.channel
    @return: nothing
    """
    # Added so that incoming data is fed to every input adapter
    # should check if in exists and create it if it doesn't
    # because a user could remove the input port by accident
    nodes = connect_graph_components(graph)
    tasks = schedule_recursively(nodes)
    inputEdges = []
    # Connect all the adapters to the input
    for node in nodes:
        if node.get_type() == 'ADAPTER':
            ie = Pype()
            node.connect_input('in', ie)
            inputEdges.append(ie)

    while True:
        data = ch.receive()
        for ie in inputEdges:
            ie.send(data)
        try:
            tasks[0].run()
        except:
            traceback.print_exc()
Example #3
0
def connect_graph_components(graph):
    """Sort the components and connect the output of a component to the
    input of the next.

    @param graph: The graph representing the work flow
    @type graph: Python dict organized as a graph struct
    @return nodes: The sorted nodes in the graph

    """
    edgeList = get_pairlist(graph)
    nodes = topsort(edgeList)
    pipes = []

    for n in nodes:
        try:
            # get this nodes outputs
            edges = graph[n]
        except:
            pass
        else:
            # for each output
            for e in edges:
                pipe = Pype()
                pipes.append(pipe)
                # does the output port exist?
                if not n.has_port(edges[e][0]):
                    raise ComponentPortError('''Trying to connect undefined
                           output port {0} {1}'''.format(n, edges[e][0]))
                else:
                    n.connect_output(edges[e][0], pipe)

                # does the input port exist?
                if not e.has_port(edges[e][1]):
                    raise ComponentPortError('''Trying to connect undefined
                           input port {0} {1}'''.format(e, edges[e][1]))
                else:
                    e.connect_input(edges[e][1], pipe)
    return nodes
    if hello.has_port('test1'):
        print 'Description for port "test1" -->', \
                                hello.get_port_description('test1')

    print 'Description for port "out" -->', hello.get_port_description('out')

    if hello.has_port('test2'):
        print 'HelloWorld contains a port called "test2"'
    else:
        print 'HelloWorld does not contain a port called "test2"'

    print 'Connection status for HelloWorld port "out":', \
                                                    hello.is_connected('out')

    # we need two pypes (2 edges)
    p1 = Pype()
    p2 = Pype()

    # A component is written as a stackless tasklet
    # We need to let stackless know. We only need a reference
    # to the first tasklet which is where we will send data
    t = stackless.tasklet(hello.run)()
    stackless.tasklet(printer.run)()

    print 'Connecting ports now...'
    # now we connect the nodes using the pypes we created
    hello.connect_input('in', p1)
    hello.connect_output('out', p2)
    printer.connect_input('in', p2)

    # Now the connection status on "out" should be True since we've just connected it
    print 'Description for port "in" -->', hello.get_port_description("in")

    if hello.has_port("test1"):
        print 'Description for port "test1" -->', hello.get_port_description("test1")

    print 'Description for port "out" -->', hello.get_port_description("out")

    if hello.has_port("test2"):
        print 'HelloWorld contains a port called "test2"'
    else:
        print 'HelloWorld does not contain a port called "test2"'

    print 'Connection status for HelloWorld port "out":', hello.is_connected("out")

    # we need two pypes (2 edges)
    p1 = Pype()
    p2 = Pype()

    # A component is written as a stackless tasklet
    # We need to let stackless know. We only need a reference
    # to the first tasklet which is where we will send data
    t = stackless.tasklet(hello.run)()
    stackless.tasklet(printer.run)()

    print "Connecting ports now..."
    # now we connect the nodes using the pypes we created
    hello.connect_input("in", p1)
    hello.connect_output("out", p2)
    printer.connect_input("in", p2)

    # Now the connection status on "out" should be True since we've just connected it