placidenduwayo 2 年 前
コミット
26c672a406

src/main/java/fr/natan/akkastreamfileprocessingapi/controller/MovieController.java → src/main/java/fr/natan/akkastreamfileprocessingapi/controller/TvSeriesController.java ファイルの表示

@@ -25,54 +25,54 @@ import java.util.concurrent.ExecutionException;
25 25
 
26 26
 @SuppressWarnings("SpellCheckingInspection")
27 27
 @RestController
28
-public class MovieController {
28
+public class TvSeriesController {
29 29
 
30 30
     private final AkkaStreamFileProcessing akkaStreamFilesProcessing;
31
-    private final CompletableFutureResult completableFutureResult = new CompletableFutureResult();
32 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 35
         this.akkaStreamFilesProcessing = akkaStreamFilesProcessing;
37 36
     }
38 37
 
39 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 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 42
         while (!completableFuture.isDone()) {
44 43
             logger.info("IS PROCESSING...");
45 44
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
46 45
         }
47 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 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 53
             throws ExecutionException, InterruptedException {
54 54
 
55 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 57
         while (!personCompletableFuture.isDone()) {
58 58
             logger.info("IS PROCESSING...");
59 59
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
60 60
         }
61 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 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 67
             throws ExecutionException, InterruptedException {
68 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 70
         while (!tvSerieCompletableFuture.isDone()) {
71 71
             logger.info("IS PROCESSING...");
72 72
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
73 73
         }
74 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 78
     @RequestMapping(value = "/tvseries/title/{tvseriePrimaryTitle}", method = RequestMethod.GET)
@@ -81,7 +81,7 @@ public class MovieController {
81 81
 
82 82
         Future<IndexedSeq<Models.TvSerie>> listFuture = akkaStreamFilesProcessing.getTvSerieByPrimaryTitle(tvseriePrimaryTitle);
83 83
         CompletableFuture<IndexedSeq<Models.TvSerie>> completableFuture =
84
-                completableFutureResult.buildcompletableFuture_(listFuture);
84
+                CompletableFutureResult.buildcompletableFuture2(listFuture);
85 85
         while (!completableFuture.isDone()) {
86 86
             logger.info("IS PROCESSING...");
87 87
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
@@ -94,17 +94,15 @@ public class MovieController {
94 94
             return null;
95 95
         });
96 96
 
97
-        return tvSeries;
97
+      return tvSeries;
98 98
     }
99 99
 
100
-    ;
101
-
102 100
     @RequestMapping(value = "/persons/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
103 101
     private List<String> getPersonsForTvSerie(@PathVariable(name = "tvSerieTitle") String tvSerieTitle)
104 102
             throws InterruptedException, ExecutionException {
105 103
 
106 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 106
         while (!completableFuture.isDone()){
109 107
             logger.info("IS PROCESSING...");
110 108
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);

+ 2
- 4
src/main/java/fr/natan/akkastreamfileprocessingapi/futurecompleteness/CompletableFutureResult.java ファイルの表示

@@ -2,7 +2,6 @@ package fr.natan.akkastreamfileprocessingapi.futurecompleteness;
2 2
 
3 3
 
4 4
 import scala.collection.IndexedSeq;
5
-import scala.collection.immutable.List;
6 5
 import scala.concurrent.Future;
7 6
 
8 7
 import java.util.concurrent.CompletableFuture;
@@ -12,7 +11,7 @@ import java.util.concurrent.Executors;
12 11
 
13 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 15
         CompletableFuture<T> completableFuture = new CompletableFuture<>();
17 16
        Executors.newSingleThreadExecutor().submit(() -> {
18 17
            while(!futureT.isCompleted()){
@@ -25,8 +24,7 @@ public class CompletableFutureResult<T> {
25 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 28
         CompletableFuture<IndexedSeq<T>> completableFuture = new CompletableFuture<>();
31 29
         Executors.newSingleThreadExecutor().submit(() -> {
32 30
             while(!futureListT.isCompleted()){

+ 0
- 1
src/main/scala/fr/natan/akkastreamfileprocessingapi/service/AkkaStreamFileProcessingImpl.scala ファイルの表示

@@ -11,7 +11,6 @@ import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{buildA
11 11
 import org.slf4j.LoggerFactory
12 12
 import org.springframework.stereotype.Component
13 13
 
14
-import scala.collection.mutable.ListBuffer
15 14
 import scala.concurrent.ExecutionContext.Implicits.global
16 15
 import scala.concurrent.Future
17 16
 import scala.language.postfixOps

Powered by TurnKey Linux.