renaming
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package ch.unisg.executorcomputation;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import ch.unisg.executorcomputation.executor.domain.Executor;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ExecutorcomputationApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ExecutorcomputationApplication.class, args);
|
||||
Executor.getExecutor();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package ch.unisg.executorcomputation.executor.adapter.in.web;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import ch.unisg.executorbase.executor.application.port.in.TaskAvailableCommand;
|
||||
import ch.unisg.executorbase.executor.application.port.in.TaskAvailableUseCase;
|
||||
import ch.unisg.executorbase.executor.domain.ExecutorType;
|
||||
|
||||
@RestController
|
||||
public class TaskAvailableController {
|
||||
private final TaskAvailableUseCase taskAvailableUseCase;
|
||||
|
||||
public TaskAvailableController(TaskAvailableUseCase taskAvailableUseCase) {
|
||||
this.taskAvailableUseCase = taskAvailableUseCase;
|
||||
}
|
||||
|
||||
@GetMapping(path = "/newtask/{taskType}")
|
||||
public ResponseEntity<String> retrieveTaskFromTaskList(@PathVariable("taskType") String taskType) {
|
||||
|
||||
if (ExecutorType.contains(taskType.toUpperCase())) {
|
||||
TaskAvailableCommand command = new TaskAvailableCommand(
|
||||
ExecutorType.valueOf(taskType.toUpperCase()));
|
||||
CompletableFuture.runAsync(() -> taskAvailableUseCase.newTaskAvailable(command));
|
||||
}
|
||||
|
||||
return new ResponseEntity<>("OK", new HttpHeaders(), HttpStatus.OK);
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package ch.unisg.executorcomputation.executor.application.service;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import ch.unisg.executorcomputation.executor.domain.Executor;
|
||||
import ch.unisg.executorbase.executor.application.port.in.TaskAvailableCommand;
|
||||
import ch.unisg.executorbase.executor.application.port.in.TaskAvailableUseCase;
|
||||
import ch.unisg.executorbase.executor.domain.ExecutorStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Component
|
||||
@Transactional
|
||||
public class TaskAvailableService implements TaskAvailableUseCase {
|
||||
|
||||
@Override
|
||||
public void newTaskAvailable(TaskAvailableCommand command) {
|
||||
|
||||
Executor executor = Executor.getExecutor();
|
||||
|
||||
if (executor.getExecutorType() == command.getTaskType() &&
|
||||
executor.getStatus() == ExecutorStatus.IDLING) {
|
||||
executor.getAssignment();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
package ch.unisg.executorcomputation.executor.domain;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import ch.unisg.executorbase.executor.domain.ExecutorBase;
|
||||
import ch.unisg.executorbase.executor.domain.ExecutorType;
|
||||
|
||||
public class Executor extends ExecutorBase {
|
||||
|
||||
private static final Executor executor = new Executor(ExecutorType.ADDITION);
|
||||
|
||||
public static Executor getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
private Executor(ExecutorType executorType) {
|
||||
super(executorType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected
|
||||
String execution(String... input) {
|
||||
|
||||
System.out.println(input);
|
||||
|
||||
double result = Double.NaN;
|
||||
int a = Integer.parseInt(input[0]);
|
||||
int b = Integer.parseInt(input[2]);
|
||||
String operation = input[1];
|
||||
|
||||
// try {
|
||||
// TimeUnit.SECONDS.sleep(20);
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
if (operation == "+") {
|
||||
result = a + b;
|
||||
} else if (operation == "*") {
|
||||
result = a * b;
|
||||
} else if (operation == "-") {
|
||||
result = a - b;
|
||||
}
|
||||
|
||||
System.out.println("finish");
|
||||
|
||||
return Double.toString(result);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1 @@
|
||||
server.port=8085
|
Reference in New Issue
Block a user