2.2.4. Computing Node

This kind of Node performs the passive (server) action of Workload Distribution Scenario. This node waits for a Job serialized as Job Data Type, and once received it performs a calculation (implemented by the user) whose output is the solution as Job Solution Data Type.

2.2.4.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. User 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.4.1.1. Steps

  • Instantiate the Computing 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 Computing Node
auto node = eprosima::amlip::ComputingNode("My_Computing_Node");

// Create a callback to process a job and return a solution
auto process_solution = []( const eprosima::amlip::types::JobDataType& ){
    eprosima::amlip::types::JobSolutionDataType solution;
    // Do some code that calculates the solution
    return solution;
};

// Wait for 1 task from any client and answer it with process_solution callback
node.process_job(process_solution);

2.2.4.2. Asynchronous

User can use method request_job_solution to send a new Job from Main Node to send new data. 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.4.2.1. Steps

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

  • Wait for tasks by calling run.

def process_job(
        job,
        task_id,
        client_id):
    JobSolutionDataType solution;
    # Do some code that calculates the solution
    return solution

# Create a new Async Computing Node
node = AsyncComputingNode(
    'MyAsyncComputingNode',
    callback=process_job,
    domain=100)

node.run()

# Wait until Ctrl+C

node.stop()