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("")) { if (response.body().equals("")) {
return null; return null;
} }
JSONObject responseBody = new JSONObject(response.body());
return new Task(new JSONObject(response.body()).getString("taskID")); return new Task(responseBody.getString("taskID"), responseBody.getString("input"));
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e); logger.log(Level.SEVERE, e.getLocalizedMessage(), e);

View File

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

View File

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

View File

@ -18,19 +18,28 @@ public class Executor extends ExecutorBase {
@Override @Override
protected 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 { try {
TimeUnit.SECONDS.sleep(20); TimeUnit.SECONDS.sleep(20);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); 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);
} }
} }