Distributed computing JAVA/JSON
You’re to write a code in Java in which there it implements the following procedures:
(T1 || T2) -> T3 -> T4
T1 := getA
T2 := getB
T3 := add
T4 := printResults
T3.left = T1 (read as T3's "left" input comes from T1's output)
T3.right = T2 (read as T3's "right" input comes from T2's output)
T4.result = T3 (read as T4's "result" input comes fromm T3's output)
“T” stands for transaction, in the above T1 and T2 are done in parallel and their job is to getA and B (in this case they get messages of both A and B).
T3 adds them both together, T4 prints out the results!
The graph representation of those transactions are as shown below
T1 T2
\ /
T3
|
T4
These Tasks can be a separate function to perform certain computation, be it string type computation of integer computation.
The names getA, getB, add, and printResults are user-defined methods/functions that can be included in your runtime.
We will be using messages maps to get our inputs from
Below is an example code of the message map class;
Message getA( Map<String, Message> incoming) {
Message a = new Message();
a.setIntParam("value", 25);
return a;
}
Message getB( Map<String, Message> incoming) {Message b = new Message();b.setIntParam("value", 30);return b;}Message add( Map<String, Message> incoming) {Message left = incoming.get("left");Message right = incoming.get("right");int result = left.getIntParam("value") + right.getIntParam("value");Message result = new Message();result.setIntParam("value", result);return result;}Message printResults( Map<String, Message> incoming) {Message result = incoming.get("result");System.out.println("result = " + result.getIntParam("value");return new Message();}It’s recommended we use JSON for messaging maps.