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("")) {
|
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);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user