refactored executor1 to have base classes in own project
This commit is contained in:
@@ -40,6 +40,11 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.unisg</groupId>
|
||||
<artifactId>executorBase</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@@ -3,11 +3,14 @@ package ch.unisg.executor2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import ch.unisg.executor2.executor.domain.Executor;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Executor2Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Executor2Application.class, args);
|
||||
Executor.getExecutor();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,12 +0,0 @@
|
||||
package ch.unisg.executor2;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class TestController {
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
return "Hello World! Executor2";
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package ch.unisg.executor2.executor.application.service;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import ch.unisg.executor2.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,36 @@
|
||||
package ch.unisg.executor2.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() {
|
||||
|
||||
int a = 20;
|
||||
int b = 20;
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
int result = a + b;
|
||||
|
||||
return Integer.toString(result);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user