Browse Source

first commit

placidenduwayo 1 year ago
parent
commit
26c672a406

src/main/java/fr/natan/akkastreamfileprocessingapi/controller/MovieController.java → src/main/java/fr/natan/akkastreamfileprocessingapi/controller/TvSeriesController.java View File

25
 
25
 
26
 @SuppressWarnings("SpellCheckingInspection")
26
 @SuppressWarnings("SpellCheckingInspection")
27
 @RestController
27
 @RestController
28
-public class MovieController {
28
+public class TvSeriesController {
29
 
29
 
30
     private final AkkaStreamFileProcessing akkaStreamFilesProcessing;
30
     private final AkkaStreamFileProcessing akkaStreamFilesProcessing;
31
-    private final CompletableFutureResult completableFutureResult = new CompletableFutureResult();
32
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
31
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
33
-    private static final int BORN_INF = 1000, BORN_SUP = 5000;
32
+    private static final int BORN_INF = 500, BORN_SUP = 5000;
34
 
33
 
35
-    public MovieController(AkkaStreamFileProcessing akkaStreamFilesProcessing) {
34
+    public TvSeriesController(AkkaStreamFileProcessing akkaStreamFilesProcessing) {
36
         this.akkaStreamFilesProcessing = akkaStreamFilesProcessing;
35
         this.akkaStreamFilesProcessing = akkaStreamFilesProcessing;
37
     }
36
     }
38
 
37
 
39
     @RequestMapping(value = "/persons/id/{personID}", method = RequestMethod.GET)
38
     @RequestMapping(value = "/persons/id/{personID}", method = RequestMethod.GET)
40
-    private ResponseEntity<String> getPersonByID(@PathVariable(name = "personID") String personID) throws ExecutionException, InterruptedException {
39
+    private String getPersonByID(@PathVariable(name = "personID") String personID) throws ExecutionException, InterruptedException {
41
         Future<Models.Person> futurePerson = akkaStreamFilesProcessing.getPersonById(personID);
40
         Future<Models.Person> futurePerson = akkaStreamFilesProcessing.getPersonById(personID);
42
-        CompletableFuture<Models.Person> completableFuture = completableFutureResult.buildcompletableFuture(futurePerson);
41
+        CompletableFuture<Models.Person> completableFuture = CompletableFutureResult.buildcompletableFuture1(futurePerson);
43
         while (!completableFuture.isDone()) {
42
         while (!completableFuture.isDone()) {
44
             logger.info("IS PROCESSING...");
43
             logger.info("IS PROCESSING...");
45
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
44
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
46
         }
45
         }
47
         Models.Person person = completableFuture.get();
46
         Models.Person person = completableFuture.get();
48
-        return new ResponseEntity<>(Json.toJson(person, person.personFormat()).toString(), HttpStatus.OK);
47
+
48
+        return Json.toJson(person, person.personFormat()).toString();
49
     }
49
     }
50
 
50
 
51
     @RequestMapping(value = "/persons/name/{primaryName}", method = RequestMethod.GET)
51
     @RequestMapping(value = "/persons/name/{primaryName}", method = RequestMethod.GET)
52
-    private ResponseEntity<String> getPersonByName(@PathVariable(name = "primaryName") String primaryName)
52
+    private String getPersonByName(@PathVariable(name = "primaryName") String primaryName)
53
             throws ExecutionException, InterruptedException {
53
             throws ExecutionException, InterruptedException {
54
 
54
 
55
         Future<Models.Person> personFuture = akkaStreamFilesProcessing.getPersonByName(primaryName);
55
         Future<Models.Person> personFuture = akkaStreamFilesProcessing.getPersonByName(primaryName);
56
-        CompletableFuture<Models.Person> personCompletableFuture = completableFutureResult.buildcompletableFuture(personFuture);
56
+        CompletableFuture<Models.Person> personCompletableFuture = CompletableFutureResult.buildcompletableFuture1(personFuture);
57
         while (!personCompletableFuture.isDone()) {
57
         while (!personCompletableFuture.isDone()) {
58
             logger.info("IS PROCESSING...");
58
             logger.info("IS PROCESSING...");
59
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
59
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
60
         }
60
         }
61
         Models.Person person = personCompletableFuture.get();
61
         Models.Person person = personCompletableFuture.get();
62
-        return new ResponseEntity<>(Json.toJson(person, person.personFormat()).toString(), HttpStatus.OK);
62
+        return Json.toJson(person, person.personFormat()).toString();
63
     }
63
     }
64
 
64
 
65
     @RequestMapping(value = "/tvseries/id/{tvSerieId}", method = RequestMethod.GET)
65
     @RequestMapping(value = "/tvseries/id/{tvSerieId}", method = RequestMethod.GET)
66
-    private ResponseEntity<String> getTvSerieByID(@PathVariable(name = "tvSerieId") String tvSerieID)
66
+    private String getTvSerieByID(@PathVariable(name = "tvSerieId") String tvSerieID)
67
             throws ExecutionException, InterruptedException {
67
             throws ExecutionException, InterruptedException {
68
         Future<Models.TvSerie> tvSerieFuture = akkaStreamFilesProcessing.getTvSerieById(tvSerieID);
68
         Future<Models.TvSerie> tvSerieFuture = akkaStreamFilesProcessing.getTvSerieById(tvSerieID);
69
-        CompletableFuture<Models.TvSerie> tvSerieCompletableFuture = completableFutureResult.buildcompletableFuture(tvSerieFuture);
69
+        CompletableFuture<Models.TvSerie> tvSerieCompletableFuture = CompletableFutureResult.buildcompletableFuture1(tvSerieFuture);
70
         while (!tvSerieCompletableFuture.isDone()) {
70
         while (!tvSerieCompletableFuture.isDone()) {
71
             logger.info("IS PROCESSING...");
71
             logger.info("IS PROCESSING...");
72
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
72
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
73
         }
73
         }
74
         Models.TvSerie tvSerie = tvSerieCompletableFuture.get();
74
         Models.TvSerie tvSerie = tvSerieCompletableFuture.get();
75
-        return new ResponseEntity<>(Json.toJson(tvSerie, tvSerie.tvSerieFormat()).toString(), HttpStatus.OK);
75
+        return Json.toJson(tvSerie, tvSerie.tvSerieFormat()).toString();
76
     }
76
     }
77
 
77
 
78
     @RequestMapping(value = "/tvseries/title/{tvseriePrimaryTitle}", method = RequestMethod.GET)
78
     @RequestMapping(value = "/tvseries/title/{tvseriePrimaryTitle}", method = RequestMethod.GET)
81
 
81
 
82
         Future<IndexedSeq<Models.TvSerie>> listFuture = akkaStreamFilesProcessing.getTvSerieByPrimaryTitle(tvseriePrimaryTitle);
82
         Future<IndexedSeq<Models.TvSerie>> listFuture = akkaStreamFilesProcessing.getTvSerieByPrimaryTitle(tvseriePrimaryTitle);
83
         CompletableFuture<IndexedSeq<Models.TvSerie>> completableFuture =
83
         CompletableFuture<IndexedSeq<Models.TvSerie>> completableFuture =
84
-                completableFutureResult.buildcompletableFuture_(listFuture);
84
+                CompletableFutureResult.buildcompletableFuture2(listFuture);
85
         while (!completableFuture.isDone()) {
85
         while (!completableFuture.isDone()) {
86
             logger.info("IS PROCESSING...");
86
             logger.info("IS PROCESSING...");
87
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
87
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
94
             return null;
94
             return null;
95
         });
95
         });
96
 
96
 
97
-        return tvSeries;
97
+      return tvSeries;
98
     }
98
     }
99
 
99
 
100
-    ;
101
-
102
     @RequestMapping(value = "/persons/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
100
     @RequestMapping(value = "/persons/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
103
     private List<String> getPersonsForTvSerie(@PathVariable(name = "tvSerieTitle") String tvSerieTitle)
101
     private List<String> getPersonsForTvSerie(@PathVariable(name = "tvSerieTitle") String tvSerieTitle)
104
             throws InterruptedException, ExecutionException {
102
             throws InterruptedException, ExecutionException {
105
 
103
 
106
         Future<IndexedSeq<Models.Person>> futurePersonSeq = akkaStreamFilesProcessing.getTeamOfPersonsForTvSerie(tvSerieTitle);
104
         Future<IndexedSeq<Models.Person>> futurePersonSeq = akkaStreamFilesProcessing.getTeamOfPersonsForTvSerie(tvSerieTitle);
107
-        CompletableFuture<IndexedSeq<Models.Person>> completableFuture = completableFutureResult.buildcompletableFuture_(futurePersonSeq);
105
+        CompletableFuture<IndexedSeq<Models.Person>> completableFuture = CompletableFutureResult.buildcompletableFuture2(futurePersonSeq);
108
         while (!completableFuture.isDone()){
106
         while (!completableFuture.isDone()){
109
             logger.info("IS PROCESSING...");
107
             logger.info("IS PROCESSING...");
110
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
108
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);

+ 2
- 4
src/main/java/fr/natan/akkastreamfileprocessingapi/futurecompleteness/CompletableFutureResult.java View File

2
 
2
 
3
 
3
 
4
 import scala.collection.IndexedSeq;
4
 import scala.collection.IndexedSeq;
5
-import scala.collection.immutable.List;
6
 import scala.concurrent.Future;
5
 import scala.concurrent.Future;
7
 
6
 
8
 import java.util.concurrent.CompletableFuture;
7
 import java.util.concurrent.CompletableFuture;
12
 
11
 
13
 public class CompletableFutureResult<T> {
12
 public class CompletableFutureResult<T> {
14
 
13
 
15
-    public CompletableFuture<T> buildcompletableFuture(Future<T> futureT) {
14
+    public static<T> CompletableFuture<T> buildcompletableFuture1(Future<T> futureT) {
16
         CompletableFuture<T> completableFuture = new CompletableFuture<>();
15
         CompletableFuture<T> completableFuture = new CompletableFuture<>();
17
        Executors.newSingleThreadExecutor().submit(() -> {
16
        Executors.newSingleThreadExecutor().submit(() -> {
18
            while(!futureT.isCompleted()){
17
            while(!futureT.isCompleted()){
25
         return completableFuture;
24
         return completableFuture;
26
     }
25
     }
27
 
26
 
28
-
29
-    public CompletableFuture<IndexedSeq<T>> buildcompletableFuture_(Future<IndexedSeq<T>> futureListT) {
27
+    public static<T> CompletableFuture<IndexedSeq<T>> buildcompletableFuture2(Future<IndexedSeq<T>> futureListT) {
30
         CompletableFuture<IndexedSeq<T>> completableFuture = new CompletableFuture<>();
28
         CompletableFuture<IndexedSeq<T>> completableFuture = new CompletableFuture<>();
31
         Executors.newSingleThreadExecutor().submit(() -> {
29
         Executors.newSingleThreadExecutor().submit(() -> {
32
             while(!futureListT.isCompleted()){
30
             while(!futureListT.isCompleted()){

+ 0
- 1
src/main/scala/fr/natan/akkastreamfileprocessingapi/service/AkkaStreamFileProcessingImpl.scala View File

11
 import org.slf4j.LoggerFactory
11
 import org.slf4j.LoggerFactory
12
 import org.springframework.stereotype.Component
12
 import org.springframework.stereotype.Component
13
 
13
 
14
-import scala.collection.mutable.ListBuffer
15
 import scala.concurrent.ExecutionContext.Implicits.global
14
 import scala.concurrent.ExecutionContext.Implicits.global
16
 import scala.concurrent.Future
15
 import scala.concurrent.Future
17
 import scala.language.postfixOps
16
 import scala.language.postfixOps

Powered by TurnKey Linux.