executor 2 change #33

Merged
rahimiankeanu merged 1 commits from executor1_input_arguments into dev 2021-11-08 13:05:46 +00:00
4 changed files with 25 additions and 12 deletions

View File

@ -46,8 +46,8 @@ public class GetAssignmentAdapter implements GetAssignmentPort {
if (response.body().equals("")) {
return null;
}
return new Task(new JSONObject(response.body()).getString("taskID"));
JSONObject responseBody = new JSONObject(response.body());
return new Task(responseBody.getString("taskID"), responseBody.getString("input"));
} catch (IOException | InterruptedException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);

View File

@ -61,7 +61,7 @@ public abstract class ExecutorBase {
System.out.println("Starting execution");
this.status = ExecutorStatus.EXECUTING;
task.setResult(execution());
task.setResult(execution(task.getInput()));
executionFinishedEventPort.publishExecutionFinishedEvent(
new ExecutionFinishedEvent(task.getTaskID(), task.getResult(), "SUCCESS"));
@ -70,6 +70,6 @@ public abstract class ExecutorBase {
getAssignment();
}
protected abstract String execution();
protected abstract String execution(String... input);
}

View File

@ -12,8 +12,12 @@ public class Task {
@Setter
private String result;
public Task(String taskID) {
@Getter
private String[] input;
public Task(String taskID, String... input) {
this.taskID = taskID;
this.input = input;
}
}

View File

@ -18,19 +18,28 @@ public class Executor extends ExecutorBase {
@Override
protected
String execution() {
String execution(String... input) {
double result = Double.NaN;
int a = Integer.parseInt(input[0]);
int b = Integer.parseInt(input[2]);
String operation = input[1];
int a = 20;
int b = 20;
try {
TimeUnit.SECONDS.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
int result = a + b;
if (operation == "+") {
result = a + b;
} else if (operation == "*") {
result = a * b;
} else if (operation == "-") {
result = a - b;
}
return Integer.toString(result);
return Double.toString(result);
}
}