Merge pull request #33 from SCS-ASSE-FS21-Group1/executor1_input_arguments
executor 2 change
This commit is contained in:
commit
615fb0cec0
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user