2.2.6. Main Node

This kind of Node performs the active (client) action of Workload Distribution Scenario. This node is able to send different Jobs serialized as Job Data Type and it receives a Solution once the task has been executed as Job Solution Data Type.

2.2.6.1. Synchronous

This node kind does require active interaction with the user to perform its action. This means that once a job is sent, the thread must wait for the solution to arrive before sending another task. Users can use method request_job_solution to send a new Job. The thread calling this method will wait until the whole process has finished and the Solution has arrived from the Computing Node in charge of this Job. By destroying the node every internal entity is correctly destroyed.

2.2.6.1.1. Steps

  • Instantiate the Main Node creating an object of such class with a name.

  • Create a new JobDataType from an array of bytes.

  • Send a new Job synchronously and wait for the solution by calling request_job_solution.

// Create a new Main Node
auto node = eprosima::amlip::MainNode("My_Main_Node");

// Create a new job to be executed remotely
auto new_job = eprosima::amlip::JobDataType("Some Job as byte array serialized from a string");

// Send a Job to a remote Computing and waits for the answer
// This could be called with an id as well, and it will return the server id that send the solution
auto solution = node.request_job_solution(new_job);

2.2.6.2. Asynchronous

Users can use method request_job_solution to send a new Job. The thread calling this method must wait until the whole process has finished and the Solution has arrived from the Computing Node in charge of this data that will process it by the Listener or callback given, and return the Solution calculated in other thread. By destroying the node every internal entity is correctly destroyed.

2.2.6.2.1. Steps

  • Instantiate the Asynchronous Main Node creating an object of such class with a name, a listener or callback and a domain.

  • Create a new JobDataType from an array of bytes.

  • Send a new Job synchronously and wait for the solution by calling request_job_solution.

  • Wait for the solution.

def solution_received(
        solution,
        task_id,
        server_id):
    print(f'Solution received from server: {server_id}\n'
        f' with id: {task_id}\n'
        f' solution: {solution.to_string()}')

def main():
    # Create a new Async Main Node
    node = AsyncMainNode(
        'MyAsyncMainNode',
        callback=solution_received,
        domain=100)

    # Create new data to be executed remotely
    data_str = '<Job Data In Py String Async [LAMBDA]>'
    job_data = JobDataType(data_str)

    # Send data to a remote Computing Node and waits for the solution
    task_id = main_node.request_job_solution(job_data)

    # User must wait to receive solution.
    # Out of scope, the node will be destroyed,
    # and thus the solution will not arrive.