예제 #1
0
    def run(self):
        logging.info("Running process on {0}:{1}".format(self.host, self.port))
        self.finished_execution = False
        self.wait = True
        create_server_thread(self.host, self.port, self.input_queue, self.finished_execution)
        logging.info("Server created. Listening on {0}:{1}".format(self.host, self.port))

        threading.Thread(target=self.runCommands).start()

        self.input_streams = [Stream(name) for name in self.input_stream_names]
        self.output_streams = [Stream(name) for name in self.output_stream_names]
        self.map_name_to_input_stream = dict()
        for stream in self.input_streams:
            self.map_name_to_input_stream[stream.name] = stream
        # Call the function that creates a network of agents that
        # map input streams to output streams.

        while self.wait:
            pass

        self.func(self.input_streams, self.output_streams)

        self.make_output_manager()
        self.make_input_manager()
예제 #2
0
def make_process(
        input_stream_names, output_stream_names, func,
        input_queue, output_conn_list, host, port):
    """ Makes a process that gets messages on its single
    input queue, processes the messages and puts messages
    on its output queues. An output queue of this process
    is an input queue of another process.

    Parameters
    ----------
    input_stream_names : list of str
             List of names of input streams
    output_stream_names : list of str
             List of names of output streams
    func : function
           The parameters of func are
                input_streams, output_streams where
            input_streams is a list of streams whose names
            are in input_stream_names and where
            output_streams is a list of streams whose names
            are in output_stream_names. func gets messages
            on its input streams and puts messages on its
            output streams.
    input_queue: multiprocessing.Queue
            Each process has a single input queue along
            which it receives messages.
    output_queues_list : list of list of multiprocessing.Queue
            output_queues_list[j] is the list of queues to
            which messages that appear on the stream with name
            output_stream_names[j] should be sent.

    Returns
    -------
          None
    Attributes
    ----------
    input_streams : list of Stream
           input_stream[j] is the Stream with name
           input_stream_name[j].
    output_streams : list of Stream
           output_stream[j] is the Stream with name
           output_stream_name[j].
    map_name_to_input_stream : dict
           key : str
                 name of an input stream
           value : Stream
                 The stream with the specified name.

    Notes
    -----
    make_process carries out the following steps:
    (1) Sets up data structures for the next two steps.
    (2) Calls func which creates the network of agents
    that process messages on its input streams and puts
    messages on its output streams.
    (3) Makes the output and input managers.


    """
    logging.info("Running process on {0}:{1}".format(host, port))
    finished_execution = False
    create_server_thread(host, port, input_queue, finished_execution)
    logging.info("Server created. Listening on {0}:{1}".format(host, port))
    # Create input_streams, output_streams and
    # map_name_to_input_stream
    input_streams = [Stream(name) for name in input_stream_names]
    output_streams = [Stream(name) for name in output_stream_names]
    map_name_to_input_stream = dict()
    for stream in input_streams:
        map_name_to_input_stream[stream.name] = stream
    # Call the function that creates a network of agents that
    # map input streams to output streams.
    func(input_streams, output_streams)

    make_output_manager(output_streams, output_conn_list)
    make_input_manager(input_queue, input_streams, map_name_to_input_stream, finished_execution)
예제 #3
0
def make_process(
        input_stream_names, output_stream_names, func,
        input_queue, output_conn_list, host, port):
    """ Makes a process that gets messages on its single
    input queue, processes the messages and puts messages
    on its output queues. An output queue of this process
    is an input queue of another process.

    Parameters
    ----------
    input_stream_names : list of str
             List of names of input streams
    output_stream_names : list of str
             List of names of output streams
    func : function
           The parameters of func are
                input_streams, output_streams where
            input_streams is a list of streams whose names
            are in input_stream_names and where
            output_streams is a list of streams whose names
            are in output_stream_names. func gets messages
            on its input streams and puts messages on its
            output streams.
    input_queue: multiprocessing.Queue
            Each process has a single input queue along
            which it receives messages.
    output_queues_list : list of list of multiprocessing.Queue
            output_queues_list[j] is the list of queues to
            which messages that appear on the stream with name
            output_stream_names[j] should be sent.

    Returns
    -------
          None
    Attributes
    ----------
    input_streams : list of Stream
           input_stream[j] is the Stream with name
           input_stream_name[j].
    output_streams : list of Stream
           output_stream[j] is the Stream with name
           output_stream_name[j].
    map_name_to_input_stream : dict
           key : str
                 name of an input stream
           value : Stream
                 The stream with the specified name.

    Notes
    -----
    make_process carries out the following steps:
    (1) Sets up data structures for the next two steps.
    (2) Calls func which creates the network of agents
    that process messages on its input streams and puts
    messages on its output streams.
    (3) Makes the output and input managers.


    """
    logging.info("Running process on {0}:{1}".format(host, port))
    finished_execution = False
    create_server_thread(host, port, input_queue, finished_execution)
    logging.info("Server created. Listening on {0}:{1}".format(host, port))
    # Create input_streams, output_streams and
    # map_name_to_input_stream
    input_streams = [Stream(name) for name in input_stream_names]
    output_streams = [Stream(name) for name in output_stream_names]
    map_name_to_input_stream = dict()
    for stream in input_streams:
        map_name_to_input_stream[stream.name] = stream
    # Call the function that creates a network of agents that
    # map input streams to output streams.
    func(input_streams, output_streams)

    make_output_manager(output_streams, output_conn_list)
    make_input_manager(input_queue, input_streams, map_name_to_input_stream, finished_execution)